Go Down

Topic: Servo Jitter Problem (Read 216 times) previous topic - next topic

trent5683

Jan 13, 2020, 06:53 pm Last Edit: Jan 13, 2020, 07:17 pm by trent5683 Reason: Attaching picture
I'm fairly new to arduino (last couple weeks) and I have decided to purchase a 6 axis robotic arm
controlled by 6 MG996R servos. These servos are controlled by 6 potentiometers.

The wiring is as follows:
servos and potentiometers are all on their own 5V power supplies.
arduino is being powered via USB.
signal out from the 6 pots hook into A0 through A5.
The PWM outputs are ~3, ~5, ~6, ~9, ~10, and ~11.

The code is as follows:


int valPot1;
int valPot2;
int valPot3;
int valPot4;
int valPot5;
int valPot6;

void setup()
{
  servo1.attach(3);
  servo2.attach(5);
  servo3.attach(6);
  servo4.attach(9);
  servo5.attach(10);
  servo6.attach(11);
}

void loop()
{
  valPot1 = analogRead(pot1);
  valPot1 = map (valPot1, 0, 1023, 0, 180);
  servo1.write(valPot1);
  delay(15);

  valPot2 = analogRead(pot2);
  valPot2 = map (valPot2, 0, 1023, 0, 180);
  servo2.write(valPot2);
  delay(15);

  valPot3 = analogRead(pot3);
  valPot3 = map (valPot3, 0, 1023, 0, 180);
  servo3.write(valPot3);
  delay(15);

  valPot4 = analogRead(pot4);
  valPot4 = map (valPot4, 0, 1023, 0, 180);
  servo4.write(valPot4);
  delay(15);

  valPot5 = analogRead(pot5);
  valPot5 = map (valPot5, 0, 1023, 0, 180);
  servo5.write(valPot5);
  delay(15);

  valPot6 = analogRead(pot6);
  valPot6 = map (valPot6, 0, 1023, 0, 180);
  servo6.write(valPot6);
  delay(15);
}


After getting this all together and done with, I turn it on only to find out that it jitters like crazy, turns the motors without any control from the pots, and even if i do control it with the pots, it's almost like its not reading the variable sent from the pot completely. i can't seem to get it to turn on all 255 or something degrees. Almost like it's limiting itself. So before this thing tries to crawl out of my office and take over the world, thought i would reach out to see if anyone knew some tips and tricks.

Lastly, I have purchased a PCA9685 16 channel servo controller in order to drive all of these servos but the setup I've listed above is what i want to get working first. If you have any ideas on how to get the PCA9685 running in this setup please let me know.

I appreciate any help you guys an give.

vinceherman

Can you give us a wiring diagram?  Pencil, paper and a camera are good enough.

If I were trying to troubleshoot this, I would want to break it down into smaller pieces.
Unplug all the servos.
Everywhere you have an AnalogRead(), follow it up with a Serial.print() of the pot number and the pot value.
Then you can look at the serial monitor and see if it is giving you expected values.

trent5683

Just attached the picture to main message

trent5683

  valPot1 = analogRead(pot1);
  Serial.print(pot1);
  valPot1 = map (valPot1, 0, 1023, 0, 180);
  servo1.write(valPot1);
  delay(15);

does this look correct because i'm not getting anything on serial monitor?

slipstick

#4
Jan 13, 2020, 08:19 pm Last Edit: Jan 13, 2020, 08:21 pm by slipstick
You need to put a Serial.begin(9600); in setup(). And you want to print valPot1 not the pin number pot1.

You seem to have a lot of 5V power supplies if each servo has its own. Are all the GNDs connected together and to the Arduino GND?

Steve

trent5683

slipstick

thanks for that, got the serial set up however now im just seeing endless 0's "00000000000000000000000000000000000000000000000000000000000000000"

im guessing i need to set a value for it to read? however where do I do that at?

no each servo does not have its own 5V power supply. all servos are running off of (1) 5V powersupply and all pots are running off of (1) 5V power supply. the arduino is being powered by USB only.

If you could explain the GND for the arduino a little bit more I would appreciate that! Thank you!

Here is the updated code so far:

#include <Servo.h>

Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
Servo servo6;

int pot1 = A0;
int pot2 = A1;
int pot3 = A2;
int pot4 = A3;
int pot5 = A4;
int pot6 = A5;

