I am in the process of building a model railway and I am putting an Arduino Mega at the heart of it to control turnouts and semaphore signals. Connected to the Arduino, I have 4 PCA9685 boards with a total of approximately 50 SG90 servos.
Inputs to the Arduino respond to the position of mechanical switches and the servos below the baseboard respond accordingly to move the blades of the turnouts in the track above. Programming takes care of the corresponding signals and also relays which change the polarity as the turnouts switch over.
I have tested the setup thoroughly on a small scale without any snags. However, as I have installed more and more servos I have experienced what I can only describe as "servo frenzy" when, for no apparent reason, a servo starts to thrash about, grinding its gears and usually resulting in the servo being trashed.
In the final configuration, the servos will spend almost all of their time in a "quiet" state in one of two positions moved only momentarily when needed to change a track or signal. I have introduced delays in the code to slow down the movement of each servo to eliminate the rapid flick which would occur otherwise.
Is anyone able to offer me advice about this? Is there something I can do to keep the servos (and myself) calm so that I can "finish" the electrical side of my project?
I would very much welcome and appreciate any help or suggestions.
@maxthesax Welcome to the forum!
First question - what are you using as a power supply for fifty SG-90 servo motors? When spinning the motor each SG-90 consumes about 550mA, of course, I expect you don't have all of them moving at the same time!
Second question - do your PCA9685 boards all have the filter capacitor installed, or is there a set of solder pads on each that are empty? Some of the "clone" boards don't come with the capacitor, usually around 100- 330uf.
As you might surmise I'm speculating that you may have a power supply issue, as noise on the supply can cause inexpensive servos like the SG-90 to act erratically. And the fact that it seemed to start happening as you increased the number of servos falls in line with a power supply issue, specifically noise on the power supply lines or a supply that can't provide enough current.
If you have an oscilloscope you could monitor the servo supply line and see if the noise increases as you add servo motors. Remember that even in a stationary position each servo will draw some current to power its internal feedback circuit, and these servos can also induce power supply noise themselves
If you don't have a scope no worries, you could try putting a few large-value electrolytic capacitors across the supply line to see if it has any effect.
Another possibility is noise or distortion on the servo control line(s) could be causing the servos to respond to "fake signals". Again a scope could sniff this out.
Just a few random thoughts, I don't even OWN fifty SG-90's so I can't duplicate what you are doing!
"Never trust a computer you can’t throw out a window." — Steve Wozniak
Thanks for your reply.
1) I am using a 5V 2A supply for the I2C boards, although I have wondered whether I ought to be using at least two.
2) The PCA9685 boards all have a capacitor fitted.
Some more information....
I have measured the current drawn by one servo. When stationary it seems to be 5-10mA, when moving it can be anything up to about 200mA although I understand it could potentially be more.
On this basis, 45 servos at 10mA and 5 servos at 200mA is still less than 2A - but as I mentioned there is no need for any to be moving simultaneously.
So far I have only had 20 servos wired in at the same time
Some servos are quite close to the supply, but the maximum distance is about 2 metres. I have measured the voltage drop at the furthest distance and it is about 0.02V. When the servos operate, the maximum voltage drop that I have measured is 0.15V.
I have tried capacitors up to 100uF at the servo end and it does not seem to make any difference to the voltage drop. But I haven't tried fitting capacitors to more than one (it would be a big project to fit capacitors to them all and I would need to feel that it would definitely would be beneficial). Should I be trying large capacitors at the supply end - if so, how large?
I have connected the power supply so that it connects to the PCA9685 boards and also to 2 bus wires (5V and GND) so that the servos are fed by a single data cable and take a feed from the bus wires. The bus wires are in the form of a ring and are much thicker than the cables attached to the servos.
The data wires are close together and it is not feasible to route them independently.
I have a small oscilloscope and will use to look at the noise as you suggest.
Thanks for your advice and your very fast response.