I am planning to make my very first arduino project, but the more I know about it, the harder it is to get the right answers.
Hope you guys can give me some good pieces of advice.
I need to control a lot of servos (at least 18) at the lowest cost possible, and i was thinking about using an Arduino Leonardo.
Why, you may ask.
Well, as far as I was able to learn the MegaServo library (now the standard Servo library) can control up to 12 servos per 16-bit timer.
On an Arduino Uno this means controlling 12 servos, while on a Mega we can attach up to 48 servos with its 4 timers.
Now, according to the datasheet the ATmega32u4 is equipped with "Two 16-bit Timer/Counter with Separate Prescaler, Compare- and Capture Mode".
So, I made my math and concluded that is theoretically possible to use up to 24 servos with the timers provided; but the board only has 20 I/O pins, so this means that the theorical maximum is lowered by 4.
This way controlling 18 servos seems almost an obvious thing.
The problems are the lack of experience (on my side) and of resources about this (internet's fault).
So, do you think is possible to do something like this? Am I missing something?
Every two cents is appreciated.
You are forgetting something.
It's all very well to control servos using all of the I/O pins, but you may wish to actually alter their positions or the pattern in which they operate - which means you need to use some I/O pins to communicate.
Are you telling me that using all the pins disables the usb communication?
I was planning to use a pc to send the servo positioning data to the arduino, who is in charge of reading it and controlling the servos accordingly.
Yeah, I could use a Mega or a Due, but i’d like to keep it as the last resort for 2 reasons:
- They cost much more (i could afford 2 leonardos and a meal)
- They are too big.
I apologize for my subbornness, but I am trying to understand how things work, not to find a way around my lack of knowledge!
Adafruit sells a 16-channel 12-bit pwm/servo i2c servo controller in their store. The unit has 6 address pins, so you can hook up 62 controllers, for a total of 992 servos/leds. You would control it via the I2C pins (A4/A5 on the Uno/Leonardo). From the description, the controller does all of the PWM support itself, so you wouldn't need any of the timers in the Arduino. I've not used it, but I've seen it in their online store. Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface [PCA9685] : ID 815 : $14.95 : Adafruit Industries, Unique & fun DIY electronics and kits.
Because you only use the i2c pins, you could drop down to a cheaper Arduino or clone to control it, if you don't need all of the extra pins in a typical Arduino board, or would prefer something that fits in a DIP package due to space concerns.
If you are primarily controlling the servos from a PC, you could by-pass the Arduino all together, and use a Pololu Maestro 24-channel USB servo controller (you could also use a serial connection from the Arduino to control it). Again, I've only seen it when I've gone to the online store, and I haven't used it in person: Pololu - Maestro USB Servo Controllers
Thanks for the tips, Michael!
I also found the servo shield 2 from renrobotics that should use the same principle.
I was going to buy it, looks nice and is cheap, but then I asked to myself: "why should I add 16 pins when there are 18 o them free?"
Controlling a Maestro from the Arduino is definitely interesting. Too bad their servo controllers are just too expensive!
Do you know if, attaching the I2C servo controller an controlling servos via both the arduino pins and the controller, there are significand imput lags or other problems?
I don't know.
I would have to imagine there is a lag to change the settings, as I believe i2c is 100 Khz, and you probably need to send several words. However, when you are actually running the things, it would off load from your microprocessor all of the necessary start/stop, etc. to do the PWM signals. You would probably need to do a deep dive on the appropriate data sheets to see what all of the details are.
The Maestro is capable of running a script without interaction from the micro controller. Of course that means it is yet another thing to learn.
I'll check those thing out, but I have the feeling I'll never know the answers until I actually try.
Thank a bunch for the help, see you next time! (maybe)
Indeed, it is.
You are my new hero.