Wiimote And BlinkM Are love

February 1st, 2008

Long time no blog. Sorry. Tonight I’m going to write about something a little different than normal. There will be no Ruby in this post! Consider yourself warned.

It should be obvious from my recent posts that I dabble in the dark arts of hardware hacking. I recently found out about (and promptly ordered) a new little toy called a BlinkM. BlinkMs are basically smart LEDs… they’re an RGB LED with a small microcontroller that you can interact with over the I2C protocol.

Tod E. Kurt, one of the guys behind the BlinkM, posted some example code which included details on how to use the guts of a Nintendo Wii Nunchuck controller to fiddle with the BlinkM. I decided to take that one step further (or one step back, depending on your point of view) and hack together a similar control without requiring you to take your nunchuck apart.

My setup requires a lot of pieces. First, the Wii remote itself with a connected nunchuck. Next, the DarwiinOSC branch/fork of DarwiinRemote. OSC, for what it’s worth, is Open Sound Control is a networked sound control protocol, sort of like MIDI over the network. It allows devices to send all sorts of information in easy to digest packets.

I’m reading the OSC messages with Processing, the environment on which Arduino based their GUI. In turn, Processing is doing some math on the sensor readings and feeding them to an Arduino via a serial connection. That Arduino is controlling the BlinkM. Complicated? Eh, not as bad as it sounds!

The best way to understand what’s going on is to see it in action. Here’s a short video I created demonstrating the hack:


Some Technical Details

  • I had a hell of a time figuring out the magic dance to get the BlinkM initialized and ready for commands. I ended up doing a gross hack which you’ll see in the code below, wherein I set the fade speed inside the update loop. Gross? Gross. For some reason, every time the BlinkM starts up, the fade speed resets to 0.
  • I’m using the oscP5 library for Processing to read the OSC messages. OSC is a damn cool protocol! I wonder if there is Ruby code to read/write it…
  • The translation of the (x,y) coordinates of the nunchuck’s joystick to displayable colors took some thinkin’. I absolutely suck at math so anything that I did right is purely by chance, heh. I ended up converting the rectangular coordinates to polar coordinates. This is convenient because the polar coordinates look like (r,θ), where r is the distance from the origin and θ is the angle from the origin axis. This maps pretty cleanly onto brightness and hue, respectively, and to make things even easier, the BlinkM can take an HSB-formatted color. I just set the saturation to full-bore and ran with it.
  • The BlinkM examples from Tod that I previously mentioned include a sketch called BlinkMCommunicator, which sets up a simple serial <-> I2C translator in the Arduino. I used this to communicate between Processing and the BlinkM.

The Code

The code is available over here. Unfortunately my syntax highlighter doesn’t like Java, so you’ll have to cope with it being monochrome :)

3 Responses to “Wiimote And BlinkM Are love”

  1. Thomas Says:

    Oh, very nice! I think I’m going to have to put in an order for a wiimote now… too many cool projects floating around that use it.

  2. David Frey Says:

    I hear the Imperial Death March pulsing from a distance. I may yet be lured into the dark world of hardware hacking.

    Nice video btw.

  3. Vincent Says:

    For OSC, it seems that someone in Japan has been taking care of it: http://www.funaba.org/en/ruby.html#osc

Sorry, comments are closed for this article.