Wednesday, January 28, 2009

Solution - Parallax motor control

Below is a bit of code I found that solves my previous question about controlling the Parallax servo motors. From the Parallax website, I found that these motors require a pulse of 1.5 ms every 20 ms in order to stand still . Pulses shorter than this cause clockwise rotation. Pulses longer than this cause counter clockwise rotation.

With this code running, you can use a screwdriver to adjust the internal potentiometer to let the motor stand still. Change the "1500" delay to another number to observe the directional control.
If anyone knows how to accomplish this using the Arduino libraries I would appreciate knowing.

Paul.

int servoPin = 10;
void setup()
{
pinMode(servoPin,OUTPUT);
}
void loop()
{
digitalWrite(servoPin,HIGH);
delayMicroseconds(1500); // 1.5ms
digitalWrite(servoPin,LOW);
delayMicroseconds(18500); // 18.5ms
}

UPDATED BY IVAN:

Try this code.

int servoPin = 9;
void setup()
{
pinMode(servoPin,OUTPUT);
}
void loop()
{
int temp;
for (temp = 0; temp <= 100; temp++)
{
digitalWrite(servoPin,HIGH);
delayMicroseconds(1500); // 1.5ms
digitalWrite(servoPin,LOW);
delay(20);  // 20 ms
}

for (temp = 0; temp <= 30; temp++)
{
digitalWrite(servoPin,HIGH);
delayMicroseconds(1600); // 1.6ms
digitalWrite(servoPin,LOW);
delay(20); // 20ms
}

//delay(100);

for (temp = 0; temp <= 31; temp++)
{
digitalWrite(servoPin,HIGH);
delayMicroseconds(1400); // 1.4ms
digitalWrite(servoPin,LOW);
delay(20); // 20ms
}
}

1 comment:

  1. I just found this out, but I've been playing and it's harder to control the angle.
    If we still have the receipts we might want to return half of the servos we bought and get regular ones.

    ReplyDelete