Thursday, February 04, 2010

Using a Wiimote as a Sensor Driver on Windows 7

Code Project - Writing a Sensor Driver for the Wiimote on Windows 7

Introduction

I was as fascinated with the Nintendo Wii gaming console as the rest of the world was when it came out and thought its unique input system was jaw-dropping awesome. I subsequently happened to stumble upon some incredibly creative work by Johnny Chung Lee on the internet one day where he demonstrates how the Wii remote - also known as the Wiimote - can be used to build innovative new ways of interacting with a computer. He got me so excited with the idea that I almost immediately went out and got a Wiimote myself though I don't even own the Wii console!

When Windows 7 came out and I learnt about the new Sensor and Location Platform, I figured writing up a little bridge driver that exposed the 3-axis accelerometer that each Wiimote comes with to the sensor platform would be kind of cool. This article attempts to explain how the driver works and what it takes, in general, to write a driver for the Sensor platform.

Acknowledgements

The implementation of the Wiimote sensor driver, particularly the communication protocol implementation, has been heavily "inspired" by Brian Peek's WiimoteLib library which has turned into a sort of de-facto standard API for gaining access to the Wiimote from managed code via the Windows HID API. Also, the sample driver implementations from the Windows Driver Kit provided the starting point to get the project off the ground. The I/O management code was taken with some slight modifications from the Sensor Development Kit.

Just show me how to use this thing

If you're looking to just use the driver and don't really care how it works, then here's what you've got to do. The Wiimote is a surprisingly self-contained piece of hardware that really is a stand-alone product by itself. It communicates with the Wii console via standard Bluetooth radio signals and identifies itself as a HID input device. To make it work with your computer, here's what you'll need:

  • A Wiimote (duh!)
  • A computer with Windows 7
  • A Bluetooth card

There have been some reports out there where people had trouble getting their Bluetooth driver stack to recognize the Wiimote. If you're one of them you'll probably need to get updated drivers for your Bluetooth card. Assuming your computer is able to pair with the Wiimote, here's how you do it in Windows 7.

Taking her out for a ride!

If you are with me so far, then you should be able to launch the "Wiidiag" tool from "C:\Wiisensor\bin\Wiidiag\Wiidiag.exe" and watch a dull little graph respond to you whenever you wave your Wiimote around! Now, what's cool is that you can pretty much get any app off the shelf and have it work with your Wiimote's accelerometer if it is designed to work with the Sensor platform. You could for instance, download the plane demo app from here and it should just work! In fact I have included the binary for that demo with the download for this article and you should find it in "C:\Wiisensor\tools\PlaneDemo\DemoApp.exe". When you launch it you should see a little plane model rendered on the screen. Just check the 3 check boxes representing the 3 axes and it should immediately start rotating the plane around as you move the Wiimote.

image

…”

Awesome! Need to hurry up and post this so I can go grab a Wiimote and try this out… :)

1 comment:

Jeff Hadfield said...

Thanks for the codeproject.com shout-out, Greg. This was a cool article! I saw it today, too.

jeff