Hi everyone.
I got a little problem with a servo. It's a common one, the GWS S03N.
I've connected it to the arduino as this:
-brown -> GND
-red-> +5
-orange -> pin n°9
And then, no way to use it as a normal servo. I mean, when I write a value, it turns CW or CCW, always at the same speed, and stops only if I use servo.detach().
Someone knows how to use it with angles, as with any servo?
Here's the piece of code used for tests:
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo.write(30);
}
@AWOL > there's no mechanical end stop in this one I think, I can make it turn forever.
@Richard > already done. With 180 value, it does ~2 turns CCW, then ~turns CW and so on. I tried to change this value to 90: it goes for 1 turn CW, stops for a few ms, goes for 1 turn CW again and so on.
I actually got a problem a bit similar to this, except they are not full rotation servo's.
When the voltage drops a bit, they go crazy and moves in one direction (same direction every time), only way to make them stop is to totally disconnect them, and then try again. Adding a better power supply fixed that problem. How do you power yours, is it the 5V on board pin, or a 5V external power supply?
I tried this one too, servo acts the same way. About the arduino I'm using, it's Duemilanove, yes. It's powered through USB only, and the servo is connected as mentionned in #1 post, directly to the board. And my clue that the servo is good is that I have another one, exactly the same. Same results.
I'm going to try servo.read...And BTW: thanks for your answers
Yep:
With 180 value, it does ~2 turns CCW, then ~turns CW and so on. I tried to change this value to 90: it goes for 1 turn CW, stops for a few ms, goes for 1 turn CW again and so on.
@AWOL > there's no mechanical end stop in this one I think, I can make it turn forever.
doesn't that mean it's a continuous rotation servo (presumably with the feedback pot replaced by a fixed resistance) and so it's supposed to rotate continuously?
Well there you go. It's doing what it's supposed to do - going round and round as if it's driving wheels. Once a servo is modified to drive wheels continuously it's no longer usable as a "normal" servo that you can set to a particular angle (not unless you un-modify it anyway).
The measured voltage using my original setup is 4.78V...could'nt be better!
The arduino board generally (and USB computer ports) cannot supply enough current to operate a servo very well. learn the difference and relationship between voltage and current. You need an external power supply of ~1a for a servo to work well. That being said, it sounds like you have a "continous rotation servo". google that to understand how they work. Below is some simple test code You can use with the serial monitor to test your servo.
//zoomkat 7-30-10 serial servo test
//type servo position 0 to 180 in serial monitor
//for writeMicroseconds, use a value like 1500
#include <WString.h> //provides easy string handling
String readString = String(100);
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup() {
Serial.begin(9600);
myservo.attach(9);
}
void loop() {
while (Serial.available()) {
delay(10);
if (Serial.available() >0) {
char c = Serial.read(); //gets one byte from serial buffer
readString.append(c); } //makes the string readString
}
if (readString.length() >0) {
Serial.println(readString);
int n;
n = atoi(readString); //convert string to number
myservo.writeMicroseconds(n);
//myservo.write(n);
readString="";
}
}