Go Down

Topic: Servo not quite going to 180 degrees  (Read 197 times) previous topic - next topic

Hank137

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():

Code: [Select]
#include <Servo.h>

Servo servo1; 
long num = 500;     

void setup()
{
 servo1.attach(9);
Serial.begin(9600);
Serial.print("Enter Pulse length = ");
}

void loop()
{
  if(Serial.available()>1)
  {
    num= Serial.parseInt();   
    Serial.print(num); 
    Serial.println(" pulse length");
    Serial.print("Enter Pulse length = ");
  }
  servo1.writeMicroseconds(num);
  delay(15);
}


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.

Robin2

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?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Hank137

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?

johnwasser

Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

Hank137

I tried setting the servo_max beyond 2400 in Servo.attach(), didn't work.

Tinkerspy

I have one of these sg servos as well and it doesn't go all the way to 180 degrees either. I figured that was normal ;-)
Author of Automaton: Reactive State Machine framework for Arduino

johnwasser

Sounds like your servo is defective.  After reading some of the reviews, I'm not very surprised:
http://www.servodatabase.com/servo/towerpro/sg90

Perhaps the vendor you got it from will replace it with a working one.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

Robin2

Sounds like your servo is defective.
From the top of the Original Post it seems the servo works as expected with an RPi.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Hank137

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.

johnwasser

When I connect the adafruit servo driver all the servos work fine (0 to 200 degrees).
What pulse widths were you using with the Raspberry Pi?
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

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.

Tinkerspy

I just connected my sg90 to my scope using the Servo library:

servo.write( 0 ); // timings: 2000 ms/19.6 ms


servo.write( 180 ); // timings: 2400 ms/17.6 ms


And, no, it doesn't quite go all the way to 180 degrees.
Author of Automaton: Reactive State Machine framework for Arduino

johnwasser

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?
Code: [Select]
#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
  }
}
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy