I am using tower pro sg90 servos which I used with a raspberry pi and the adafruit 16 channel servo driver board. Using the PI (both with and without the servo driver board) I've been able to turn the servos from 0 to roughly 200 degrees using PWM. However when I use the arduino the servos never go beyond roughly 160 degrees (all 5 of them). The servo never hits a mechanical limit with the arduino but it does with the PI.
I'm using the following code to set the servo position using writeMicroseconds():
The problem is that the servo never goes beyond the point of 2400us. Entering something like 3000us moves it to 160 degrees, same position as 2400us. I've copy pasted many codes and all with the same result, never beyond 160 degrees. It seems to me as if there is a limit somewhere preventing the arduino (or maybe it's the servo library) from sending a PWM signal with a pulse width greater than 2400us to the servo.
It may be that the Servo library has limits built into it. Have a look at the code in the library.
I presume from what you say that when the servo moves to 2400µsecs you can physically move it the extra 20 degrees in the same direction? Or, is it possible that the problem is that it is not going far enough at the other end?
I can push the servo further in the same direction (after cutting power to it), it handles the lower limit just fine.
I think this might be the library: https://github.com/arduino/Arduino/blob/master/libraries/Servo/src/Servo.h #define MAX_PULSE_WIDTH 2400 // the longest pulse sent to a servo. Could this be the culprit? Should I change that and save it as a custom library to use or something?
When I connect the adafruit servo driver all the servos work fine (0 to 200 degrees). I think I'll just give up on using the arduino directly for the servos.
Directly from the RPI I used pulse widths between 0.5 ms and about 3 ms. From the adafruit driver some servos needed 2.8 ms pulses to reach 180 degrees.
Hank137:
Directly from the RPI I used pulse widths between 0.5 ms and about 3 ms. From the adafruit driver some servos needed 2.8 ms pulses to reach 180 degrees.
Does it travel more than 160 degrees when you run this?
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup() {
// attaches the servo object to the servo on pin 9 and
// sets the 0 and 180 pulse lengths in microseconds
myservo.attach(9, 500, 3000);
}
void loop() {
for (int pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (int pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}