I am trying to control about 200 servo motors. I have never done anything this large before.
I am planning to use a shift out register. However, I can not figure out how to program my arduino to control the shift register. I can turn LEDs on and off but servos are creating difficulty for me. I am not sure what the code should look like.
You can plan this but you can't do it. A servo needs a pulse position modulation signal and a shift register can only supply a steady logic level. That's why you can't figure out how to program it, it can't be done.
Some servos can use PWM (although others it will damage), you can get 16 PWM outputs using a TLC9540. You can chain these together and so you will need to chain 13 of them for the number you want. There is a library to control these but you will have to hack it to get it to cope with 13 ICs.
there are pwm chips out there that can control 40 servos but for the price it would be just as easy to get some atmega32 chips and set them up as master slave. I'm not sure how hard it is though to run all pins as servo outputs.
You should be able to program these using an FTDI-cable (~13$ at Sparkfun). Then you could buy 4 and have 1 master and 3 slaves. That should provide control over 48*4 servos with the standard Arduino servo library + plenty of I/O's and ADC's to spare. And it may be both cheaper and easier than buying a MEGA board + 9-10 TLC5940 chips.
BUT I'm not sure this is possible, however worth researching...
This servo shield uses only 4 pins to control up to 16 servos. It's based on two 4017 decade counter chips. I'm not suggesting you buy like 10 shields but rather the chips themselves...
PS: Please keep us updated on this (no offence) looney project of yours ... 200 servos (!!!) I LIKE it ...
EDIT: Just did a quick google on this chip and they cost only 0.23$ each!!! If you make this work it would be AWESOME...
That's an interesting product and although it does significantly reduce the number of pins needed it would need more timers to control more servos. Although it can support up to 16 servos on a Duemilanove, the resolution is 25 microseconds (compared to 1 microsecond using the Arduino library) although this may be enough if movement in steps of around 5 degrees is acceptable.
In short, you may need just as many Arduino boards to control 200 servos with 4017 chips as with digitalPins for each servo
Ah! Off course...the timer issue...And here I was having wet dreams about all the things I could do with 4017 chips
But off course steps of around 5 degrees isn't acceptable at all...
However I remember something westfx said in another thread:
For each timer the chip has, you can easily control up to 10 servos. Since the ATmega168 (and 328) have three (or even 6, depending on how you count), you can control more servos than there are pins.
So since the 4017 seemingly uses the Arduino timer(s) I'm not sure whether the low resolution is due to it's hardware or the library that goes with it? Shouldn't it be possible to control ATLEAST 30 servos from an atmega168/328 using a similar "low tech" chip with a DECENT resolution? What use is this shield with a resolution THAT low?
Timer0 is used for millis and delay so that leaves timers 1 and 2. Timer 1 is used for the Servo library, you could drive a 4017 but you would be controlling two less servos.
Timer two is an eight bit timer so either has much lower resolution or it needs lots of interrupts.
I was wondering how it was possible to control 32 servos based on an Atmega168?! But I thought maybe the 4 tiny chips (which I can't identify) had their own timer or something?! Like I suppose is the case with the TLC5940?!
That product is just an ATmega8 with dedicated software to drive servos. Those small chips are just shift registers 74HC595. The schematic for this is here:- http://www.lynxmotion.com/images/data/ssc32sch.pdf
So there is nothing here that you can't do with a normal arduino board.
Aha! So it IS possible to control servos via a shift register. I don't mean to nitpick but doesn't that sorta contradict your previous statement? :-/
A servo needs a pulse position modulation signal and a shift register can only supply a steady logic level. That's why you can't figure out how to program it, it can't be done.
It also shows that it's possible to control up to 32 servos from an Atmega168 and still get a proper resolution. Off course the Arduino servo libraries don't work here so you'd have to write your own. And I suppose it would occupy all the timers so you'd no longer be able to call functions like millis() or delay() without messing with the servos' timing?! But if we're talking a dedicated servo slave MCU setup it wouldn't be a problem.
So it does seem like an option and both the Atmega168 and the 74HC595 are cheaper than a TLC9540.
The 7HC595 approach is similar to the 4017 discussed above, you need the ATmega168 to provide the timing. Getting a 168 to handle 32 servos accurately while responding to serial requests would not be easy. So you should factor in the time and effort to design debug and test the code before deciding which is the 'cheapest' route.
The TLC5940 handles the timing for you and there is a library to drive it. [u]Avnet[/u] seem to have the SMT version in stock for $3 each. The DIP version is only $2.75 but you would need to check when they are expecting them back in stock
I don't mean to nitpick but doesn't that sorta contradict your previous statement?
No nitpick away, that is the nature of electronics.
It is a trueisim that any statement made can be proved to be wrong given enough hoop jumping. It's a game played by generations of engineers, and the more experienced you are the better you are at playing it.
Basically a shift register (in this context) is something to expand the input or output capability of the processor. Therefore anything that can be done by a GPIO can be done through a shift register output pin. It is 'just' as mem says a matter of getting the software timing right.
Everything has it's advantages and disadvantages and with me not knowing what delicate state your knowledge was at tended me to advise you against trying something that was tricky. The point I was trying to make was that you just couldn't stick a shift register on and expect it to produce the PPM signal to drive a servo.
The point about that board is that it is doing nothing else but drive the servos so there is no other demands on the software, something that would not be the case for you.
As I always say I offer a money back guarantee on all advice.
About the (delicate) state of my knowledge: well I don't know much...just enough to be dangerous
But I am aware that it would be tricky to say the least using a 7HC595 for servos. However the AVR code for the SSC-32 board is open source and can be downloaded here:
So perhaps someone will "hack" it into an Arduino library som day?!
The reason I like the 7HC595 so much is because it's cheap and readily available everywhere. EVEN here in Argentina I can get it within a few hours (for ~0.50$). While the TLC5940 I'd have to buy off the internet, wait a month and then see what happens I HATE internet shopping!!!
Still I would also advice anyone to use the TLC5940 rather than the 7HC595 given the circumstances. Just trying to eplore the options
PS: The Atmega1280 breakout boards I mentioned earlier...any reason they couldn't be used as a standalone MEGA board??