ServoTimer2.h does not rotate 180 degrees fully??

I am doing a project involving the use of both Servo.h and Virtualwire.h. Eventually, I changed to use ServoTimer2.h because of the timer problem.

After testing the same servo motor with same algorithm using Servo.h and ServoTimer2.h respectively, I found that the servo motor using ServoTimer2.h does not rotate to the critical angles fully. :drooling_face: Say, Servo.h rotates from 5 to 175 degrees while ServoTimer2.h can only rotate from about 20 to 160 degrees.

I know that ServoTimer2 uses microseconds as input parameter and I have already tested with different values, including values out of range theoretically (0 to 5000) to ensure that the servo motor reaches its limits. Therefore, I believe this problem does not involve wrong microseconds input.

So anyone know how to solve this? As Servo.h works well to me is there any option that keeping Servo.h and using RF at the same time? Or how to modify the library so as to change the timer settings?

Thanks! :grinning:

After testing the same servo motor with same algorithm using Servo.h and ServoTimer2.h respectively,

Would you care to post the code for both tests ?

UKHeliBob:
Would you care to post the code for both tests ?

Here is the code for Servo.h:

#include <Servo.h>
Servo myservo;

void setup() {
  myservo.attach(9);
}

void loop() {
  myservo.write(0);
  delay(1000);
  myservo.write(180);
  delay(1000);
}

Using ServoTimer2.h:

#include <ServoTimer2.h>
ServoTimer2 myservo;

void setup() {
  myservo.attach(9);
}

void loop() {
  myservo.write(0);
  delay(1000);
  myservo.write(5000);
  delay(1000);
}

Thanks!

Do you have data sheets for the servos? Do the data sheets guarantee 0 to 180 degree motion?

Those programs have a fundamental difference. What happens if you use writeMicroseconds() when using Servo.h ?

groundfungus:
Do you have data sheets for the servos? Do the data sheets guarantee 0 to 180 degree motion?

I am just using the common Tower Pro SG90 Micro Servo and its datasheet says it rotates 180 degree. But of course the real one would have about +-5 degrees deviation.

I should explain it more clearly. The problem is that using the same servo motor, the rotation span of using ServoTimer2.h is narrower than that of using Servo.h. After testing, I can have nearly 0-180 degrees for Servo.h but 20-160 degrees for ServoTimer2.h.

UKHeliBob:
Those programs have a fundamental difference. What happens if you use writeMicroseconds() when using Servo.h ?

I have tested using writeMicroseconds() and the result is just the same as using write().

Maybe the library has a built-in limitt for the upper and lower numbers for microseconds. Have a look in the library code as if that is the problem it should be perfectly possible to change the limits.

...R

Is this what yu are using?

ServoTimer2.h has

#define MIN_PULSE_WIDTH       750        // the shortest pulse sent to a servo  
#define MAX_PULSE_WIDTH      2250        // the longest pulse sent to a servo

whereas the regular Servo.h has

#define MIN_PULSE_WIDTH       544     // the shortest pulse sent to a servo  
#define MAX_PULSE_WIDTH      2400     // the longest pulse sent to a servo

oqibidipo:
Is this what yu are using?
GitHub - nabontra/ServoTimer2: ServoTimer2 is a simple library for Arduino 1.x that does not use Timer1 in case of a conflict.

ServoTimer2.h has

#define MIN_PULSE_WIDTH       750        // the shortest pulse sent to a servo  

#define MAX_PULSE_WIDTH      2250        // the longest pulse sent to a servo




whereas the regular Servo.h has


#define MIN_PULSE_WIDTH      544    // the shortest pulse sent to a servo 
#define MAX_PULSE_WIDTH      2400    // the longest pulse sent to a servo

I can realize the cause of difference now. Thanks oqibidipo!

Besides, I have discovered an alternative - using the Software Servo Library:
http://playground.arduino.cc/ComponentLib/Servo

It is capable to use SoftwareServo.h and VirtualWire.h at the same time! :slight_smile:

Finally, thanks for all your replies!!!