The classic electronic speed controller (ESC) can be found in RC cars, boats and model planes. I have always used H-bridges for my robot cars which are connected to the Raspberry Pi computer with a variety of cables. Connecting the H-bridges with up to six cables has always offered potential for errors, e.g. a loose contact or a loose plug. With an electronic speed controller (ESC) connected to a servo controller like a PCA9685 with only one plug with three contacts, the risk of errors is significantly lower.
For my project Donkeycar I had to install a speed controller like the following one. So I had to deal with the connection and the control in connection with a Raspberry Pi.
In addition to the electronic speed controller, a PCA9685 servo controller and a Raspberry Pi are required. The servo controller is connected to the I2C bus of the Raspberry Pi and offers 16 connection possibilities for standard RC components such as servo motors and the above mentioned speed controller.
For the PCA9685 servo controller there is an Adafruit library which makes it very easy to control it from a Python program. I have written a series of articles under the following link which introduces the PCA9685 servo controller and explains step by step which software is required.
Tutorials PCA9685 Servo Controller: 16-Channel PCA9685 Servo Controller – Part 1 Introduction and connections
The following picture shows a Raspberry Pi with a servo controller connected to the I2C bus. The servo controller itself needs 5V to supply the servo motors with power. This cable is not yet connected and you only need it if your ESC does not support BEC.
Raspberry Pi with PCA9685 servo controller
I installed the RC model speed controller in my Donkeycar and connected it to the small DC motor of the model car. In the model I work with voltages of 7.2 V and 5V for the Raspberry Pi and the servo controller. After connecting the speed controller to channel 0 of the servo controller I could control it with my Python program.
Python Program – Control an electronic speed controller
With the small Python program I wrote it is possible to control a speed controller on channel 0 and a steering servo on channel 1 of the servo controller. So it is possible to remote control almost every RC car with a Raspberry Pi and the Python program with the keyboard via SSH.
The program is available for download at GitHub: GitHub – Python program RC electronic speed controller
The Python program esc.py can be started with the following command. A text menu then appears after typing e.g. the up arrow key. The RC model car can be remote controlled using the arrow keys on the keyboard.
Command: python esc.py
The following picture shows the text menu of the Python program for the remote control of the RC car.
Once you have understood how a RC modelling speed controller can be controlled with a Raspberry Pi, you don’t really want to build an H-bridge anymore. Compared to an H-bridge you save a lot of cables and can use standard RC components.
But you have to play with the zero position of the speed controller. Please refer to the documentation in a program. Only if the zero position of the lever for acceleration is correct to the throttle used, it can be activated and the car drives forward or backward. The zero position should be between 380 and 420. My Python program is written accordingly.
Übersicht der PCA9685 Servo Kontroller Anleitungen:16-Kanal PCA9685 Servo Kontroller - Teil 1 Einführung und Aufbau
16-Kanal PCA9685 Servo Kontroller - Teil 2 Software Installation und Test
16-Kanal PCA9685 Servo Kontroller - Teil 3 Ansteuerung einer L298N H-Brücke
16-Kanal PCA9685 Servo Kontroller - Teil 4 Ansteuerung eines LED Bandes mit Dimm-Funktion
16-Kanal PCA9685 Servo Kontroller - Spezial: Raspberry Pi elektronischer Modellbau Fahrtenregler