Best way to operate and control 12 Servos

Hi there,
I am currently making a spider robot with 4 legs. Each leg contains three motors making it a total of 12 servo motors. Any suggestions for the best, clutter-free method to control all these servos?
Any help is much appreciated.

Hello
Take a view to get some additonal project ideas.

Have a nice day and enjoy coding in C++.

Considering that you may want to remote control your spider, you might not want to use all the timers you have available, the way standard servo.h does.
I'd send pulses to the servos manually, with a minimum frequency of 50Hz (a pulse every 20ms) and with not to many restrictions on the time between pulses. Pulses up to 50ms or even 100ms apart will still work fine.

To do this efficiently, you should

  • 'sort' the pulses by length first.
  • make sure at least 20ms has passed since the pulses were sent last time
  • start all pulses
  • stop the shortest pulse first and on to the next from there.

You will be holding up the program for the duration of the longest pulse (2.5ms or so) , but you will not use any resources used by any remote, and you can even leave interrupts turned on, although that may cause very slight inaccuracies. You will also still have PWM on all the pins that provide that, though you may not have a lot of pins left. You can use a pro-mini to control your robot.

I'm not sure what you mean by "clutter free" but if you want to avoid complexity with the servo wiring then consider using a PCA9685 board like Overview | Adafruit PCA9685 16-Channel Servo Driver | Adafruit Learning System. Up to 16 servos will plug into that board using their standard servo plugs and the wiring to the Arduino is just 2 pins.

Steve

Well, two Arduino I/O "pins" for I²C and specifically A4 and A5 for the Nano but the 5 V and ground must of course be connected.

The built-in Servo library (Servo.h) uses only Timer1 and can control up to 12 servos on any digital output pins.

Yes, but it depends on interrupts being turned on all the time, which causes conflicts with other libraries like softwareSerial and neopixel for instance.

Same could be said for running softwareSerial (or even hardware serial) along with neopixel. If it is unacceptable to have interrupts turned on, then the peripheral servo driver would be the best bet.

In short, if you propose to do any serious programming, you need the PCA9685. :sunglasses:

Hi,
Here is Adafruit's board and example;


Tom... :grinning: :+1: :coffee: :australia:

It could also be done using a TLC5940 but I think the PCA9685 board
would be much easier to use.

If I were you I wouldn't even waste the time or money buying a chip, it really isn't that hard to do like this ServoMotorWiring it might be a little cluttered but it's just a breadboard that has an external power source and then you connect each data pin to the data pin of the servo. As long as it isn't a really tiny robot this should be just fine.