I started with a three-axis accelerometer board ("WiTilt") with a Bluetooth interface from Sparkfun, along with a small lithium polymer (LiPo) battery about the same size as the board. Both are a bit smaller than a standard business card:
My goal was to connect it up to PureData (pd) to interactively generate audio in real-time based on the accelerations. I previously have captured data using HyperTerm and played it back later at the Dorkbot DC meeting using the pd file reading object.
The WiTilt talks over Bluetooth as a serial port. I first tried to use the "comport" object in pd, but that was quite flakey (on Windows anyway). Then I tried to use Python with pyext to create a pd "external" in Python. Pyext works OK for pd objects that get messages then send messages, but the threading model for an external that would continuously send data into pd did not work so well.
Instead I used the pd "netreceive" object which uses IP sockets to receive pd messages. A Python helper program runs to intercept the Bluetooth serial port data, I do some string manipulation on it (raw data from WiTilt looks like "X=223 Y=474 Z=678"), and then send it to pd using TCP to a localhost port. This required Python for Windows Extensions as well as pySerial (nothing is ever easy, is it?). So I ended up with the Python program below, note that the message I send to pd needs a semicolon on the end:
from socket import *
s.send(x+' '+y+' '+z+';')
The upside of using netreceive is that the computer running the Bluetooth serial port and the computer running pd could be separate computers, possibly on different continents...
So then came the pd patch, which simply took the three axis data and shot it into three separate oscillators for now:
And here's the video of the system in action. You can see that the board is sensitive to the acceleration of gravity as I tilt it as well as to the acceleration due to physically mov