Help on 18 Servo controller

Hi, Just trying to hook up arduino with the servo controller and i’m getting the red Light and a flashing yellow, can’t get the servo to centre.

Error at the Pololu Centre:
Serial signal error
Serial protocol error

Performance Flag:
Advanced update late (1 times)
Basic update late (1 times)

Not sure if that means i need to update or something.

My circuit is set up as follows: Arduino TX to Maestro RX
Arduino 5V to Maestro Vin
Arduino GND to Maestro Gnd
VIN = VSVR ----------------- Its only 1 servo so there shouldn’t be a problem with power…right?

Code i’m using: (found on this forum aswell and is supposed to work)

void setup()// run once, when the sketch starts
{
  //Set up Serial library at 9600 bps
  //Note: The controller will support any rate between 2000 and 40000 baud
  Serial.begin(9600);
}

void loop() //Main program loop, executes forever after setup()
{
  //Set servo position on port 0 to 3000 (Absolute Position)
  //Note: This function only has to be called once to update the position
  put(0,3000);
  
  //Delay so you can see the servo controller's serial status LED blink
  delay(1000);
}

void put(int servo, int angle)
{
  //servo is the servo number (typically 0-7)
  //angle is the absolute position from 500 to 5500

  unsigned char buff[6];

  unsigned int temp;
  unsigned char pos_hi,pos_low;

  //Convert the angle data into two 7-bit bytes
  temp=angle&0x1f80;
  pos_hi=temp>>7;
  pos_low=angle & 0x7f;

  //Construct a Pololu Protocol command sentence
  buff[0]=0x80; //start byte
  buff[1]=0x01; //device id
  buff[2]=0x04; //command number
  buff[3]=servo; //servo number
  buff[4]=pos_hi; //data1
  buff[5]=pos_low; //data2
  
  //Send the command to the servo controller
  for(int i=0;i<6;i++){
    Serial.print(buff[i],BYTE);
  }
}

Thanks in advance.
Edit* controlling the Servo from USB clearly works so the problem seems to be with arduino, help me please! I’m planning on using the controller for an hexapod so i’m waiting for batteries, at the moment thought i just wanna get 1 servo working.

anyone? help please

Hello.

Based on some of the comments in your code, it looks like the example you have been working from was originally designed for one of our older servo controllers. The Maestro is different. If you haven’t found it already, here is the section of the Maestro User’s Guide that fully explains how to use the Maestro’s serial interface:
pololu.com/docs/0J40/5

You are not constructing the serial command properly:

  • buff[0] is wrong; it should be 0xAA[/li]
  • buff[1] is probably wrong because the default device number of the Maestro is 12
  • buff[4] and buff[5] need to be switched
  • a better name for the “angle” parameter would be “target” and the units of target must be in quarter microseconds (so 4000-8000 is the normal range)

Your wiring of the serial lines will cause problems because TX and RX are used to upload programs to the Arduino. I recommend that you connect the Arduino’s RX pin to some free pin on your Arduino and use the NewSoftSerial library to communicate with it. We have some example code that uses the NewSoftSerial library to communicate with a different product here:
pololu.com/docs/0J44/6.7.1

Your power situation is probably not ideal. I’m not sure exactly how much power the Arduino’s regulated 5V line can supply, but it is not likely to be enough for one servo. Until your batteries arrive, I recommend that you add a distinctive LED blinking pattern at the beginning of your Arduino sketch so that you can tell if your Arduino gets reset due to power issues.

Finally, make sure that your Maestro is in the right serial mode. The default, “UART, detect baud rate” should work for you but it if you know your baud rate ahead of time it is better to choose “UART, fixed baud rate” and enter the baud rate you will be using.

–David

Thanks for the response, this is the new code i’m using (coding isn’t my strong point)
i just need to be able to feed inverse kinematics angles as servo values into the put function.

void setup()// run once, when the sketch starts
{
  Serial.begin(9600);
}

void loop() //Main program loop, executes forever after setup()
{
  //Set servo position on port 0 to 3000 (Absolute Position)
  //Note: This function only has to be called once to update the position
  put(0,5000);
  //Delay so you can see the servo controller's serial status LED blink
  delay(1000);
}

void put(unsigned char servo, unsigned int target){
   //servo is the servo number (typically 0-7)
   //angle is the absolute position from 500 to 5500
   //Send a Pololu Protocol command
   Serial.print(0xAA,BYTE); //start byte
   Serial.print(0x0C,BYTE); //device id
   Serial.print(0x04,BYTE); //command number
   Serial.print(servo,BYTE); //servo number
   //Convert the angle data into two 7-bit bytes
   Serial.print(((target>>7)&0x3f),BYTE); //data1
   Serial.print((target&0x7f),BYTE); //data2
}

Its working now and responding to values, but after the comand the red light comes on, any reason why?
Thanks again

Your code looks good now. (It doesn’t support targets above 8191, but that’s not a big deal.) The red LED means that the Maestro experienced some kind of error. Please connect the Maestro via USB and use the Maestro Control Center to find out what the error is.

–David

The error is a serial protocol Error.
I checked the serial monitor on arduino and its outputing 8a,
any advice?

---- Tidied up the code and its working now, thanks for the help, take a look at the code above if there are any errors you can spot before i settle on this. Thanks so much again