Comprehensive Pi Servo Hat Setup Guide: Hardware, Wiring, and Python Control
Introduction
The SparkFun Pi Servo Hat expands a Raspberry Pi’s capabilities, allowing you to control up to 16 hobby servos via an I2C bus. By off‑loading servo power and communication to the Hat, you free the Pi’s GPIO pins for other projects and gain a convenient serial terminal for headless setup.
Required Materials
To follow this guide, assemble the following items. We recommend a blank microSD card rather than a NOOBS card, as newer OS images are required for Pi Zero W support.
- Break Away Headers – Straight
- Wall Adapter Power Supply – 5.1V DC 2.5A (USB Micro‑B)
- microSD Card with Adapter – 16GB (Class 10)
- Raspberry Pi GPIO Tall Header – 2×20
- Raspberry Pi Zero W
- SparkFun Pi Servo HAT
Finally, acquire a hobby servo for testing. A generic sub‑micro servo is a good starting point for the example scripts.
- Servo – Generic (Sub‑Micro Size)
Required Tools
No special equipment is needed beyond basic soldering supplies. For best results, use a 30W soldering iron and lead‑free solder.
- Solder Lead Free – 15‑gram Tube
- Soldering Iron – 30W (US, 110V)
Hardware Overview
The Hat is intentionally simple. Key components include:
- USB Micro‑B Connector – Supplies 5 V to the servos and can also power the Pi. It also provides a serial console that lets you configure the Pi without a monitor.
- Power‑Isolation Jumper – Closed by default, connecting the servo rail to the Pi’s 5 V rail. Clear it when you run multiple high‑current servos to prevent noise from resetting the Pi.
- Servo Headers – 16 0.1‑inch spaced pins, pre‑arranged for standard hobby servo connectors.
Hardware Assembly
We recommend soldering the male headers onto the Pi Zero W first, then attaching the Pi Servo Hat. A quick technique:
- Solder a single pin to the board.
- While the solder is still hot, tilt the board so the pin sits flat, then secure the header in place.
- Finish soldering the remaining pins.
Repeat the process with the female header and the Pi Servo Hat, ensuring the short pins insert from the bottom of the board. Keep the headers level before completing the solder joints.
Once assembled, stack the Hat on the Pi Zero W. Connect a hobby servo to channel 0, referencing the servo’s datasheet for pinout. Use a 5 V wall adapter to power the Pi and the Hat via the USB Micro‑B connector labeled PWR IN.
Software – Python
The Hat’s PWM controller is an I2C device, commonly accessed as SMBus. Full example code is available in the product’s GitHub repository.
Initialize SMBus
import smbus bus = smbus.SMBus(1) # I2C bus 1 on Raspberry Pi addr = 0x40 # Default I2C address of the PWM chip
Configure the PWM Chip
bus.write_byte_data(addr, 0x00, 0x20) # Enable PWM module bus.write_byte_data(addr, 0xFE, 0x1E) # Auto‑increment register addresses
Set a Pulse Width for Channel 0
bus.write_word_data(addr, 0x06, 0) # Start time (always 0 for 200 Hz) bus.write_word_data(addr, 0x08, 1250) # Stop time → 1.5 ms pulse
The PWM chip runs at 200 Hz (5 ms period). The stop register (0–4095) maps to 1.2 µs steps, so 1250 ≈ 1.5 ms, the neutral position for most servos.
To address other channels, add 4 to the register addresses:
| Channel | Start Addr | Stop Addr |
|---|---|---|
| 0 | 0x06 | 0x08 |
| 1 | 0x0A | 0x0C |
| 2 | 0x0E | 0x10 |
| 3 | 0x12 | 0x14 |
| 4 | 0x16 | 0x18 |
| 5 | 0x1A | 0x1C |
| 6 | 0x1E | 0x20 |
| 7 | 0x22 | 0x24 |
| 8 | 0x26 | 0x28 |
| 9 | 0x2A | 0x2C |
| 10 | 0x2E | 0x30 |
| 11 | 0x32 | 0x34 |
| 12 | 0x36 | 0x38 |
| 13 | 0x3A | 0x3C |
| 14 | 0x3E | 0x40 |
| 15 | 0x42 | 0x44 |
Each degree of movement requires 4.6 register counts. For example, a 45° offset from neutral is 207 counts (45 × 4.6), added or subtracted from 1250 to set the desired pulse width.
For more detailed examples, visit the GitHub repo and explore the included Python scripts.
Pi Servo Hat Hookup Guide
Manufacturing process
- Comprehensive Guide to Laser Marking: Types, Benefits, and Applications
- Industrial Hard Hats: Standards, History, and Future Trends
- Stetson Hat: From Frontier Innovation to Modern Icon
- FLIR Lepton Integration Guide: Hardware, Software, and Raspberry Pi Setup
- Raspberry Pi 3 Starter Kit Setup Guide – Assembly, OS, and Remote Access
- SparkFun Qwiic HAT for Raspberry Pi – Complete Hookup Guide
- Professional 40‑Pin Raspberry Pi Wedge Setup Guide
- Master Arduino Servo Motor Control: Step‑by‑Step Guide
- Mastering Power Hammers: A Comprehensive Guide for Modern Blacksmithing
- Servo Press Machines: How They Work & Their Advantages Over Mechanical Presses