Controlling 12 Micro Servos with Servo Library

Hi there, I’ve hit a little roadblock while working on a robotic arachnoid quadruped. Here’s the setup:

(Ignore the power regulator circuit, I’ve stopped using it)
Imgur

As you can see, it is a four-legged robot powered by 12 small servos from Sparkfun (http://www.sparkfun.com/commerce/product_info.php?products_id=9065), with four-segmented legs printed on a MakerBot. I’m currently using a CD as a test chassis and powering the motors off of a breadboard connected to a 6V / 800 mA RadioShack wall wart. Control cables are connected to digital outs 2-13 on a new Duemilanove. Arduino ground (digital side) is connected to breadboard ground.

I seem to be having a problem with the servos. At first, they were going completely haywire until I realized I needed to add pull-down resistors to the control cables. They are now coherently addressable, but are giving me a harder to track problem: When I first supply power to the motors and turn on the Arduino to control them, several of them often go haywire and try to spin in directions they shouldn’t be. As far as I’ve figured out, the only way to fix this problem is to cut power to the motors, unplug the control cables, bring power back up on the motors and then plug the control cables back in, one by one (the motors then spinning solidly to the correct angles, one by one)… And even then they sometimes end up going bonkers again. I’ve found that it happens more often with a few of my motors than it does with the others, and that it’s more likely to get stuck in “freak-out mode” when more motors are being controlled.

I’ve thought of several possible causes but I’m not sure how to determine which one is the culprit and was hoping that maybe a member of the community here would point out an insight about controlling servos that I wasn’t aware of? Perhaps not enough voltage or amperage? Crappy servos? Incorrect pull-down resistor ratings (mine are a mix between 10k and 100k, I believe)? Something about refresh times with the Servo library?

Below is my code. Thanks in advance!

#include <Servo.h> 
 
Servo One_1;
Servo One_2;
Servo One_3;
Servo Two_1;
Servo Two_2;
Servo Two_3;
Servo Three_1;
Servo Three_2;
Servo Three_3;
Servo Four_1;
Servo Four_2;
Servo Four_3;
 
void setup() 
{ 
  One_1.attach(2); 
  One_2.attach(3);
  One_3.attach(4);
  Two_1.attach(5);
  Two_2.attach(6);
  Two_3.attach(7);
  Three_1.attach(8);
  Three_2.attach(9);
  Three_3.attach(10);
  Four_1.attach(11);
  Four_2.attach(12);
  Four_3.attach(13); 
} 
 
void loop() 
{ 
  setEverything(90);
} 

void setEverything(int x)
{
  One_1.write(x);
  delay(25);
  One_2.write(x);
  delay(25);
  One_3.write(x);
  delay(25);
  Two_1.write(x);
  delay(25);
  Two_2.write(x);
  delay(25);
  Two_3.write(x);
  delay(25);
  Three_1.write(x);
  delay(25);
  Three_2.write(x);
  delay(25);
  Three_3.write(x);
  delay(25);
  Four_1.write(x);
  delay(25);
  Four_2.write(x);
  delay(25);
  Four_3.write(x);
  delay(25);
  return;
}

Hmm, one of my servo examples (Servo > Sweep) says this

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created

At first, they were going completely haywire until I realized I needed to add pull-down resistors to the control cables.

You do? I am playing around with a servo too, and I don’t need one…

800 ma may not be enough to power so many servos. A good test for power issues is to unplug all but one servo and see how it works. If it works ok, add additional servos one at a time and see if performance starts to degrade as more servos are added. Your resistor seems strange.

Thanks for the suggestions. I posted this problem on the Sparkfun forums as well and they also targeted the 800mA power supply as a problem, mentioning that it’s “dirty” power, too. They suggested using individual 7805 regulators for each leg (three servos each), but I don’t really know much about power regulation or the capacitors used in such applications. Are there any good tutorials out there? Also, it looks like this sucker is gonna need a good 3-4 amps… Since I don’t want to use battery power while testing it out, are there any wall adapters that can output that kind of amperage?

Richard Crowley: I like your idea of power-up sequencing. I’ll probably end up building that in :slight_smile:

If you got an old computer power supply, you could use that for testing. :)

800 ma may not be enough to power so many servos

There's no "may not" about it: Sparkfun says their servo is similar to an HS-55. The HS-55 datasheet (sorry, you'll have to google it yourself: too much trouble to dig the URL out of all the bleep google wraps it in) says the running current is 180mA per servo.

So the 800mA power supply is almost certainly overtaxed even during some normal operations. At power-up time, with (nearly) all the servos running simultaneously to reach their "home" positions, it'll be completely hopeless.

Ran