Archive for the ‘Wiimote work’ Category

How to Use a WiiMote in a Processing Sketch

Thursday, May 15th, 2008

There has been a lot of development to reverse engineer the Wiimote so you can use it in new and interesting ways (see Johnny Lee’s stuff, for example). However, most artists and designers probably aren’t really familiar with programming in C#. Luckily, you can use the Wiimote in Processing, so you can get up and running pretty quickly, and start creating interactive sketches. There are a lot of steps involved, so I thought a short summary would be useful. It is geared for people using an Intel Mac (MacBook or MacBookPro), because that’s what I have.

You need several pieces of software for this to work correctly, ideally the latest versions. Download these to your desktop or a working folder, and unzip the archives:

  1. Processing. Ideally, this should already be installed and running on your system. See the Processing website for details.
  2. WiiRemoteJ. This is a Java library written by Michael Diamond (aka Cha0s), that listens to the Bluetooth port on your Mac and can format the Wiimote information for Java, which is what Processing is written in. Click on the downloads link, and then select a file called something like: “WiiRemoteJ v1.3.zip.gz”.
  3. Bluecove. This is a bit of software that implements something called the JSR082 API. It provides a way for Java programs to access the Bluetooth hardware on your system. You want the file called something like: “bluecove-2.0.2.jar”.
  4. Wrj4p5. This a library that converts the WiiRemoteJ information to somthing easy to work with in Processing. Follow this link and click on the wr4jp5 package, then select the zip file that is the latest release, like something listed under: alpha_004).
  5. A demo Processing sketch to see if it all works (originally written by Classiclll).

Once you’ve downloaded all of that stuff and have unzipped it, do the following steps:

  1. First, you need to set up WiiRemoteJ and bluecove to work with Java on your computer. So, open up the following directory on your computer: YourHardDrive/System/Library/Java/Extensions
  2. Copy the following files into this directory:
    • WiiRemoteJ.jar (from the WiiRemoteJ files you unzipped above)
    • bluecove-2.0.2.jar (from the bluecove files you unzipped above)
  3. Now, in your main Processing folder (located in Applications/Processing/libraries), you need to create a folder called wrj4P5.
  4. In the new wrj4P5 folder, create a new folder called Library.
  5. Now copy the following files into Library:
    • WiiRemoteJ.jar (from the WiiRemoteJ files you unzipped above)
    • bluecove-2.0.2.jar (from the bluecove files you unzipped above)
    • wrj4P5.jar (from the wrj4P5 files you unzipped above)
  6. Finally, open a new sketch in Processing and cut and paste the demo code into it.
  7. When you run this new code, it should run without generating any error messages in red. If you get those, doublecheck the steps above. Hopefully, your sketch should look like this picture:
    Demo Wii Code
  8. Here’s where it gets tricky. Your system is now waiting to hear from the Wiimote. You should wait 4 or 5 seconds and simultanously press Buttons 1 and 2 on your Wiimote. This tells the Wiimote to look for something to connect to.
  9. If everything is going well, the bluecove software will detect this signal and you should receive a message like: Discover called # 0. The box will start to wiggle if you move the wiimote and the display area will show any keys you press.
  10. Always shut down gracefully by turning off the Wiimote (press power button) and then closing your sketch. You’ll get the message: “Remote disconnected… Please Wii again.
  11. Then close your sketch window and you will get a confirmation: “BlueCove stack shutdown completed”

Troubleshooting:

Pairing the Wiimote with Processing is pretty flaky. It’s often inconsistent and you may have to try several times to get it to work. Sometimes, it’s helpful to shut off the power to the Wii and restart your sketch. Always wait a few moments after your sketch starts so that the bluetooth communications can fire up and get ready to hear from the Wii. These problems will probably be ironed out as the various bits of software are improved. Time will tell. In the meantime, have fun trying it out and be sure to look at the Processing website discussion board for code samples.