Will all 12 of the servos need to run at the exact same time? Or will they be going on and off in intervals (for instance, 1 moves, then 3 move, then 2 move ... etc ....)?
I just recently completed a project that runs 18 servos from two Decimilia boards, which were networked via serial communication between the two. At any given time however, the maximum amount of servos running at the same time was 3. I had an external power supply for each board - each powering 9 servos from 5V. The power supplies were providing about 1000 MA each which was necessary.
The machine ran very well, and is currently functioning in a gallery as part of an exhibit for hours and hours on end.
heres the code for the "sender" board:
/*----------------------------------------------------------------oooo
nick bruscia
091307
homeostat v 1.3
board 1 (sender)
/----------------------------------------------------------------oooo */
int SERVOa = 12;
int SERVOb = 11;
int SERVOc = 10;
int SERVOd = 9;
int SERVOe = 8;
int SERVOf = 7;
int SERVOg = 6;
int SERVOh = 5;
int SERVOi = 4;
int MIN_PULSE = 500;
int MAX_PULSE = 2000;
int lastPulse;
int lastFunc;
int lastFunc2;
long randNumber;
long randFunction;
long randFunction2;
//----------------------------------------------------------------oooo
void setup()
{
int i;
pinMode(SERVOa, OUTPUT);
pinMode(SERVOb, OUTPUT);
pinMode(SERVOc, OUTPUT);
pinMode(SERVOd, OUTPUT);
pinMode(SERVOe, OUTPUT);
pinMode(SERVOf, OUTPUT);
pinMode(SERVOg, OUTPUT);
pinMode(SERVOh, OUTPUT);
pinMode(SERVOi, OUTPUT);
Serial.begin(9600);
randomSeed(analogRead(0));
//---------------------------------------------o
// pull servos to their respective maximums
for (i=0; i<10; i++)
{
digitalWrite(SERVOa, HIGH);
delayMicroseconds(MIN_PULSE);
digitalWrite(SERVOa, LOW);
delay(20);
}
for (i=0; i<10; i++)
{
digitalWrite(SERVOb, HIGH);
delayMicroseconds(MIN_PULSE);
digitalWrite(SERVOb, LOW);
delay(20);
}
for (i=0; i<10; i++)
{
digitalWrite(SERVOc, HIGH);
delayMicroseconds(MIN_PULSE);
digitalWrite(SERVOc, LOW);
delay(20);
}
for (i=0; i<10; i++)
{
digitalWrite(SERVOd, HIGH);
delayMicroseconds(MAX_PULSE);
digitalWrite(SERVOd, LOW);
delay(20);
}
for (i=0; i<10; i++)
{
digitalWrite(SERVOe, HIGH);
delayMicroseconds(MAX_PULSE);
digitalWrite(SERVOe, LOW);
delay(20);
}
for (i=0; i<10; i++)
{
digitalWrite(SERVOf, HIGH);
delayMicroseconds(MAX_PULSE);
digitalWrite(SERVOf, LOW);
delay(20);
}
for (i=0; i<10; i++)
{
digitalWrite(SERVOg, HIGH);
delayMicroseconds(MIN_PULSE);
digitalWrite(SERVOg, LOW);
delay(20);
}
for (i=0; i<10; i++)
{
digitalWrite(SERVOh, HIGH);
delayMicroseconds(MIN_PULSE);
digitalWrite(SERVOh, LOW);
delay(20);
}
for (i=0; i<10; i++)
{
digitalWrite(SERVOi, HIGH);
delayMicroseconds(MIN_PULSE);
digitalWrite(SERVOi, LOW);
delay(20);
}
Serial.println("servo's at highpoints");
delay(2000);
}
//----------------------------------------------------------------oooo
void randservo()
{
int i;
int pulse_width;
int function;
int function2;
randNumber = random(500, 2000);
randFunction = random(1, 19);
pulse_width = randNumber;
function2 = randFunction2;
//-------------------------o
if (randFunction >= 0 && randFunction <= 9)
{
randFunction2 = random(4, 13);
for (i=0; i<100; i++)
{
digitalWrite(function2, HIGH);
delayMicroseconds(pulse_width);
digitalWrite(function2, LOW);
delay(20);
lastPulse = pulse_width;
lastFunc2 = function2;
}
}
else if (randFunction >= 10 && randFunction <= 18)
{
Serial.print(randFunction, BYTE);
}
}
//----------------------------------------------------------------oooo
void randservo2()
{
int i;
int pulse_width;
int function;
int function2;
pulse_width = lastPulse - 300;
function2 = lastFunc2 + 1;
//-------------------------o
for (i=0; i<100; i++)
{
digitalWrite(function2, HIGH);
delayMicroseconds(pulse_width);
digitalWrite(function2, LOW);
delay(20);
}
}
//----------------------------------------------------------------oooo the simple loop
void loop()
{
randservo();
randservo2();
}