Making a Wii remote talk to Pure Data (PD)
Making a Wii remote talk to PD could be fun. You have a pretty-accurate/not-over-sensitive accelerometer inside a Wii remote. Also, there are a bunch of LEDs and a pager motor (vibrator) inside the Wii that can be used for a lot of fancy purposes. In this guide, we assume that you are running Ubuntu on the Beagleboard. You need a bluetooth dongle to let the Beagleboard and the Wii remote pair with each other. To finish this task, we need to install a bunch of Ubuntu packages and PD patches.
Making sure the devices are in place
1) Plug in the dongle into the Beagleboard. Ubuntu should detect the dongle automatically and supply it with the necessary drivers. Check the status of the dongle with the command lsusb. If lsusb is not installed, you should run the command sudo apt-get install lsusb. Once the package is installed, run the command lsusb just to make sure the dongle plugged into the computer.
2) Install the bluez package: We do the same as we did in step 1 to install packages.
3) bluez installs a program called hcitool, which is basically a bluetooth device scanner. Once you run this program, you should get an output like this:
00:22:41:CB:1C:D3 cmn53 00:22:41:FF:4C:53 Jimmy Sago's MacBook Pro 8C:56:C5:53:9C:B2 Nintendo RVL-CNT-01 5C:59:48:CE:97:2C Creand River's MacBook Pro
The line that contains "Nintendo" is the Wii Remote. Note the mac address in that line. We need it and it's important!
4) Now install the package called wminput. This package helps us connect the Wiimote to the Beagleboard. Note that in order to put the Wiimote in a discoverable mode, you should press the buttons 1 and 2 together and the LEDs on the Wiimote continue to blink for around 15-20 seconds. The Wiimote continues to be in the discoverable mode as long as the LEDs blink.
5) Run the wminput program to pair up the devices. You might have to run this program in sudo mode (the command is sudo wminput) since you are pairing up the system with another device, so you need some administrative rights. Once the command is executed, you should get an output like this:
Put Wiimote in discoverable mode now (press 1+2)... Ready.
6) Once the Wiimote is connected, the device acts like a mouse by default. Since we are on a display-less Beagleboard, we cannot see that. Run the command dmesg to make sure its connected. The command produces a multi-page output and in (may be) the last line of that output, you should see something close to this:
[ 2854.231475] input: Nintendo Wiimote as /devices/virtual/input/input2
7) Run the command sudo hcidump to let the program sniff the packets coming in from the Wiimote through the dongle . You will actually not see what data is being transmitted, but will be able to see the metadata of the packets that are being transmitted. Something like this:
> ACL data: handle 42 flags 0x02 dlen 11 L2CAP(d): cid 0x0041 len 7 [psm 0] > ACL data: handle 42 flags 0x02 dlen 11 L2CAP(d): cid 0x0041 len 7 [psm 0] > ACL data: handle 42 flags 0x02 dlen 11 L2CAP(d): cid 0x0041 len 7 [psm 0] ...... ...... ...... ......
This finishes our preliminary setup.
Time for some patience
8) Download this http://mikewoz.com/downloads/wiimote_0.6.00.tar.gz. On a second note, check his site http://mikewoz.com - he did some pretty cool stuff. Untar the archive into a folder. Get inside the new folder (It's called Wiimote). I really wish It was a simple 'make' from here, but things aren't that easy. Rev up with some coffee and get ready to install some huge packages.
9) It helps a ton to go through the README file here. As you would read in the directions to install the Wiimote PD package, first run the ./configure command. From now it's an iterative process to run the ./configure command and install the missing packages until the configure command is satisfied. Here's a small example:
ccrma@satellite:~/Wiimote/src/cwiid-0.6.00$ ./configure checking for gcc... gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking for gawk... no checking for mawk... mawk checking for flex... no checking for lex... no configure: error: flex not found
Now that flex is not found, I have to install flex using the command sudo apt-get install flex. For my Beagleboard, I had to install the following packages as well, until I got no more errors from :
flex bison (run the sudo apt-get update command after this) bluetooth libbluetooth-dev libbluetooth3 libcwiid1 cwiid-dbg
10) Change makefile and wiimote.c to reflect correct paths (Ed to help here)
11) Run the make command now and you should be able to compile everything without any errors. Copy the wiimote.pd_linux file into the externals folder and the 'wiimote' object should be workable in PD without any problems.
The final touch
12) Open the wiimote_help.pd object that comes with the package. In that patch, there's a connect object through which we can connect to the Wiimote. Replace the address here to the one you noted down (from the point 3 of this guide)
13) One observation from my experience: Keep the Wiimote in discoverable mode and then click on the 'connect' object in the patch. Otherwise PD would just crash or not just connect.
(Written by Ravi Kondapalli on 17th November 2010)