HI, I have two RC Servos modified for continuous movement attached to pins 9 and 10 of a Duemilanove. However, when I try to send a move to one of the servos the other moves as well. For exemple, the second servo moves continuously even when i commented the line that send moves to the second servo, as below:
#include <Servo.h>
Servo myservo1;
Servo myservo2;
int pos = 80;
void setup()
{
myservo1.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(10); // attaches the servo on pin 10 to the servo object
}
void loop()
{
myservo1.write(pos); // tell servo to go to position in variable 'pos' //myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(20);
}
This looks funny, can it have to do with your wiring?
On the other hand delay(20) gives the servo no chance at all to do something useful.... Change that to delay(100) or so
I checked all the wiring. No short. The only thing I didn't test was to substitute the Servo (I don't have a spare). I mind if I forget some code in working with two servos or if a defective servo or Arduino could be the cause for this behavior.
Any idea?
TIA
How are you powering the servos?
Is it from the 5V line of the arduino?
If so you could be getting some interference from the servos.
Try a septate supply for one servo and see if it fixes it.
Also set the position of servo 2 to something in the setup routine so it knows where to point.
Hi, I found the answer. The problem is that once I attach the servo with the pin 10, and I do not send any command to it, it start moving. The solution was to initialize (setup) it just afer the attachement. A simple myservo2.write(80) setup it in center position.
Thanks.