I got the Ultimate Starter Kit, and through some experimenting I've found that the servo they gave me is reading approximately 45 degrees too far clockwise.
This means that if I try to write 0 to the servo, it will not be able to get there, and if I write 180, it gets there but then when I release it I can turn it 45 degrees more by hand.
I know of a few different ways to attempt to solve this, the most obvious of which is buying a new servo, but I was wondering if anyone has a better idea. The other two things I thought of are: changing the code in the servo module itself (although I code on multiple computers so I'd have to do that on all of them), and opening up the servo and fixing the mechanics of it (not sure the likelihood that that will be successful...)
So yeah if anyone knows the best way to solve this, help is much appreciated!
On most servos, a potentiometer feedback element reads the arm position. On some of those, there is a small hole in the shaft for screwdriver access to change the registration between the potentiometer wiper and the servo arm.
Edit: do avoid the common mistake of powering the servo from the Arduino. Use a separate power supply and connect the grounds.
Basic servo test code you can use with the serial monitor to determine the mechanical limits of your servo. You can command the servo to the desired command position, then remove the servo horn and replace in the desired position.
// 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
}
}
Thanks for the replies everyone! Couple of things: I did know that I could reposition the servo attachment, but the problem is with the potentiometer in the servo.
This leads me to my next thing: if I simply compensate for it in my code, not only might it not work with another motor, but the problem with that is that the module is incapable of writing anything greater than 180 degrees to the servo, therefore putting an unnecessary limit on its range of motion.
Also a question for jremington: why not power the servo from the Arduino? I've been doing that and except for the misreading it's been doing just fine, although I will say it works better when the board is powered by a 9-volt rather than the computer. (I suppose I should have assumed that, considering standard computer USBs only output 5V)
Anyway, it actually turns out that this might have become obsolete because during my (reckless) testing of the servo's strength, the two topmost gears both lost a tooth! If I really wanted to, I could probably design and 3D print new ones and then fix the potentiometer, but the servos are cheap enough that I don't think it's worth the trouble. Thanks anyway, though!
I did know that I could reposition the servo attachment, but the problem is with the potentiometer in the servo.
I don't understand.
I got the Ultimate Starter Kit, and through some experimenting I've found that the servo they gave me is reading approximately 45 degrees too far clockwise.
This means that if I try to write 0 to the servo, it will not be able to get there, and if I write 180, it gets there but then when I release it I can turn it 45 degrees more by hand.
What do you mean by this? "... if I write 180, it gets there but when I release it I can turn it 45 degrees more by hand."
Are you saying that the servo turns an entire 180 degrees when you change from sending 0 to sending 180, but that you can manually turn it 45 degrees more?
If you want to experiment with moving your servo with longer and shorter pulses to see what it is capable of, try "servo.writeMicroseconds(n)". Usually n is between 1000 and 2000, as midband on a servo is supposed to be 1.5ms (1500us). But you can try values outside this.
This means that if I try to write 0 to the servo, it will not be able to get there, and if I write 180, it gets there but then when I release it I can turn it 45 degrees more by hand.
Turning the servo horns by hand often strips the gears in small servos. Driving them against the internal hard stop can also strip the gears.
@JimboZA ahh that makes sense. I'll start doing that from now on, thanks!
@polymorph what I mean is that, for example, I turn the servo to its minimum possible value by hand before I start the program; it should then read "0" but instead it reads somewhere around 45. If the program tries to make the servo go to 0, it strains to go beyond the limitations of the physical gear because the potentiometer inside it thinks that it's still at 45.
If the program tells it to go to 180, then it should theoretically go to its maximum value. However, since the potentiometer is apparently reading off, it thinks that it has reached that position 45 degrees early, therefore I can turn it 45 degrees more by hand.
@zoomkat thanks... I figured that out the hard way.
Some digital servos are by default programmed to only rotate +-45 deg instead of +-90 deg. if your servo was a digital one then this may have been an issue.
When a device is mass produced and easy to replace, best to replace it. if you re-write any code for that one, then all the others will be off. if you spend two hours to work around a $2.00 part, you set your own hourly rate.
as for understanding how and why it works, that is well worth the effort.
Yep I'll most likely just be replacing it when I get a chance. Merry Christmas, by the way! Also, this is my first time using the forum, how do you make the topic show up as [SOLVED]? to you just add that to the title or is there a button somewhere on the page that I'm not seeing?
I think you can go to the first post and use the modify option in the lower right of the post to modify the origional subject line. Don't discard the servo with damaged gears as it might be used to drive a large H-bridge module.
@polymorph what I mean is that, for example, I turn the servo to its minimum possible value by hand before I start the program; it should then read "0" but instead it reads somewhere around 45. If the program tries to make the servo go to 0, it strains to go beyond the limitations of the physical gear because the potentiometer inside it thinks that it's still at 45.
The maximum/minimum possible rotation by hand is not necessarily the maximum/minimum rotation that it can drive itself electrically.
Are you talking about radio control servos, or something else? All the RC servos I've used are not reset by moving them manually. Center is still center. Unless you take it apart and start messing with it.
What do you mean it "reads" 45? What reads 45? Where are you "reading" 45? What do you mean by "read"?
I agree with the idea that if this servo is defective, replace it. Stop wasting time on a $2 part.
oh of course! my room is an absolute mess because I don't throw anything away I always scrap anything I can for parts if it isn't useful for its intended purpose!