This tutorial will show you how to have the basic servo control using Raspberry Pi and Pololu Maestro. The implementation of the following instruction can be used for hand gripper, robot leg, or pan/tilt camera.
- Raspberry Pi Model A 256MB
- Pololu Maestro USB 6-Channel Servo Controller
- MG946R Towardpro servo (or similar)
- Power supply: 1300mAh 11.1V LiPo baterry
- UBEC 5V 5A with the right connectors
- A laptop running Ubuntu or Mint
- 4 leads with different colours: Black, Red, Blue, and Yellow
- SD Card 8GB loaded with Rasbian OS
- USB Wifi Dongle
- Raspberry Pi power supply or USB to microUSB lead to power it up with your laptop USB
- Wireless Router
Software list on the Pi:
- Pololu manufacturer driver and application supplied for initial testing purpose
- Pololu Python3 driver (you can code your own, or modify someone else’s)
- CherryPy or Tornado web server installed for Python3
- Client side codes: JQuery, HTML5, CSS
- SSH access enabled
- Wifi connection enabled
Setting Up the Pi
Insert the SD card, insert the USB Wifi dongle, connect the power, and make sure you can boot and SSH into the Pi from your laptop. There are many tutorials on how to do this, will not be covered on this note.
Turn off and power off Pi before you connect any peripherals.
Setting Up Pololu Maestro
There are 3 components to be connected with the Maestro:
- Raspberry Pi
- Power line
1. Pololu Maestro – Raspberry Pi GPIO wires setup:
- Connect Pi GPIO 5v pin with red wire to Pololu Maestro VIN pin
- Connect Pi GPIO ground pin with black wire to Pololu Maestro GND pin
- Connect Pi GPIO TX pin with blue wire to Pololu Maestro RX pin
- Connect Pi GPIO RX pin with yellow wire to Pololu Maestro TX pin
2. Pololu Maestro – Servo setup:
- For a start, please use Mid-size servo like MGR946R or any servo with similar spec
- Connect servo wires respectively with the following channel 0 pins on Maestro: SIG, PWR, GND
- To connect more servos, you can use any of the remaining channels 1-5.
3. Pololu Maestro – Power setup:
- Pololu Maestro accepts 5V power input for the control circuit, so Pi GPIO 5V pin is sufficient for this purpose.
- Pololu Maestro relays whatever power you supply for the servos. In this exercise, 11.1V LiPo battery connected and voltage-converted via UBEC 5V 5A is perfect to power up to six servos. A typical mid-size servo will run on 5V-6V and use up to 1A under a heavy load. Please check your servo spec before connecting any power.
See below picture for complete setup
Let’s prepare the basic building blocks to control a servo via the Internet. For this you must be familiar with basic Python3 codes, HTML5, and JQuery.
A simplistic view of the application connectivities are as follows:
Client-side controller interface -> Python 3 Web Server (Via CherryPi or Tornado WebSocket) -> Python Driver – > Servo
Pololu Maestro Python 3 Driver
The following Python 3 driver can work for basic servo tasks: Device.py. Feel free to modify it to suit your needs. This is an open-source public property. If you could come up with awesome improvement to the Driver, don’t forget to upload it on GitHub and share it with all of us.
To test if it works, you can download and run this Device-tester.py file for basic servo sweeping command.