Servo Shield and multiple servos

I'm currently working on a robotic arm using 6 servos and I have the Adafruit 16-channel PWM/Servo Shield. I did this to see if it would help decrease the jittering when I try it without the servo and it seems to help with most of the servos but one servo just won't stop jittering. Only ONE servo (the "elbow") keeps non-stop jittering. I've tried everything I could, changed the pot pin (I'm using pot to control the servos) thinking it could have been a faulty pin, it wasn't, I tried to change the servo pin, doesn't do anything, and last but not least I checked all the solder joints to see if there were any poorly soldered joints, that didn't help either. I finally thought there was something wrong with the code but I wasn't able to find anything wrong as all the servos are programmed the same but the elbow was the only problem.

Here is my code:

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

// Servos
// Servo     Pin
// Base      0
// LShoulder 1
// RShoulder 2
// Elbow     3 Testing 6
// LClaw     4
// RClaw     5
const int base = 0;
const int shoulderL = 1;
const int shoulderR = 2;
const int elbow = 3;
const int clawL = 4;
const int clawR = 5;

// Pot Pins
const int bPot = 0;
const int sPot = 1;
const int ePot = 2;
const int cPot = 3;

// Servo Degrees
int bDegree;
int sLDegree;
int sRDegree;
int eDegree;
int cLDegree;
int cRDegree;

// Servo Pulse Length
int bPulse;
int sLPulse;
int sRPulse;
int ePulse;
int cLPulse;
int cRPulse;

const int servoMin = 150;
const int servoMax = 590;

void setup () {
  pwm.begin();
  pwm.setPWMFreq(60);
}

void loop () {
  // Set Degree to Potentiometer
  bDegree = analogRead(bPot);
  sLDegree = analogRead(sPot);
  sRDegree = analogRead(sPot);
  eDegree = analogRead(ePot);
  cLDegree = analogRead(cPot);
  cRDegree = analogRead(cPot);

  // Map degree from 0 - 1023, to 0 - 180
  bDegree = map(bDegree, 0, 1023, 0, 180);
  sLDegree = map(sLDegree, 0, 1023, 0, 180);
  sRDegree = map(sRDegree, 0, 1023, 180, 0);
  eDegree = map(eDegree, 0, 1023, 0, 180);
  cLDegree = map(cLDegree, 0, 1023, 0, 180);
  cRDegree = map(cRDegree, 0, 1023, 180, 0);

  // Set Pulse Length
  bPulse = map(bDegree, 0, 180, servoMin, servoMax);
  sLPulse = map(sLDegree, 0, 180, servoMin, servoMax);
  sRPulse = map(sRDegree, 0, 180, servoMin, servoMax);
  ePulse = map(ePulse, 0, 180, servoMin, servoMax);
  cLPulse = map(cLDegree, 0, 180, servoMin, servoMax);
  cRPulse = map(cRDegree, 0, 180, servoMin, servoMax);

  // Rotate Servo
  pwm.setPWM(base, 0, bPulse);
  pwm.setPWM(shoulderL, 0, sLPulse);
  pwm.setPWM(shoulderR, 0, sRPulse);
  pwm.setPWM(elbow, 0, ePulse);
  pwm.setPWM(clawL, 0, cLPulse);
  pwm.setPWM(clawR, 0, cRPulse);
}

I really need help with this as I need this done soon.

Most servo problems come from inadequate power supply and poor grounding. Your servos may be overloaded by your arm design. Since you are using an Adafruit servo shield, Adafruit might have some answers for you. Below is some basic servo test code for use with the serial monitor to test servos attached to the arduino (always use an external power supply for the servo).

//zoomkat 7-30-10 serial servo test
//type servo position 0 to 180 in serial monitor
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);
  myservo.attach(9);
  Serial.println("servo-test"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the String readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured String 
    int n = readString.toInt();  //convert readString into a number
    Serial.println(n); //so you can see the integer
    myservo.write(n);
    readString="";
  } 
}

zoomkat:
Most servo problems come from inadequate power supply and poor grounding. Your servos may be overloaded by your arm design. Since you are using an Adafruit servo shield, Adafruit might have some answers for you. Below is some basic servo test code for use with the serial monitor to test servos attached to the arduino (always use an external power supply for the servo).

//zoomkat 7-30-10 serial servo test

//type servo position 0 to 180 in serial monitor
// Powering a servo from the arduino usually DOES NOT WORK.

String readString;
#include <Servo.h>
Servo myservo;  // create servo object to control a servo

void setup() {
  Serial.begin(9600);
  myservo.attach(9);
  Serial.println("servo-test"); // so I can keep track of what is loaded
}

void loop() {

while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the String readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured String
    int n = readString.toInt();  //convert readString into a number
    Serial.println(n); //so you can see the integer
    myservo.write(n);
    readString="";
  }
}

I actually found my problem I wrote ePulse = map(ePulse, 0, 180, servoMin, servoMax); instead of ePulse = map(eDegree, 0, 180, servoMin, servoMax);

You'll increase your resolution a bit by by mapping your pot inputs direction to the PWM output range rather first mapping to degrees than then to PWM.

You would increase your resolution even more if you didn't use the Adafruit shield and used "writeMicroseconds".

I posted some code to smooth out the motion of servos when controlled with a joystick. There are a lot of comments in the code which provide instructions on how to use the code with more than just two servos. The code will of course work with pots instead of joysticks (pots with a handle).

The code is attached to reply #18 and there are a couple links to videos showing the code in action in reply #23.

The servos both accelerate up to their top speed and decelerate as they stop. I think this provides a much smoother action than driving servos at their top speed all the time. It's also an improvement over driving servos at a constant speed.

I thought gyrojeremy put this constant acceleration code to good use in his robot arm project.

The code could easily be modified to work with the Adafruit shield however it wouldn't be able to drive the servos as precisely using the shield as driving the servos directly from Arduino I/O pins.

BTW, the pots in servos do go bad over time. A symptom of a bad pot is a servo which jitters severely. Once a servo starts to jitter because of a bad pot, the wear on the pot greatly increases and jittering servo will soon be unusable.

One indication jitter is caused by a worn out pot is when the jitter goes away when the servo is moved from its center position. The pot generally wears out in one place initially and when the servo is moved to a different location, the jitter stops.

I have a couple hexapods and I occasionally have to replace servos due to worn out pots.

As Zoomkat suggested, by far the most common cause of servo jitter is insufficient power.

If your servos work better when used with the Adafruit shield than when they were directly controlled by the Arduino, then the improvement is likely the result of better power distribution.