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.