Page 1 of 1

Controlling many servos from rpi by the help of some avr-s

Posted: Thu Jan 03, 2013 8:09 am
by kulminaator
Another robot building attempt here.

My plan: building a snake from 8 servos (snake built from 9 sections, 8 servos to turn them (4 servos can turn the next part left or right and 4 servos can turn the next part up or down, the different turning directions would be interleaved for flexibility)).

Current design idea:
  • * RPI does the thinking and communication with the rest of the world over wifi
    * Atmel's avr-s (atmega328 in my case) are in charge of driving servos
    * RPI would communicate with the atmega over I2C bus from the GPIO connector.
    * Servos pick up timings from atmegas and turn the sections.
Current part list that i have:
  • * rpi with a nano wifi card
    * 2 atmega328 chips (and an avr dragon to program these over isp programming)
    * 8 digital servos (got them pretty cheap from hobbyking)
    * some leds and other common circuit parts (and a 3300 uF cap to stabilize the voltage)
    * 4xAA NiMH battery pack
Issues that i have to iron out:
  • * power (rpi and atmegas can share the power easily, putting the servos on the same power source is stretching it quite a bit (even with a big cap and when using the servos one by one))
    * stability of communication
    * debugging on the run what the atmegas are doing
    * having to write some C code for the avr-s to translate the I2C messages to servo states.

My reasoning why i don't drive the servos directly from RPI's GPIO:
1) too afraid to lose my RPI (it would take a while to order a new one)
2) i don't want to stress the timings, RPI is good at running linux and atmegas are good at timing servo signals, in addition the atmegas have 6 pwm channels each ...
3) atmegas have some other nice features that i may want to use at some point (i will still have several unused i/o pins

Little ascii art to demonstrate the idea too:

Code: Select all

 || /* I2C bus */
 ||                                               servo1 servo2 servo3  servo4
 ||  = atmega328   ---------(pwm channels) --------/-------/------/------/
 ||                                               servo5 servo6 servo7  servo8
 ||  = atmega328   ---------(pwm channels) --------/-------/------/------/
 ||  =  /* any other future device i  want to add here, as long as bandwidth can take it */
If you have any good suggestions to share, please do (and if you want to steal part of the idea, please do, i don't mind).

Re: Controlling many servos from rpi by the help of some avr

Posted: Thu Jan 03, 2013 4:45 pm
by rew
If you want you can buy: i2c_servo or spi_servo. Each board handles up to 7 servos. You can daisy chain as many as you want from a raspberry pi. (well, ok. there is a 120 maximum per bus, so with two SPI and one I2C bus, you'd get into trouble after 2520 servos. :-) )

Then you can concentrate on programming the 'pi. The AVR doing the PWM for the servos has already been done, as well as the communications protocols.

Re: Controlling many servos from rpi by the help of some avr

Posted: Thu Jan 03, 2013 7:42 pm
by kulminaator
rew wrote:If you want you can buy: i2c_servo or spi_servo.
Well ... it's a bit too late to change my mind right now, but i will keep these in mind for any next attempts for sure, they look as if they can save a bunch of time :-) Nice products (and a nice price too).