Baby you can drive my car (with a bit of Python)

Tharshan Muthulingam

Bit About me

  • Final Year Computer Systems Engineering Student
  • Studying in Cardiff University


mbed micrcontroller
ps3 controller
breadboard, wires, optoisolators


  • A microcontroller developed by a team at ARM
  • Similar to the Arduino
  • Great for hobbyist projects and good for when you want to take it to the next step
  • Microcontrollers are for rapid prototyping


  • To prevent high voltages from affecting the system receiving the signal. 
  • In our case, the remote for the car is receiving the signal.

The big picture

ps3 controller usb packets

Using libusb we can read the usb packets in python

We need to find the right data values for a forward and backward motion, and also turning left and right.

  • Using joysticks
  • SixAxis motion

Python code

import usb
import serial
import pdb

ps3 = usb.core.find(find_all=True, idVendor=0x054C, idProduct=0x0268)[0]
ser = serial.Serial('/dev/tty.usbmodem1422', 115200, timeout=0.1)
if __name__ == "__main__":
    while True:
        data = ps3.ctrl_transfer(0xa1, 0x1, 0x0101, 0, 0x31)
        # 0-90 and 255-135
        # print "Triangle %03d Cross %03d Left JoyStick %03d" % (data[22], data[24], data[42])
        ser.write("%03d%03d%03d" % (data[22], data[24], data[6]))

Mapping Controls

Triangle Button for backwards, X button for forwards
Left Joystick for left and right

Though trial and error....

We find the index in the usb packet that map to those actions

Next finding Threshold Values...


Threshold for the button is easy
0 for not pressed and greater than 0 for pressed

We want to use the Left Joystick to turn

Wiring it up 


  • 4 PWM Outputs and 1 Serial Output
  • What is PWM?
  • Pulse width modulation (PWM) is a simple method 
of using a rectangular digital waveform to control an 
analog variable 
  • PWM duty cycle is changed based on ps3 controller values

Programming the mbed

  • Online IDE, Plug and play,  C++ SDK
        PwmOut forward(p26);
        if (x_btn > 50){
            back = (float(x_btn-128)/128);
        }else if (triangle_btn > 50){
            forward = (float(triangle_btn-128)/128);
        if (xaxis > 120 and xaxis < 135){
        }else if (xaxis > 130){
            left = (float(xaxis-128)/128);
            right = float(abs(1-float(xaxis)/128));


Thanks for listening

Twitter: @viperfx09



Baby you can drive my car (with a bit of Python)

By Tharshan Muthulingam

Baby you can drive my car (with a bit of Python)

  • 2,529
Loading comments...

More from Tharshan Muthulingam