User Tools

Site Tools



I've wanted to use my Wiimote to control my PC for some time now, and finally got around to trying it all out.

Getting the wiimote connected to my PC was easy - just install wmgui, a little GUI app which demonstrates connectivity (via

There's also a package called wminput which probably does what most people want - it turns a wiimote into an X11 input device (e.g. mouse) so you can point to move the mouse around. You have to sudo modprobe uinput first on Ubuntu 9.04, btw.

Doing it myself

I wanted to play with it myself, so I installed python-cwiid and messed about with a Python script until I got the hang of the API1):

#!/usr/bin/env python
# Wiimote experiments. Hopefully this'll grow into something I can use with
# wminput (or emulate it to the same affect)
import os
import sys
import time
import cwiid
wiimote = None
print "Press 1+2 on the Wiimote now..."
while not wiimote:
		wiimote = cwiid.Wiimote()
	except e:
		print e
		print "Ignoring previous exception"
wiimote.led = cwiid.LED1_ON | cwiid.LED2_ON | cwiid.LED3_ON | cwiid.LED4_ON
wiimote.rumble = True
wiimote.rumble = False
wiimote.led = cwiid.LED1_ON | cwiid.LED4_ON
print wiimote.state
wiimote.enable(cwiid.FLAG_MESG_IFC)	# "if changes"
wiimote.rpt_mode = cwiid.RPT_BTN
while True:
	messages = wiimote.get_mesg()
	for mtype, m in messages:
		if mtype == cwiid.MESG_BTN:
			for x in dir(cwiid):
				if not x.startswith("BTN_"): continue
				if eval("cwiid.%s" % x) != m: continue
				print x
			if m == cwiid.BTN_A | cwiid.BTN_B:
				print "A + B, exiting"
				wiimote.rpt_mode = 0
				exit	# Causes a segfault.. (why?)
		elif mtype == cwiid.MESG_ERROR:
			for x in dir(cwiid):
				if not x.startswith("ERROR_"): continue
				if eval("cwiid.%s" % x) != m: continue
				print x
			for x in dir(cwiid):
				if not x.startswith("MESG_"): continue
				if eval("cwiid.%s" % x) != mtype: continue
				print x

Next I need to workout how to inject things into X11, probably via /dev/misc/uinput. I think this snippet will be invaluable.

WiiMote was useful in working out the API
coding/wiimote.txt · Last modified: 2009/06/07 23:58 by robm