Raspberry Pi and Wiimote

It’s been a while between posts again but I have made some time for my projects recently.  I have been playing around with hand switches and adding some functionality to my python software. Menu bars have been added with options for enabling different functions such as continuous mode (servos move as soon as the slider is moved) and head tracking mode.

I was working away on improving my code when I saw this cheeky little post on the Raspberry Pi website.  http://www.raspberrypi.org/archives/3298.  I was inspired and my Raspberry Pi has been waiting patiently for me to do something with it for a while now and I thought this may be a good opportunity to have a play. The plan was to use a Wiimote to control my robot, using the Raspberry Pi as the middle man. It happened that I had a couple of Wiimotes knocking about so it seemed too good a project to pass up. I acquired a Bluetooth adapter and promptly threw it in the bin because it caused me no end of trouble on the Pi and on my other computers both running Ubuntu. I purchased a different Bluetooth adapter (cheaper than the first I may add) and everything worked wonderfully. I installed blueman as I have found it works well on my Ubuntu machines. To test the connection with the Wiimote I installed wmgui (sudo apt-get install wmgui). This is a little program that connects to the Wiimote and shows button presses and accelerometer data coming from the Wiimote on the screen. So far so good, Bluetooth working and  Wiimote connected.

The next job was to work out how to get the data from the Wiimote into a Python program so I could use it to control my robot. Luckily, it would appear someone has done all of the hard work in the form of CWiiD. I installed CWiiD onto the Pi (sudo apt-get install python-cwiid).  I found the following page more than helpful in getting started started with using CWiiD in my Python program http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/wiimote/

I think Python is great. Everything works really well and all of the code I had written for my desktop to control the robot could be used with the Raspberry Pi with very little modification. All I had to do was comment out the OpenCV stuff for now, as the SD card I’m using has a clean install of wheezy on it and I haven’t got round to building OpenCV again. I added some code to connect the Wiimote to the Pi.  The three-axis accelerometer in the Wiimote gives values of acceleration in the x, y and z directions. Using two of these values, it’s possible to detect if the Wiimote is being tilted front to back or rolled left to right easily. Rotation in the third plane is more complicated so I decided that only two servos should be controlled at a time. To move each pair of servos, a button must be held down before the accelerometer data is used to move the servos. Button B for the head and the direction buttons to switch between pairs of servos on the arms. For an added touch I used the home button on the Wiimote to send all of the robots servos to their home position.

This project was perfect for the Raspberry Pi and there is a lot of documentation out there to help. What I would like to do next is incorporate the storing of robot positions using the Wiimote to allow sequences to be programmed and replayed.

I’ve put together a video showing the Wiimote control in action. Enjoy!


Facts and Thoughts on Technological Progress

Turing's Radiator

Pleasantly Warm Topics in Computational Philosophy

Mind the Leap

One small step for the brain. One giant leap for the mind.

Steve Grand's Blog

Artificial Life in real life


Hi, I'm Jim. Read what I write and I'll write more to read.