Building a robot with Raspberry Pi? The Waveshare Motor Driver HAT provides dual H-bridge motor control plus servo outputs directly on the GPIO header.
Features
- TB6612FNG dual H-bridge, 1.2A continuous/channel
- 2-4 servo channels via PCA9685 PWM controller
- I2C interface (0x40), uses only 2 GPIO pins
- Separate motor power input (6-12V)
- Reverse polarity protection, thermal shutdown
Hardware Setup
- Mount HAT on Pi GPIO header.
- Connect DC motors to M1/M2 terminals.
- Connect servos to servo headers.
- Connect 6-12V battery to motor power input.
- Power Pi separately via USB-C.
Critical: Use separate power for motors to avoid brownouts.
Python Motor Control
from adafruit_pca9685 import PCA9685
from adafruit_motor import motor
import busio, board, time
i2c = busio.I2C(board.SCL, board.SDA)
pca = PCA9685(i2c); pca.frequency = 1000
m1 = motor.DCMotor(pca.channels[0], pca.channels[1])
m2 = motor.DCMotor(pca.channels[2], pca.channels[3])
m1.throttle = 1.0; m2.throttle = 1.0 # Forward
time.sleep(2)
m1.throttle = -0.5; m2.throttle = -0.5 # Reverse half
time.sleep(2)
m1.throttle = 0; m2.throttle = 0 # Stop
Servo Control
from adafruit_motor import servo
pca.frequency = 50
s1 = servo.Servo(pca.channels[14])
s1.angle = 0; time.sleep(1)
s1.angle = 90; time.sleep(1)
s1.angle = 180
Robot Build Guide
Line-Following Robot: Pi 4 + Motor HAT + 2x BO motors + 3-channel IR sensor + 7.4V LiPo.
import RPi.GPIO as GPIO
L,C,R = 17,27,22
GPIO.setmode(GPIO.BCM)
for p in [L,C,R]: GPIO.setup(p, GPIO.IN)
while True:
if not GPIO.input(C): m1.throttle=0.6; m2.throttle=0.6
elif not GPIO.input(L): m1.throttle=0.3; m2.throttle=0.7
elif not GPIO.input(R): m1.throttle=0.7; m2.throttle=0.3
else: m1.throttle=0; m2.throttle=0
PID Speed Control
Add optical encoders and implement PID: P corrects current error, I corrects accumulated error, D dampens oscillation. Start with Kp=0.5, add Ki=0.1, then Kd=0.05.
Frequently Asked Questions
Can I control steppers?
Small bipolar steppers up to 1.2A per coil. Use A4988 for larger steppers.
How many motors?
Two DC + up to 4 servos. Chain PCA9685 HATs for more.
Works with Pi 5?
Yes, GPIO header compatible. Use latest Adafruit CircuitPython libraries.
Motors stutter at low speed?
TB6612 PWM at very low duty cycles may not overcome static friction. Set minimum throttle to 0.3.
Conclusion
The Waveshare Motor Driver HAT is the simplest way to add motor control to Pi robots. HAT form factor eliminates messy wiring, and Python libraries make control straightforward.
Browse the full Waveshare collection at Zbotic.in with fast shipping across India.
Add comment