Servo jitter...
It is a global issue... Spreading across nations...
Can you guys help me with it?
I have a towerpro mg995 and a flex sensor running through an arduino mega.
Notes:
external 6v power supply.
servos work fine with zoomkat's serial servo code
ferrites do not work.
flex sensors are fine through serial
servos jitter like hell.
/*
Controlling a servo position using a potentiometer (variable resistor)
by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
modified on 8 Nov 2013
by Scott Fitzgerald
http://arduino.cc/en/Tutorial/Knob
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int potpin = A0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = constrain(map(val, 300, 600, 0, 180), 17, 170); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
any ideas?
How about a Serial.println(val); to verify the servo's not being commanded to move slightly?
You say servos plural but that code only has one... not a power supply thing with many servos drawing too much curent?
People have been having problems with MG995 servos powered with anything but 5V. Use a couple diodes to drop your 6V down to 5V and see if that works.
servos work fine with zoomkat's serial servo code
That indicates the problem is with the the noise/instability of the flex sensors or how the flex sensor is configured to input the arduino. How is the flex sensor wired to input to the arduino? Do you have it configured as part of a voltage divider?
zoomkat:
part of a voltage divider?
yeah. it's in a voltage divider with a 22k Ohm resistor.
zoomkat:
That indicates the problem is with the the noise/instability of the flex sensors or how the flex sensor is configured to input the arduino.
Yep that's what I was getting at with this:
JimboZA:
How about a Serial.println(val); to verify the servo's not being commanded to move slightly?
But OP silent on that one, so far.
Servo pot code with a dead band to filter out pot noise.
//zoomkat dual pot/servo test 12-29-12
//view output using the serial monitor
#include <Servo.h>
Servo myservoS1;
Servo myservoS2;
int potpinS1 = 0; //analog input pin A0
int potpinS2 = 1;
int newvalS1, oldvalS1;
int newvalS2, oldvalS2;
void setup()
{
Serial.begin(9600);
myservoS1.attach(2);
myservoS2.attach(3);
Serial.println("testing dual pot servo");
}
void loop()
{
newvalS1 = analogRead(potpinS1);
newvalS1 = map(newvalS1, 0, 1023, 0, 179);
if (newvalS1 < (oldvalS1-2) || newvalS1 > (oldvalS1+2)){
myservoS1.write(newvalS1);
Serial.print("1- ");
Serial.println(newvalS1);
oldvalS1=newvalS1;
}
newvalS2 = analogRead(potpinS2);
newvalS2 = map(newvalS2, 0, 1023, 0, 179);
if (newvalS2 < (oldvalS2-2) || newvalS2 > (oldvalS2+2)){
myservoS2.write(newvalS2);
Serial.print("2- ");
Serial.println(newvalS2);
oldvalS2=newvalS2;
}
delay(50); //slow down looping to better read serial monitor
}
zoomkat:
Servo pot code with a dead band to filter out pot noise.
Bookmarking this zk.... I had a problem the other day which might be solved by this, will test over the weekend.
The servo works fine with a regular pot, It's the flex sensors.
used Zoomkat's code and edited it: works fine
//zoomkat dual pot/servo test 12-29-12 edited ShadowGaming
//view output using the serial monitor
#include <Servo.h>
Servo myservo;
int potpinS1 = A0; //analog input pin A0
int newvalS1, oldvalS1;
void setup()
{
Serial.begin(9600);
myservo.attach(9);
Serial.println("Testing single flex servo");
}
void loop()
{
newvalS1 = analogRead(potpinS1);
newvalS1 = map(newvalS1, 300, 600, 0, 179);
if (newvalS1 < (oldvalS1-2) || newvalS1 > (oldvalS1+2)){
Serial.print("1- ");
Serial.println(newvalS1);
oldvalS1=newvalS1;
myservo.write(newvalS1);
}
delay(1); //slow down looping to better read serial monitor
}
ShadowGaming:
The code works fine with a regular pot, It's the flex sensors.
That doesn't gel with this from your first post:
flex sensors are fine through serial
You still haven't said if you tried Serial.println(val); to indicate if the servos are being commanded to move by mistake.
sorry, typed that last reply on phone. edited
That's confused me.... you mean it works fine with zk's code with the flex sensor or is that still with the pot only? (Code has a comment "Testing single flex servo" so I'm not sure....)
Part of the problem may be indicated in the below line of code. The issue may be that the actual voltage range out of the flex sensor voltage divider is small (looks to be ~1.5v), that any small voltage changes are significant in terms of final servo movement. I'd try putting a capacitor between the voltage divider output and arduino ground to somewhat stabilize the voltage divider output voltage.
val = constrain(map(val, 300, 600, 0, 180), 17, 170); // scale it to use it with the servo (value between 0 and 180)
Well if OP responds to my suggestion of Serial.println(val); we would see exactly what's being sent to the servo....
Guys. I used a GOOD servo. Problem solved
ShadowGaming:
Guys. I used a GOOD servo. Problem solved
Hmmmm..., seems like a delta between the above and below from the first post.
servos work fine with zoomkat's serial servo code