void setup()
{
// Initialize the digital pin as an output:
// Right motor:
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
// Left motor:
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
}
void loop()
{
// Turn on right motor (clockwise?), wait for 80 ms, then turn off. Wait 1 second.
digitalWrite(5, HIGH);
delay(80);
digitalWrite(5, LOW);
delay(1000); // Wait for a second
// Turn on right motor (anti-clockwise?), wait for 80 ms, then turn off. Wait 1 second.
digitalWrite(4, HIGH);
delay(80);
digitalWrite(4,LOW);
delay(1000);
// Turn on left motor (clockwise?), wait for 80 ms, then turn off. Wait 1 second.
digitalWrite(3, HIGH);
delay(80);
digitalWrite(3, LOW);
delay(1000); // Wait for a second
// Turn on left motor (anti-clockwise?), wait for 80 ms, then turn off. Wait 1 second.
digitalWrite(2, HIGH);
delay(80);
digitalWrite(2,LOW);
delay(1000);
}
However, we are getting spikes on the control pin for the servo (white wire) when this code runs. We confirmed this with an oscilloscope. Does anybody know why this might be? Any help would be appreciated, thank you!
You need to be a member of diydrones to add comments!
Replies
RC servos need regular pulses to work, and the length of the pulse and how often you send pulses is critical. Normal RC servos expect to get a pulse 50 times per second (frame time of 20ms) and how long that pulse is will determine were the arm moves to. A 1.5ms long pulse is center, 1.0ms is fully one way and 2.0ms is fully the other way. There is no standard for the direction although you can count on the same model servos always moving the same direction for a given pulse length but not the exact center or end points. The total angle moved can be counted on generally. Another thing of note is you must keep sending the pulses even if you don't need to change the position.
I am afraid your example above would not work at all. Given the code above and a very good digital servo I would not expect to see any spikes on the control line, on an old analog servo anything is possible, as severe shortcuts were taken with the design to make them cheap and easy to build.
Does this happen without the servo (with just the board)?
Sending it 100% duty cycle might cause it to draw a load of power and do some nasty stuff with your source (and potentially burn out).