The default library in Arduino can handle 12 servos at once on the Pro Mini. This is already quite useful, but if you look closely, there is a total of 20 pins that can be used for digital output. We will need two of them for I²C, but the rest could be used for servos. All we need is a library that handles that.
When @The Big One constructed his #Stubby the (Teaching) Hexapod, he had to write such a library that could handle 18 servos at once. I took the liberty of borrowing his code, and with just minor adaptations for the ATmega328p and accounting for the Arduino environment, I got it working. There were two issues to be solved.
First, the code refused to compile. That was because ATmega328p has no PORTA port, and because some of the syntax in the C file required C99 dialect. @The Big One told me about the PWM_PORTA_UNUSED macro that avoids the former, and renaming the file to "pwm.cpp" resolved the latter.
Second, the PWM signal generated stubbornly had about 6.1Hz instead of the requested 50Hz. After some experimenting with my new oscilloscope, I determined that the problem only appers when the prescaler is set to 1 or 8, and not when it's set to higher values. That kept me lost for several hours, until, in a flash of intuition, I added zeroing the timer prescaler bits, instead of just setting the ones that were supposed to be 1. Turns out the Arduino code apparently sets its own prescaler for that timer, and the two settings were getting OR-ed.
So for now I have code in the repository that sets 18 servos to their centers and then proceeds to doing nothing at all. Now I just need to add some basic I²C communication there.
There has also been some progress on the hardware part of the project. The prototypes so far were made using a stripboard, but now I want to have a proper PCB. I figured out that if the PCB itself is thin enough, and the holes for the signal headers are alternating, I could simply plug that PCB under the actual Pro Mini without soldering, and maybe add two jumpers to make sure the power connection is good. I designed a board with that in mind:
It even has room for an optional capacitor! I didn't order it yet, however, because it's considerably smaller than the 5×5cm limit, so I can panelize and get several boards in a single order.
Discussions
Become a member
In order to follow projects & hackers or give likes
Already a member?you need to create an account.