Driving up to 48 servos with a Spider controller

Controls more servos than you can fit on one robot :p
_48_servos_array.zip850 bytes

This tip/walkthrough will work with all Arduino Mega PCBs and their clones. I have found the instructions for the servo command to be a little vague so in this tip I will share my research.

The Spider controller is an Arduino Mega compatible PCB. Unlike the Arduino Mega the Spider controller was designed specifically to drive a large number servos. This made it ideal for this tip/walkthrough.

The Arduino servo library is capable of driving up to 48 servos. After a bit of experimenting I found that the servos can be assigned to any of the digital pins from D0 to D63. For those thinking that the digital pins only go to D53, analog pins A0 - A9 are digital pins D54 - D63.

For those who have never used the servo command before I will start at the beginning using the attached code as my example. The first line of the code "#include <Servo.h>" means that the instructions needed to generate the servo control signals will be included in the code to be uploaded to the microcontroller.

Before the setup() function you must define your servos same as you define your global variables. I've simply called my servos s00 to s47. You should name your servos with descriptive names to make your program easier to read.

The Servo command uses a timer for each 12 servos used starting with Timer 5. As these timers are also used for commands like PWM you need to plan your pin assignments to avoid conflicts.

1   to 12 servos use timer   5          disabling PWM on pins 44,45 and 46.
13 to 24 servos use timers 1&5       disabling PWM on pins 11,12,44,45 and 46.
25 to 36 servos use timers 1,4&5    disabling PWM on pins  6,7,8,11,12,44,45 and 46.
37 to 48 servos use timers 1,3,4&5 disabling PWM on pins 2,3,5,6,7,8,11,12,44,45 and 46.

Once you have defined your servos you need to attach them to the physical pins of the controller. In the setup() function you can attach your servos to any of your digital outputs. In my sample I have avoided digital pins 0 and 1 as they are used for serial communications. At this point even thought the servos have been attached to a pin they are not receiving any signals.

The first time you write to a servo using either the servo write() or writeMicrosecond() command the pin will be initialised and the servo will receive a control signal. depending on your application you may need to initialise the servos in the setup() function. In my example I initialise the servos in the loop() function.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

If you use more than one power source, you must be sure to connect the grounds.

Why did you find this marvel?  I googled and came up empty.  Curious inventor doesn't seem to be carrying them anymore.

The Spider controller used in the video is prototype. The final product is being manufactured now and will be available in a few weeks.

Interesting~ I had same code as you used but I was using mega with i/o shield but they are not working like yours. Could that be the reason cuz you using spider?

12 servos works fine but it won't work after 12+

It looks like you have servos on pins 11 and 12 whitch are required to be open for more servos.

There is nothing special about pins 11 and 12. As I mentioned above, the servo command disables PWM on some pins due to the fact that the timers are required for both functions. The more servos you connect, the more PWM pins are disabled.

I could not understand why you have a problem. The Spider has no unusual hardware apart from the switchmode power supply.

There are only two reasons I can think of for your problem. Either your code ties up timer 1 somehow or your electronics is faulty. Perhaps your grounds are not connected.

In my example the servos run from the same 5V supply as the processor. For larger servos requiring more current or higher voltage I would use an external supply with the grounds linked.