Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Arduino + Pololu Micro Serial 8 Servo Controller


#6

Really? This Page says you can control up to 20 servos directly with the Arduino. Anyway, once you get it working you should totally post your code on the Arduino forums (and here too).

Looks like a pretty sweet setup you’ve got there! I like the clever use of the ServoCity servo gearbox. If you’re looking to build a new mount anyway, they make some nice compact pan/tilt servo platforms now, with and without downgearing.

I don’t actually have an Arduino board to verify this on, but I can try it out on another ATMega168 board at work. An Arduino program to control the servo controller in Pololu mode should look something more like this:

void setup()// run once, when the sketch starts
{
	Serial.begin(9600);// set up Serial library at 9600 bps
}

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

	unsigned char buff[6];

	unsigned int temp;
	unsigned char pos_hi,pos_low;
	
	temp=angle&0x1f80;
	pos_hi=temp>>7;
	pos_low=angle & 0x7f;

	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

	for(int i=0;i<6;i++){
		Serial.print(buff[i],BYTE);
	}
}

void loop()// run over and over again
{
	put(0,3000);
}

If you have everything powered up, the Arduino and the serial servo controller on a common ground, and Pin1 (TX) of the Arduino connected to the Logic Level Serial Input pin of the serial servo controller, this should send servo 0 to it’s center position.

Any luck?

-Adam


#7

Adam,

Thanks for the code. I’m getting a solid yellow with the blinking red LED with no servo movement.

Is this code for the Pololu mode? I tried it in both modes and had the same results.

Tomorrow I’ll take a closer look at it.

Thanks for the help,
Phil


#8

This code is for Pololu mode. I don’t have a board to test it on at home, but I have a theory about what might be going wrong. The flashing red LED indicates a fatal error, probably unintelligible serial data.

The Arduino boards use a serial bootloader, so you don’t have to buy a separate programmer to download programs to the microcontroller. When you download a program to the Diecimila over the USB connection, the data goes through a USB/serial converter chip and into the serial input pin on the microcontroller (Pin 0 on the Diecimila board). The chip responds with checksum and verification information, which goes back through the USB/serial converter to your computer. Unfortunately, I think this programming response data is also going out Pin 1 of the Diecimila board, and is confusing your servo controller.

Here’s a slightly modified version of the code from before:

void setup()// run once, when the sketch starts
{
   Serial.begin(9600);// set up Serial library at 9600 bps
   delay(100);
}

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

   unsigned char buff[6];

   unsigned int temp;
   unsigned char pos_hi,pos_low;
   
   temp=angle&0x1f80;
   pos_hi=temp>>7;
   pos_low=angle & 0x7f;

   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

   for(int i=0;i<6;i++){
      Serial.print(buff[i],BYTE);
   }
}

void loop()// run over and over again
{
   put(0,3000);
   while(1);
}

I’ve just added a startup delay at the beginning, and an infinite loop after it sends out the first servo command, so it should only send the servo position command once. After downloading this program to the Arduino, try power-cycling the servo controller (so the red LED isn’t blinking any more) then hitting the reset button on the Arduino. It should send just one correctly formatted Pololu mode servo command to the servo controller.

The servo controller takes just a little bit to start up before it’s ready to receive serial data. I’m not sure how that compares to the Arduino’s startup time, but with the startup delay you should be able to power on the Arduino and the servo controller at the same time (like by throwing the same power switch). If everything works, you can try shortening or removing this delay later.

So, any luck now?

-Adam


Arduino and Trex JR
#9

Adam,

  • Still no servo movement but the red LED is off.
  • Reseting the Arduino will make the green LED blink once.
  • Pressing the reset button again gives me another green LED blink.
  • Removing delay(100);, or changing it doesn’t effect the above results.

I was in San Antonio all day today and will be out again tomorrow until late in the evening. Relatives are visiting and I’m their tour guide. :confused:

Should I post the latest code on the Arduino forum to see if an experienced Arduino user can help out?

Thanks again…we must be getting close,
Phil


#10

