I recently purchased this shield and 4 Deegoo-FPV MG995 7 volt servo motors. The shield is powered by a 12V 5A power supply (with built in AC to DC invertor). When I run the sketch the servo rotates slightly at full speed then in very tiny increments approxiamtely 180 degrees. No matter what I change the servomin and max values to, this does not change. The sketch is one I copied and pasted from the instructor of an online arduino course I'm taking that he posted on github. It is as follows:
Code: Select all
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
//#define SERVOMIN 130 // this is the 'minimum' pulse length count (out of 4096) for the HD-1800A servo
//#define SERVOMAX 530 // this is the 'maximum' pulse length count (out of 4096) for the HD-1800A servo
#define SERVOMIN 130 //1 // this is the 'minimum' pulse length count (out of 4096) for the SM-S4303R continuous rotation servo
#define SERVOMAX 530 //380 // this is the 'minimum' pulse length count (out of 4096) for the SM-S4303R continuous rotation servo
int pulselength_0 = map(0, 0, 180, SERVOMIN, SERVOMAX);
int pulselength_45 = map(45, 0, 180, SERVOMIN, SERVOMAX);
int pulselength_90 = map(90, 0, 180, SERVOMIN, SERVOMAX);
int pulselength_135 = map(135, 0, 180, SERVOMIN, SERVOMAX);
int pulselength_160 = map(160, 0, 180, SERVOMIN, SERVOMAX);
int pulselength_180 = map(180, 0, 180, SERVOMIN, SERVOMAX);
void setup() {
pwm.begin();
pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates
Serial.begin(9600);
}
void loop() {
// Drive each servo one at a time
// use pulselength = map(degrees, 0, 180, SERVOMIN, SERVOMAX); to convert degrees to pulse length
for (uint16_t pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++) {
Serial.println(pulselen);
pwm.setPWM(15, 0, pulselen);
delay(100);
}
delay(500);
for (uint16_t pulselen = SERVOMAX; pulselen > SERVOMIN; pulselen--) {
pwm.setPWM(15, 0, pulselen);
delay(100);
}
delay(500);
// Uncomment the following lines to make the servo move to specific positions
// pwm.setPWM(0, 0, pulselength_0); // Turn servo to 0 degrees (make pulselength 1 for a CRS - this will make it turn CCW at top speed)
// delay(500);
// pwm.setPWM(0, 0, pulselength_45); // Turn servo to 45 degrees (if using a CRS, it will turn CCW at medium speed)
// delay(500);
// pwm.setPWM(0, 0, pulselength_90); // Turn servo to 90 degrees (if using a CRS, it will stop)
// delay(500);
// pwm.setPWM(0, 0, pulselength_135); // Turn servo to 135 degrees (if using a CRS, it will turn CW at medium speed)
// delay(500);
// pwm.setPWM(0, 0, pulselength_160); // Turn servo to 160 degrees (if using a CRS, it will turn CW at higher medium speed)
// delay(500);
// pwm.setPWM(0, 0, pulselength_180); // Turn servo to 180 degrees (if using a CRS, it will turn CW at top speed)
// delay(500);
}