This is not a fancy project to demonstrate what can be done with the Pololu Servo Controller. This is the bare minimum to get your Arduino working with the Pololu Servo Controller. The rest is up to you.
Parts
- Arduino Uno SMD
- Pololu Micro Serial Servo Controller
- Power HD Micro Servo HD-1900A
Configuration
- Remove jumper from Servo Controller to place in Pololu mode
- Connect power source for controller board and power source for servos
- Connect ‘logic-level serial input’ pin to Arduino pin 1 which is used for serial transmit
Notes
- The Arduino will not control the servos while the USB is connected to your computer.
- Upload your sketch
- Disconnect USB
- Restart Arduino
- Slowly increment the position numbers to find out the maximums for your servo. Not all 180 degree servos are the same. I found the limits for my servo to be 1000 and 4700.
Sketch
// Arduino pin connected to Pololu Servo Controller const int servoController = 1; // location of Servo plugged into Pololu Servo Controller (defaults 0-7) const int servo0 = 0; void setup() { Serial.begin(9600); servoSetSpeed(servo0,127); } void loop() { delay(1000); servoMove(servo0,3000); delay(1000); servoMove(servo0,4000); } /* Move Servo using Pololu Servo Controller servo = servo number (default 0-7) hornPos = position (500-5500) {Test your servos maximum positions} */ void servoMove(int servo, int pos) { if( pos > 5500 || pos < 500 ) return; // Build a Pololu Protocol Command Sequence char cmd[6]; cmd[0] = 0x80; // start byte cmd[1] = 0x01; // device id cmd[2] = 0x04; // command number cmd[3] = servo; //servo number cmd[4] = lowByte(pos >> 7); // lower byte cmd[5] = lowByte(pos & 0x7f); // upper byte // Send the command to the Pololu Servo Controller for ( int i = 0; i < 6; i++ ){ Serial.write(cmd[i]); } } /* * Set Servo Speed using Pololu Servo Controller * servo = servo number (default 0-7) * speed = (1-127) (slowest - fastest) 0 to disable speed control */ void servoSetSpeed(int servo, int speed){ // Build a Pololu Protocol Command Sequence char cmd[5]; cmd[0] = 0x80; // start byte cmd[1] = 0x01; // device id cmd[2] = 0x01; // command number cmd[3] = lowByte(servo); // servo number cmd[4] = lowByte(speed); // speed // Send the command to the Pololu Servo Controller for ( int i = 0; i < 5; i++ ){ Serial.write(cmd[i]); } }