I’ve been disconnecting the signal wire going to the Pololu servo controller when uploading the new code. It does error, red LED, if I keep it connected during the upload. Disconnecting it during an upload isn’t a problem.

Phil


#11

Except for the servo not moving that looks like proper behavior. I was able to test the code on a Pololu Orangutan just now (when you hit “Upload” on the Arduino compiler it generates a .hex file you can download to any ATMega168-based microcontroller board). It moved the servo just fine, so I’m wondering if the problem isn’t a hardware one now.

Feel free to post the code on the Arduino forums though, and the Pololu servo controller protocol in absolute mode is explained in a little more depth here.

The code I sent you is only trying to move servo 0, corresponding to the numbering on the back of the servo controller board. Also, how are you powering the servos?

-Adam

P.S. I need an excuse to get back down to San Antonio. My lab used to have a project that was tested at SWRI in San Antonio once or twice a year. We would road-trip down from Michigan in like 24 hours (rotating drivers of course). Basically we would break our robots all day and fix them all night, but in between we had a huge daily food budget! I’ve tried to smoke brisket at home, and it’s alright, but not even close.


#12

I just tried this code and it works GREAT! I was banging my head on the desk looking for examples for Arduino. I was also doing something wrong, I was trying to use the RS232 pin, but apparently Arduino uses +5V non-inverted Logic Level Serial. Also make sure to match the servo position! I was using “Slot 7” but I double-zero-based and put “6” as the servo number in the code. I moved the servo to the 1st slot (Slot 0), and it started turning!

For reference I am using Arduino Diecimilla, IDE 0010 Alpha.

You just helped me bring my robot to life again! I was up until 2AM last night. Thanks!


#13

Zagrophyte,

Congratulations on getting it working and confirming that the code is correct!

Now I need to find out what I did wrong. This is how I have mine connected.

  • Arduino USB powered with 3 wires going to the Pololu Micro Serial Servo Controller.
  • Nothing is connected to the Vcc=Vs jumper.
  • Arduino Power Gnd to Pololu GND (Black Wire)
  • Arduino Power 5V to Pololu VIN (Red Wire)
  • Arduino Digital 1(TX) to Pololu SIN (Yellow Wire)

Putting a volt meter on the servo power connections is showing 0v with 4.9v coming into the servo controller board from the Arduino. This must be why my servo isn’t moving.

Any idea what I’m missing?

Thanks,
Phil


#14

You’re missing the servo power! USB ports are limited to 500 mA max per port, and sometimes less than that depending on the hardware and device. A single servo could draw more than that moving a load, or just peak past that when it starts to move with no load.

Since servos take so much more power than the electronics, the servo bus has it’s own separate power line, so you need another power source connected to the Servo Power pins (just above the Servo 0 pins). The circuit board layout looks something like this:

The Vcc=Vs jumper connects the voltage regulator that powers the electronics to the servo power, so both the electronics and the servos can run from one power source, but it only works in that direction. So, your power choices are:

-Adam

P.S. I had these graphics left over from an old post, and honestly those were the most battery-looking batteries I could find on the MS word clipart search. By the way, your pictures look very professional!


#15

Adam,

Nice graphics! I’m going to use the one battery source configuration with the jumper and I’ll get it set up tomorrow and then post my results.

My pictures would be better if I used my tripod but I was in a hurry. Also the white background was an 8.5 x 11 sheet of paper and the black background is the poker chip case. :slight_smile:

Phil


#16

I forgot to mention another handy trick when using Arduino+Pololu. As long as they have a common ground (which they should) you can connect the reset pin of the pololu servo controller to the reset pin of the Arduino, so when you reset the Arduino, it automatically resets the servo controller!

I’ve tested this, and it works great even with the auto-reset when you upload your code from the IDE.

I think we definitely have enough information here to warrant a page on the Arduino Playground, as suggested earlier. This controller makes servo control so much easier and hassle-free (once you find out how to use it), and I’m sure many more people with Arduinos would buy one if they had a good reference at their disposal.

I cleaned up the code and added more comments:

