A few days ago, I looked under the couch and found my dusty, disused Wii Balance Board. I bought it years ago, when I was a bit chubbier and thought Wii Fit might help me lose some weight and become fitter. It worked very very well, although I think it was mostly because I didn’t want to eat junk any more, as that would mean that the mind-numbingly boring hour of exercise I just did would be for naught.
For those of you who don’t know what a Wii Balance Board is, it’s the bastard offspring of a bathroom scale and a step pad. It connects to the Wii via Bluetooth, and it can weigh you and also tell which way you are leaning.
Seeing the board, I thought it would be fun to connect it to the computer and try to read the weight values from a script. I started by trying to pair it with the computer, and, after searching online for a bit, I eventually discovered that, for permanent pairing, one must needs use the PIN “000000”. Using that, the board was permanently paired with my computer, and I would no longer need to turn it over, remove the battery cover, press the red “sync” button, replace the cover, flip it over, and then (finally) use it, every single time.
Searching around, I found various packages that allow you to use the Wiiboard with Python without having to mess with the protocol, such as cwiid (which Matt Cutts used in his hackery of his board), but in the end I went with wiiboard-simple, because it’s one simple and straightforward Python class.
wiiboard-simple, I could read the weight values from the board, but it is a bit heavy. It requires threading and
pygame for events for something which is pretty much one simple loop, so I gutted it and removed all those depencencies in favor of a processor class that gets called whenever an event is generated. That’s a much cleaner design, in my opinion, although it’s still pretty hacky.
I called my script
Gr8W8Upd8M8, and you can find it on GitHub here:
It’s pretty much the same as
wiiboard-simple, but has two crucial differences:
- It doesn’t require threading or
pygame, so it’s much lighter.
- It uses
bluez-toolsto disconnect the board after a measurement, which doesn’t otherwise happen on my system (the board would just stay on for ever).
Unfortunately, I ran into two problems: First, and least importantly, the problem I mentioned above: The board wouldn’t disconnect after the Bluetooth connection was closed (this is Ubuntu, your mileage may vary), and would just stay on for ever. I couldn’t find a way to do this from Python, so I just shelled out to
bt-device to disconnect the device, which worked beautifully.
The second problem was that automatic pairing doesn’t really work. It does connect to my laptop automatically, but I have to disconnect it from the Ubuntu Bluetooth device manager, which is a major inconvenience, as it means that I can’t just step on the scale and take a measurement.
I will solve this later. I have solved this, see edit at the bottom of the page.
In the end, after pairing and using the script, I had something that will (almost) automatically connect to the board as soon as it’s turned on, wait for me to step on it, read the weight (I use a histogram and just read the most frequent value reported by the scale for this, as it reports a few values per second), and shut off when I get off the scale.
However, at that point, I needed to actually do something with the data. I figured that a good thing to do with it would be to log it somewhere and maybe graph it, but where? I could write a small Python script to output a graph, but where’s the fun in that? A few minutes later, I had written a simple way to send the data to this very site you are reading, and plot it using Google Charts (which is pretty nifty).
So, here it is: A live feed of my weight that automatically updates whenever I step onto my Wii Balance board. I didn’t care enough to make it private, because I figure that, for one, nobody will be interested in it, and two, it probably can’t be used against me, unless someone wants to tackle me.
So, that’s what this weekend was about. If you have any cool Balance Board hacks or ideas, please let me know, as I am very interested. Stay tuned for next week’s post, where I get a Leap Motion (it’s in the mail). Hopefully it won’t suck and I’ll be able to make something cool with it!
HUGER EDIT BEFORE THE HUGE EDIT BELOW: The steps below are obsolete, just run the
xwiibind.sh script that’s in
the repo, and the board will pair automatically.
HUGE EDIT: I have finally managed to get the Wii Board to successfully (and permanently) pair with my Ubuntu computer. Here are the steps:
sudo apt-get install build-essential libdbus-1-dev check checkinstallto install the dependencies.
apt-get source bluezto get the source.
- Apply this patch to actually get it to recognize hex pin codes.
sudo checkinstallto create a .deb you can remove after pairing.
- Restart your computer/bluetooth services/etc.
./test/simple-agent hciX ##:##:##:##:##:##, you need to change
hciXto whatever your Bluetooth adapter is (usually
hci0, find it with
hcitool dev). The hashes are the Balance Board’s Bluetooth address.
- Your pin is now
AA:BB:CC:DD:EE:FFis your Bluetooth adapter’s bluetooth address. Just reverse the order of the octets, so
- Your balance board will pair, and you have to immediately connect to it with
python gr8w8upd8m8.py ##:##:##:##:##:##, or it might not pair.
- If you missed the connecting step above, run
./test/simple-agent hciX ##:##:##:##:##:## removeand try again.
- To trust the device so it will connect in the future, run
bt-device --set ##:##:##:##:##:## Trusted 1
Hopefully that will work for you, let me know in the comments!