Need help with code on 360 degree servo (Not Continuous!)

Hey,

I recently purchased the following 360 degree servo (S125 3T D):

http://www.gwsus.com/english/product/servo/s125.htm

I am having issues controlling where and when it stops, I wish to control it like a standard servo with a potentiometer. When I currently try it using myServo.write(0 - 360) its behaviour is rather random and does not turn to the required angle. It typically keeps going till it gets to its turn limit then reverses in the other direction.

I have read that you have to accurately map this type of servo but am struggling to find what values to map it to.

Any help coding this thing would be great as I need it for my university honours project.

Forum user Zoomkat frequently posts servo test code that might be useful. Or look at the sweep example and tweak the values.

Generally, there's an expectation that an ordinary servo won't have more than 180 degrees of travel - you might try just dividing the number of degrees by two. However you do it, it should just be a matter of experimenting until you find what numbers control it. You might take a look at servo.writemicroseconds too.

When I currently try it using myServo.write(0 - 360) its behaviour is rather random and does not turn to the required angle.

That servo appears to rotate three turns. You use the command range you would with standard servos. In this case instead of 0-180, 45-135 (or 1000us-2000us) might make for the three turns. Below is some servo code test code you night use to find the proper command range.

// zoomkat 12-25-13 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// Send an a to attach servo or d to detach servo
// for IDE 1.0.5 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

#include <Servo.h> 
String readString; //String captured from serial port
Servo myservo;  // create servo object to control a servo 
int n; //value to write to servo

void setup() {
  Serial.begin(9600);
  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7, 500, 2500);  //the pin for the servo control, and range if desired
  Serial.println("servo all-in-one test code 12-25-13"); // so I can keep track of what is loaded
  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) {
    Serial.println(readString);  //so you can see the captured string 

      // attach or detach servo if desired
    if (readString == "d") { 
      myservo.detach(); //detach servo
      Serial.println("servo detached");
      goto bailout; //jump over writing to servo
    }
    if (readString == "a") {
      myservo.attach(7); //reattach servo to pin 7
      Serial.println("servo attached");
      goto bailout;
    }    

    n = readString.toInt();  //convert readString into a number

    // auto select appropriate value
    if(n >= 500)
    {
      Serial.print("writing Microseconds: ");
      Serial.println(n);
      myservo.writeMicroseconds(n);
    }
    else
    {   
      Serial.print("writing Angle: ");
      Serial.println(n);
      myservo.write(n); 
    }

bailout: //reenter code loop
    Serial.print("Last servo command position: ");    
    Serial.println(myservo.read());
    Serial.println();
    readString=""; //empty for next input
  }
}

Standard servos have 150 degrees or so usually, but there's no hard and fast rule, these are not precision engineering components (well not the cheap ones).

MarkT: Standard servos have 150 degrees or so usually, but there's no hard and fast rule, these are not precision engineering components (well not the cheap ones).

I've never had any RC stuff, but I think most RC equipment will only rotate a typical servo +-45 deg. The sail winch servo should rotate the full three turns within this typical RC control range.