Recently received my Pololu micro serial servo controller. It is connected through TTL to Arduino UNO Rev3 to control 1 servo (9g micro) for now but plan on using 4 or more later. Reset line is connected.
After struggling with serial problems and learning how to send data to the micro SSC, the biggest issue turned out to be lack of power from the USB.
I was getting various combinations of LED’s lighting up depending on the method of power up. Best results were achieved by powering the Arduino and servo with the USB and waiting for 5 seconds before powering the Micro SSC.
I cobbled together this code that moves the servo up and down it’s usable range in adjustable steps and delays.
// Include the servo library to add servo-control functions:
#include <SoftwareSerial.h>
#define rxPin 11
#define txPin 12
// set up a new serial port
SoftwareSerial softSerial = SoftwareSerial(rxPin, txPin);
// 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;
int servo0Pos;
void setup()
{
pinMode(rxPin, INPUT);
digitalWrite(txPin, HIGH); // keeps pololu board from getting spurious signal
pinMode(txPin, OUTPUT);
Serial.begin(9600); // data rate Serial monitor PC
delay (1000);
softSerial.begin(9600); //data rate Micro Servo controller
/* Set Servo Speed using Pololu Servo Controller
* servo = servo number (default 0-7)
* speed = (1-127) (slowest - fastest) 0 to disable speed control
*/
servoSetSpeed(servo0,120);
}
void loop()
{
int servoposition; // Output value to the servo.
for (int servoposition=1500; servoposition<4000;servoposition=servoposition+50) { // Servopos 0 to 255
servoMoveUp(servo0,servoposition);
servo0Pos = servoposition;
delay(500);
serialPrint();
}
for (int servoposition=4000; servoposition>1500;servoposition=servoposition-50) { // Servopos 0 to 255
servoMoveDn(servo0,servoposition);
servo0Pos = servoposition;
delay(500);
serialPrint();
}
}
void servoMoveUp(int servo, int pos)
{
if( pos > 4500 || 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++ ){
softSerial.print(cmd[i]);
}
}
void servoMoveDn(int servo, int pos)
{
if( pos > 4500 || 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++ ){
softSerial.print(cmd[i]);
}
}
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++ ){
softSerial.print(cmd[i]);
}
}
void serialPrint()
{
Serial.print(" servo: ");
Serial.println(servo0Pos);
}
What I noticed that tipped my off to a power problem is that while the controller was working, the Yellow LED was flashing brightly, the Green LED was flashing at the same frequency but a shorter duration and the Red LED was barely flickering. The LED’s were blinking at the same rate as the TTL softSerial.print.
Every once in a while it would just freeze and the Red LED would come on solid.
I connected a 5V 5Amp regulated power supply that I picked up at the surplus store yesterday to power everything. Works great. I just get the Green LED flashing. It’s been sitting here for over an hour moving the servo up/dn with no issues. MORE POWER!!!
The power up issue that I am having is that if I power up everything at the same time (no USB cable attached) the micro will have the Red LED on and the Green will flash @ 9600 baud. Cycling power to the micro will make it work fine.
@ 2400 and 4800 baud the Yellow LED is on and the Red LED flashes. Power cycle works.
Doesn’t seem to like anything > 9600 baud. Yellow LED on.
Removing the delay has no affect.
I could connect a relay to a digital pin that will interrupt the micro power for a few seconds after power up, but my design is short on digital pins.
OK, just figured it out. Apparently softSerial is the problem. I switched everything back to the standard serial and it starts up normally. Works 99% from 2400-36000 baud on the Serial.
So, next step is to troubleshoot the softSerial…