int valPot1;
int valPot2;
int valPot3;
int valPot4;
int valPot5;
int valPot6;

void setup()
{
 Serial.begin(9600);
 servo1.attach(3);
 servo2.attach(5);
 servo3.attach(6);
 servo4.attach(9);
 servo5.attach(10);
 servo6.attach(11);
}

void loop()
{
 valPot1 = analogRead(pot1);
 Serial.print(valPot1);
 valPot1 = map (valPot1, 0, 1023, 0, 180);
 servo1.write(valPot1);
 delay(15);

 valPot2 = analogRead(pot2);
 Serial.print(valPot2);
 valPot2 = map (valPot2, 0, 1023, 0, 180);
 servo2.write(valPot2);
 delay(15);

 valPot3 = analogRead(pot3);
 Serial.print(valPot3);
 valPot3 = map (valPot3, 0, 1023, 0, 180);
 servo3.write(valPot3);
 delay(15);

 valPot4 = analogRead(pot4);
 Serial.print(valPot4);
 valPot4 = map (valPot4, 0, 1023, 0, 180);
 servo4.write(valPot4);
 delay(15);

 valPot5 = analogRead(pot5);
 Serial.print(valPot5);
 valPot5 = map (valPot5, 0, 1023, 0, 180);
 servo5.write(valPot5);
 delay(15);

 valPot6 = analogRead(pot6);
 Serial.print(valPot6);
 valPot6 = map (valPot6, 0, 1023, 0, 180);
 servo6.write(valPot6);
 delay(15);
}


trent5683

Please see this attachment for wiring diagram.

slipstick

#7
Jan 13, 2020, 10:09 pm Last Edit: Jan 13, 2020, 10:12 pm by slipstick
If all your Serial.prints are printing 0 all the time then your pots are not wired up correctly.

In this case it's probably because you must have connections between the negative (black) wires of both power supplies and one of the Arduino pins marked "GND". Without that connection the analogReads have no ground/zero reference to measure the pot voltages against.

EDIT: just seen your diagram. If you really have 12V connected to the pots and the servos then you have probably killed the Arduino and all the servos.

Steve

trent5683

Made some progress. Implemented a GND reference from the arduino and got things to read to the serial port.

NOT 12V!!!!! it is 5V. I just forgot to edit the label in eagle.

slipstick

You can see what you have. We can't. All we know is what you tell us. If that's not correct it can waste a fair amount of time.

But congratulations on getting the GND sorted out. Now, are the Serial.print values fairly steady. I.e. if you don't move the pot the value stays pretty much constant? If so then you can connect ONE of the servos and see if that is working o.k.

Steve

trent5683

#10
Jan 13, 2020, 11:26 pm Last Edit: Jan 13, 2020, 11:27 pm by trent5683
The serial print values are steady (012301230123012301230123012301230123012301230ect). I am going to go over continuity of all my pins and get this robot arm on something more stable that can take the "flopping" around. I found multiple issues with the servo right and left limits that I was hitting which are now fixed. However after controlling one servo, It seems adding another one into the mix really makes things unhappy again.

My next question is the following:
"Is dealy(15);" in ms or degrees?

valPot6 = analogRead(pot6);
Serial.print(valPot6);
valPot6 = map (valPot6, 0, 1023, 0, 180);
servo6.write(valPot6);
delay(15);

slipstick

delay() is in milliseconds. Top of the page, Resources/Reference gives details of all the standard Arduino commands.

But if one servo works but two causes problems then the most likely cause is either insufficient power or poor wiring (by far the most common problems we see with servos). And since you're committing both of the cardinal sins of high current wiring, running power through a breadboard AND connecting using unreliable high resistance crocodile clips I'm going for bad wiring. More direct connections to the servos will almost certainly help.

But just in case, what is the specification of the 5V power supply to the servos. For six MG996s you really need at least 10A, possibly more.

Steve

zoomkat

#12
Jan 14, 2020, 07:41 am Last Edit: Jan 14, 2020, 07:42 am by zoomkat
You best just drop back to one pot and one servo, and disconnect the other servos. See if you can get one servo to control properly with one pot using the "knob" servo code example. If you can get one servo operating properly, then you can add more servos and see how it goes. Where does the 5v going to the pots come from? Is this power supply ground properly attached to the arduino ground? If not, it might cause issues.
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

Go Up