Use pi-blaster to run ESC and servo motor from a Raspberry Pi
Inspired by PiBoat I also want to control an RC boat with the help of my Raspberry Pi Zero. Read about the first steps to get the boat moving.
Used hardware:
- Raspberry Pi Zero WH
- SanDisk Extreme micro SDHC A1 UHS-I U3 or similar
- M-F Jumper cables
- Tamiya 300054393 Electric Motor Type 380
- Hobby Wing Quick Run WP 1625 Brushed including manual
- Carson 500607017 Charger for Glow Plug, 230 V
- Carson 500502015 CS-3 Servo
Used software:
Find out about your OS version by running cat /etc/os-release
My kernel version is 4.14.98+ #2100
. To know yours, run uname -a
Don’t worry if the kernel version does not exactly match yours, as long as you use the stretch
release, this tutorial should work for you too.
Hardware configuration
Have the Raspberry turned-off with no power-supply attached and connect the pins according to the following graphics.
1. Connect the 7.2V battery and the motor to the ESC:
If you connect motor cables to the ESC in the wrong way, the motor will just turn into the reverse direction. Nothing to worry about, just switch the cables later on.
Be sure the motor is not attached to any propeller yet, in case something goes wrong during the configuration.
Now we need to connect the ESC and servo motor to the Raspberry Pi Zero. Get yourself knowledgeable about the available pins on the Raspberry:
2. Connect the servo motor by using the 5V, GND and GPIO 18 pin:
3. Connect the ESC to the GND and GPIO 17 pin:
Do NOT connect the 5V power supply cable of the ESC to the Raspberry. Plugging it in can burn your ESC or Raspberry. Having the ESC connected to the battery pack is good enough.
Software configuration
Install pi-blaster according to their instructions:
sudo apt-get install autoconf
git clone https://github.com/sarfata/pi-blaster.git
cd pi-blaster
./autogen.sh
./configure
make
To install & start at every boot, run:
sudo make install
Check if the daemon is running with sudo systemctl status pi-blaster
Alternatively, you can also start it manually with sudo ./pi-blaster
For our setup, we just need pi-blaster to work with GPIO pin 17 (ESC) and 18 (servo). Therefore I define that in the startup options:
sudo nano /etc/default/pi-blaster
Add the following line to this file:
DAEMON_OPTS="--gpio 17,18"
You can test the control of the servo steering by running:
echo “18=0.1” > /dev/pi-blaster
Getting the ESC to start the motor is a bit more complicated. First, turn the ESC on, so it starts blinking red. In order to start the motor, my hardware needs an initialization procedure.
You might find this in the manual for your ESC. In my case, there was nothing written inside and I found out by trial and error. Generally, it needs a value between 1000–2000us sent to the ESC. In my case, it is 1600us, which translates to 0.16
. This value is defined as the neutral point.
echo “17=0.16” > /dev/pi-blaster
After running this command, the ESC gave a long confirmation beep but has not yet started running the motor. In order to achieve that, you can run the same command (range between 0.08 and 0.2 should be safe).
echo “17=0.2” > /dev/pi-blaster
You can turn it off again by running:
echo “17=0” > /dev/pi-blaster
In case things do not work out with pi-blaster for you, you can also have a look at pigpio. It seems very well maintained and could help you get started.
You can also check out some of my other tutorials like connecting a camera to your Raspberry 📝🤖.