Servo.write vs. Servo.writeMicroseconds

Hi, I am wondering if there is any advantage in using one or the other? Do I get better accuracy if I use writeMicroseconds?

servo.write() allows a maximum of 180 servo positions
servo.writeMicroseconds() allows a maximum of 1000 servo positions

Both functions depend on the ability of the actual servo to do what is requested. Some servos, for example, cannot move through 180 degrees.

thanks for the reply. I guess I didn't state clear about my question. I understand that Servo.write takes degrees as argument verses servo.writeMicroseconds takes in micro seconds. and I also know that not all servos can do a 180 degrees turn. I use the tower pro 966R a lot. and I found out that at the most it could only go as far as 160 degree. . But what puzzles me about these two functions is that there must be a reason the Arduino IDE has two similar functions that seem to do the same thing. That is why I wonder there is an advantage with one over the other.

The "write" method simply maps the "degrees" to microseconds and calls the "writeMicroseconds" method anyway.
The "degree" of turn is simply a convenient abstraction, and few bother to calibrate it.

Simple servo test code you can use with the serial monitor to see the difference between the two servo command methods.

// zoomkat 3-28-14 serial servo incremental test code
// using serial monitor type a character (s to increase or a 
// to decrease) and enter to change servo position 
// (two hands required, one for letter entry and one for enter key)
// use strings like 90x or 1500x for new servo position 
// for IDE 1.0.5 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

#include<Servo.h>
String readString;
Servo myservo;
int pos=1500; //~neutral value for continuous rotation servo
//int pos=90;

void setup()
{
  myservo.attach(7, 400, 2600); //servo control pin, and range if desired
  Serial.begin(9600);
  Serial.println("serial servo incremental test code");
  Serial.println("type a character (s to increase or a to decrease)");
  Serial.println("and enter to change servo position");
  Serial.println("use strings like 90x or 1500x for new servo position");
  Serial.println();
}

void loop()
{
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }
  if (readString.length() >0) {
    if(readString.indexOf('x') >0) { 
      pos = readString.toInt();
    }

    if(readString =="a"){
      (pos=pos-1); //use larger numbers for larger increments
      if(pos<0) (pos=0); //prevent negative number
    }
    if (readString =="s"){
      (pos=pos+1);
    }

    if(pos >= 400) //determine servo write method
    {
      Serial.println(pos);
      myservo.writeMicroseconds(pos);
    }
    else
    {   
      Serial.println(pos);
      myservo.write(pos); 
    }
  }
  readString=""; //empty for next input
}
1 Like