As the first stage of Project Mario, I will implement bluetooth control of a Polulo Zumo using a controller from a USB joystick attached to a Raspberry Pi.

The USB dongle I’m using is called a Bluetooth CSR 4.0 Dongle, which is a very cheap BT 4.0 compatible dongle. I actually forgot to check ahead of time it was compatible with the Pi, but luckily enough it is. The BT receiver on the Zumo used is a HC-05 (kindly lent by Brendan Calvert). Finally, the joystick is a cheap Playstation 2 imitation USB controller, bought on the cheap from eBay.

The first step I took was to ensure I could read the joystick on the Pi. I decided to read the joystick using the pygame joystick module. I found a simple piece of test code here, which ran successfully on the Pi except that I ran it from command line and therefore couldn’t hit the close button to quit (ctrl-c didn’t work either).

The next step was to send some test serial messages over bluetooth. As my test receiver I used an Arduino connected to my laptop, with the HC-05 tx and rx connected to pins 8 and 9. I simply used the AltSoftwareSerial example, which relayed any received messages from one serial connection to another so I could monitor any received massages. Setup and testing of the bluetooth module was done using the process outlined here.

I already had code that would control a Zumo over bluetooth using a computer keyboard, implemented using the lightblue bluetooth module for Mac and Tkinter to get keyboard input. Now was just a simple case of modifying the output to use the serial module and pygame joystick input as in the above examples. I also found this code, a module for controlling a quad-rotor using similar joysticks, very useful.

Here is the result: