I am trying to control the ESC (Electronic Speed Control) of my Traxxas RC car with my raspberry pi (rev.2). I have been looking through the internet and while I can find some projects that seem to have done it, none seem to be explaining: pin connections, init sequence on the PWM and how to program the control software.

The XL-5 has a 3-wire connection going into the micro receiver unit: a black one (ground), red one (power, assuming 5V), and a white (control).. this is as much as the Traxxas documentation provides.

I found that the ESC can get its power from the car battery connection so I am not sure whether the red/black is actually required.

I plugged the white wire into GPIO-18 and put it in PWM mode using the GPIO utility. I understand that an ESC expects an initialization sequence to start but I can't seem to figure it out. Any idea?

  • did you fix it out? I got the same question right now
    – user14852
    Commented May 13, 2014 at 20:24

4 Answers 4


I have resolved this. Thanks varesa for the note. Your information is correct but there are 2 elements that I think miss in all of the documentation I've ever found on this.

1) The pi is not the right PWM controller to do this if you need it to do anything else at the same time. Maintaining control over the pulse frequency requires its own controller. I added a PCA9685 board to the setup (Adafruit has a good product). That chip can control 16 PWM devices simultaneously. You communicate from the pi to the 9685 through I2C and the pi does a very good job with that. I use a 3.3v pin of the pi to turn the 9685 board on and off (it also gets 5V from a USB battery).

The 9685 has its own set of challenges but you can find pretty good doc on that. Basically, it runs a clock at 25Mhz. You set your frame size using a formula available in the doc. Remember that 20ms frames = 50Hz. It's a 12-bit controller so your values range from 0 to 4095. If your pulse need to be 1ms in a 20ms frame, that's 1/20 of 4096, which is roughly 200.

2) The second issue is that this ESC can be turned on in many ways. The documentation says you need to press the 'on' button until you get one red flashing light for full ON forward, full on reverse. If you keep your finger pressed, you then get 2 flashes and it goes into race mode, which is full ON forward, and no reverse. Then there's a third mode ('training') with 3 flashes for half forward, half reverse.

Here, the trick is to just keep your finger pressed until the light turns green and then release. Surprisingly, green means it is just ON. As soon as you will initialize the PWM controller and arm, the light will turn red, which means it is ready to move.

Really kinda tricky. The basic arming sequence is to turn on on idle, go to max forward, back down to max reverse and back to idle. (I actually don't think my code does this anymore as it just works)

I posted 2 small update videos on youtube if you want to see the product. It is very very far from what I want to do but it's a bit of progress. http://youtu.be/MYivzxwIl38 and http://youtu.be/IIzBZdOLWAk

I've been using github for my code, if you're interested. https://github.com/fpapleux/mcqueen


I am not familiar with that exact ESC, but I'd except it to work like any other.

The interface consists of three pins: GND, +5V, Signal

You have to connect the pi ground to the ESC ground, but the +5V is optional. You could probably power your pi from that if you wanted.

The signal itself is a PWM signal. It has a period of 20ms and pulse width of 1 to 2 ms, lets say mapped to values 0-100.

Normal usage should not need any initialization. You might need to center the value for a while to "arm" the ESC. Might not be so necessary on a car where the transmitter trigger re-centers. However imagine having a plane with the throttle stick set to max when you insert the battery.

After your ESC is armed, the PWM value should correspond to the throttle position. Pulse width of 1.5ms is centered, 2ms is full forward, 1 ms is full reverse/brake. (Might be the other way around, try it out.)

Calibration and programming work the same way as you would use it on you tx. Usual calibration sequence involves making the PWM value high, powering the ESC, waiting for a beep, taking the PWM value low.

If the ESC uses a programming card/adapter, you need to hook an oscilloscope to see what it does.

You can also see what the PWM should look like at: http://en.wikipedia.org/wiki/Servo_control You could propably find some existing servo control library. If you start making your own, you might benefit from having access to an oscilloscope that allows you to measure the period and pulse width.

I can't help with the actual software side as I've never used PWM on a pi, just on various microcontrollers.


The Pi's native PWM output is perfect, hardware driven and wont be interrupted by software. Many people use software based PWM on the Pi and it's not very good. If you only need 2 axis F/B L/R, then the Pi B, B+ and 2 B all have two hardware PWM outputs.

As far as ESC's go, I just purchased one and had no documentation either. I found that I had to set the duty cycle to 50hz (20ms) then go through an init process with the ESC, with the ESC off, start the PWM at 2ms , power the unit on, you should hear beeps, set PWM to 1ms... then wait a second, then go to 1.5ms, you'll hear 3 beeps or more indicating it calibrated around 1.5ms as the 0 speed center.

  • 1
    There are quite a few modules which use DMA timed PWM to generate servo and PWM pulses independently on any of the gpios on the expansion header. That is good enough for servos and more flexible than solutions based on external hardware such as the PCA9865.
    – joan
    Commented Apr 10, 2015 at 21:16
  • I have a Raspberry Pi 2 - you say it has two hardware PWM outputs? Are there some official docs for these? Can these be found on the GPIO header - what pins are these?
    – Kozuch
    Commented Feb 26, 2016 at 22:15

I also wasn't able to find specifications for that ESC, but as a start, I would suggest hooking a oscilloscope (or less-ideally a voltmeter) between the ground and control lines on the micro receiver unit where they connect to the ESC while you go through the calibration sequence described here. This will allow you to see what sort of signals are going into the ESC for various functions on the control stick. Eventually you will want to connect the RPI's GPIO port to the control line and connect the ground lines on the ESC and RPI, but I wouldn't try it until you know how much current the ESC draws in operation and what voltages it needs, etc. You might need some additional circuitry between the RPI and the ESC, for example if it needs a 5V control signal.

  • I think I'm going to need an oscilloscope. Thanks so much for the answer. I also found that the Raspi is not exactly the right platform to control an ESC and a servo so I got myself an Adafruit 16-channel PWM & Servo controller. I'm trying to make that work now...
    – Fabien
    Commented Jan 31, 2014 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.