Im trying to control two servos at once using Arduino UNO and Arduino Motor Shield. My servos are modified, so that they can work with constant movement. When I send the first order myservoP.write(180); (thats mean full speed) it works fine, however, when I try to order my servo to change direction (myservoP.write(0);) immediately my Arduino crashes and resets. At first I though it may be a problem with the power supply, but after testing it with my program (listed below), I am starting to think that it's a problem with buffer or memory. Without delays, the Arduino crashes after about 10 iterations. With delay(10), it will crash after about 90 iterations. With delay(20), Arduino is able to repeat a full cycle 5 times, from start to finish. During the 6th attempt, it crashed again...
Someone have any idea? I don't know how to deal with this problem...
Here is my code:
#include <Servo.h>
Servo myservoL;
Servo myservoP;
int i;
void setup()
{
delay(2000);
myservoL.attach(9); // attaches the servo on pin 9 to the servo object
myservoP.attach(10); // attaches the servo on pin 10 to the servo object
Serial.begin(9600);
}
void loop()
{
for(i=180; i>=0; i--)
{
delay(20);
Serial.println(i);
myservoP.write(i);
myservoL.write(i);
}
for(i=0; i<=190; i++)
{
delay(20);
Serial.println(i);
myservoP.write(i);
myservoL.write(i);
}