16-Channel 12-bit PWM/Servo Shield and servo

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
andycandler
 
Posts: 2
Joined: Mon Apr 17, 2023 2:50 am

16-Channel 12-bit PWM/Servo Shield and servo

Post by andycandler »

Mon Apr 17, 2023 3:22 am

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);
}
Any help is appreciated.
Last edited by adafruit_support_bill on Mon Apr 17, 2023 6:59 am, edited 1 time in total.
Reason: Please use [code] tags when posting code to the forums

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: 16-Channel 12-bit PWM/Servo Shield and servo

Post by adafruit_support_bill »

4 Deegoo-FPV MG995 7 volt servo motors. The shield is powered by a 12V 5A power suppl
Your power supply is nearly twice the rated voltage for the motors. I would not expect them to last long at that voltage.
When I run the sketch the servo rotates slightly at full speed then in very tiny increments approxiamtely 180 degrees.
The initial quick motion is the servo seeking to the first position. The 'for' loops in the code are incrementing the seek position every 100 milliseconds.
No matter what I change the servomin and max values to, this does not change.
It is not clear what you are expecting to change. Servomin and servomax just determine the beginning and end positions. It will not alter the incremental seeking behavior in the code.

User avatar
andycandler
 
Posts: 2
Joined: Mon Apr 17, 2023 2:50 am

Re: 16-Channel 12-bit PWM/Servo Shield and servo

Post by andycandler »

I purchased an adjustable power supply and it arrived today. I set it to 7 volts and there was still the exact same problem. I tried it on the other servos that came in the set of 4 and nothing changed, so the first servo was not damaged by the 12 volt PS. After some experimentation I've determined the problem was with the 100 ms delays inside the for loops. Once I changed them to 0, the horn moved smoothly.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”