Daily Archives: August 8, 2016

A Raspberry Pi HAT with 16-Channel PWM Servo

DC servo motors are a few of the things that the single board computer, Raspberry Pi or RBPi, finds uncomfortable. The reason being the specific and repetitive timing pulses these motors require for setting their position, which the RBPi is unable to provide in the absence of a real time clock. Although the Linux kernel can do the job, it leaves the RBPi rather over taxed.

A HAT or Hardware Attached on Top board eases the situation. It takes care of all the timing requirements, runs and controls 16 Servos, and is capable of delivering pulse width modulated or PWM signals up to 1.6 KHz using 12-bit precision. Additionally, all this is completely free running that leaves the RBPi to handle everything else.

The 16-Channel 12-bit PWM/Servo HAT from Adafruit can drive 16 servos simultaneously or output PWM signals. It communicates with the RBPi through only two pins using the I2C protocol. Additional RBPi processing overhead is not required for the on-board PWM controller on the HAT board to drive all the 16 channels at a time. Moreover, you can stack more HAT boards – up to 62 of them and control 992 servos – all with only the same two pins.

Adafruit offers a Python library that you can use to immediately set up and run the servos to make your robotic system come to life. When you need to run several servos, this HAT and the Python library to go with it are the simplest and perfect solution.

The HAT board requires two levels of DC voltages. The 3V3 DC comes from the RBPi to power the PWM chip and to decide the logic levels for the PWM signals and the I2C signals. The voltage is available as soon as you plug in the RBPi – shown by the PWR or the red LED on the RBPi.

The other voltage is required for the servos, for which you need to supply 5-6V DC. Usually, most servos will be happy with only 5V, and will work a little more strongly if you give them 6V. You can connect this supply via the DC jack or the blue terminals on the HAT board. A reverse-polarity diode protects the board in case you have the wires connected in reverse. However, do not use both the DC jack and the terminal block at the same time.

Keep in mind that servos need a lot of current from the 6V DC supply. Even if you are using micro servos, they will draw several hundred mA when moving. Larger servos will need more power and you should have provision of about 2A for up to four servos. That means it is not recommended drawing this power from the 5V supply of the RBPi, as it could cause your RBPi to behave erratically. Keeping the servo power supply and the RBPi power supply totally separate gives good results.

On the RBPi, there is a place for soldering a through-hole capacitor. It is a good idea to use one if you are driving many servos. Switching motors generate dips and spikes on the power lines and these can upset the RBPi. A capacitor takes care of the sudden variations – use n*100µF, where n is the number of servos.