/*
 * Pololu Protocol Example
 * For Pololu Micro Serial Servo Controller
 * by Adam Borrell (http://www-personal.umich.edu/~aborrell/)
 *
 * An example of using the Arduino board to communicate
 * with the Pololu Micro Serial Servo Controller 
 * https://www.pololu.com/products/pololu/0207/
 *
 * This example focuses on the Set Position (absolute) command, but
 * a wide variety of commands can be sent to the controller. 
 * Documentation on the other commands can be found at:
 * https://www.pololu.com/products/pololu/0207/ssc03a_guide.pdf
 * 
 */

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);
  }
}

#17

Also, to share how I’m using this controller–nice helicopter, by the way!–here is the robot I am building, “Ping”:


(Yes, those are Meccano/Erector Set pieces, I got a great deal at Wal-Mart for $50, can’t be beat for rapid prototyping!)

There’s a ProtoShield kit with optional breadboard stacked on the Arduino, and he is using a Parallax Ultrasonic Rangefinder for his eyes, which he uses to scan 180 degrees and look at the closest object. Soon I will have him seek out nearby objects in the room and perform actions based on various criteria, I’m not sure just what yet.

He currently he has no way to move around, but I hope to fix that soon with some stepper motors or tank treads. It was getting cumbersome controlling everything in one loop, taking (most of) the servo code out of the equation helps a lot!


#18

Nice bot there Zagrophyte! I also really like the reset pin trick, that way it doesn’t matter that the servo controller will be confused by the serial programming, since it gets auto-reset at the end.

Thanks for the nice code presentation too. If you’re going to make a playground page about it, I can pull some other Pololu protocol functions out of my code, and maybe you could Arduino-validate them. Actually, the only other one I really use on the servo controller is speed control. Basically you can set each servo to a slower than max speed, so that when you send a new position command, the servo controller splits it up into smaller steps over time. The servo still moves smoothly, with zero overhead to your MCU!

If you want to drive you robot with DC motors, Pololu also makes a bunch of DC motor controllers. Some are carrier boards for H-bridge chips that you PWM control, but they also make some pretty sweet open loop and even feedback-controlled serial motor controllers. All the serial devices use the same protocol, so you can daisy-chain them on a single serial line.

They don’t make a stepper motor controller, yet…

-Adam


#19

Zagrophyte,

Thanks for sharing your Arduino tips as I’m new to all of this. I agree you about there is enough information here to add a page on the Arduino Playground. I’m going to add a post about my project with pictures and video after I get it completed in the next 4-6 weeks.

I like Ping and he’ll look mean with tank treads. Be sure to post a video when he starts moving. I’d like to get a SRV-1, your Ping reminded me of it, but I don’t have the time to play with it for now.

I’m happy with my toys for now. :slight_smile:

Phil

[/url]


#20

Edit: There are some problems with the code I originally posted here, so I have removed it. Please read the rest of the thread, or jump here for working code!
Here are two more useful Pololu serial servo controller functions pseudo-translated (but untested) into Arduino code. Zagrophyte, if you would like to include these in your playground code, please check them on your Arduino first. I may have the speed limiting function comment backwards.

-Adam


usb16: code to control servo speed doesn't work
#21

Awesome! I’ll test\add those when I get home.


#22

I’ve added the jumper wire and the servos are powered by a 6v rc battery pack currently showing 5.5v while the Pololu board is powered. The yellow light stays on solid even if the only thing connected is the battery pack. The servo jumps when power is turned on.

Any ideas why the yellow led is on?

Phil


#23

My graphics aren’t totally clear about this (I only made them to illustrate the possible power connections), but I have a guess. You should disconnect the Arduino bus power line from your servo controller if you’re going to power it from the servo battery, which I’m guessing you did, but you still need the serial wire and a ground wire connection between the Arduino and the servo controller. Did you perchance disconnect both wires?

-Adam


#24

Ahhh…I did disconnect the ground wire. I’m charging up the battery pack and will try it again WITH the ground wire connected.

Thanks,
Phil


#25

IT’S ALIVE!

Thanks for your help an patience as I made every rookie mistake without frying the board. Now I have multiple servos moving and can begin working on servo routines.

Thanks again,
Phil