Menu

Servo simulation does not fit 0-180 degrees

2018-09-10
2018-09-11
  • Piero giagnoni

    Piero giagnoni - 2018-09-10

    A simple sketch with a servo, driven by "Servo.h" library, does not fit 0-180 degrees, but about 30-40 instead of 0 and 140-150 instead of 180.
    Is there any parameter to trim to adjust right angles?

    Ciao,
    P.

     
  • Santiago

    Santiago - 2018-09-10

    Hi Piero.
    The only customizable parameter is servo speed.

    But it works for me with Arduino Servo library, check Examples/Arduino/servo-sweep , it uses Arduino servo-sweep example and it goes from 0 to 180.

    Maybe it would be useful add properties to set pulse timing, but "standard" is 1mS to 2mS as far as i know.

    Regards.

     
  • Piero giagnoni

    Piero giagnoni - 2018-09-10

    Hi Santiago.
    Thanks for your answer.
    I modified servo sweep as follows:

    /* Sweep
     by BARRAGAN <http://barraganstudio.com>
     This example code is in the public domain.
    
     modified 8 Nov 2013
     by Scott Fitzgerald
     http://www.arduino.cc/en/Tutorial/Sweep
    
     THIS SKETCH HAS BEEN MODIFIED TO SHOW THAT SERVO CONNECTED TO PIN 9
     DOES NOT MOVE FROM 0° POSITION UNTIL ANGLE = 45° AND REACH 180°
     POSITION AT ABOUT 145°
    */
    
    #include <Servo.h>
    
    Servo myservo;  // create servo object to control a servo
    // twelve servo objects can be created on most boards
    
    int pos = 0;    // variable to store the servo position
    
    void setup() {
      Serial.begin(9600);               // configure serial port @ 9600 bps
      while (!Serial) { ; }
      myservo.attach(9);  // attaches the servo on pin 9 to the servo object
    }
    
    void loop() {
      for (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'
        Serial.print (pos);               // print position
        Serial.print (" ");
        delay(1000);                       // waits 1s to control the position
      }
      Serial.println ("");
      for (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'
        Serial.print (pos);;               // print position
        Serial.print (" ");
        delay(1000);                       // waits 1s to control the position
      }
      Serial.println ("");
    }
    

    I verify the sketch and export it in hex form. Then i load firmware in an Arduino Uno with a servo connected at pin 9 as usual.
    From the serial monitor I see that servo does not move from o° position until the angle reach about 45° and it reachs 180° position at about 145°.
    Maybe there is something wrong in my procedure?

    Ciao,
    P.

     
  • Santiago

    Santiago - 2018-09-10

    Yes, you are right.

    The example looked like was working, but indeed it wasn't working correctly.
    I did a bit of reseach and turned out that Servo.h defaults are 0º= 544 uS, 180º= 2400 uS.
    SimulIDE servo is: 0º= 1000 uS, 180º= 2000 uS.

    So you should configure it like this ( Servo.h line 37 ):
    myservo.attach( 9, 1000, 2000 );

     
  • Piero giagnoni

    Piero giagnoni - 2018-09-11

    I forgot login :-)
    "Thank you"

    Ciao,
    P.

     
  • Santiago

    Santiago - 2018-09-11

    Thanks to you for reporting.

     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.