I like to play around with the occasional new Microsoft technology, and since I recently traded my old Treo for an HTC Touch Pro, it seemed like it might be fun to check out the onboard accelerometers.
Fortunately, courageous bloggers have probed the secrets of HTCSensorSDK.dll, culminating in the .NET wrapper by Koush. This makes developing a mobile app that uses the device’s sensors a snap.
My first thought was to see what the data stream from the sensors looks like, so I wrote a primitive real-time graphing app by using the Windows Mobile 6 SDK. The WinMo SDK has nice integration with Visual Studio, so it’s painless to create a Smart Device project.
Koush’s sample code is great, and it was easy to adapt it to draw waveforms. Here’s the app in the designer:
The TiltData main form in the Visual Studio designer.
There are three panels, one for each component of the tilt vector. The tilt vector is the vector, in device space, that measures the alignment of the device relative to the gravity vector. When the device is held upright, the Y value is maximum (at around 9.8, units are m/sec/sec), and the X and Z values are zero.
To produce some interesting signal, I taped my phone to the spokes of a bicycle wheel. Here are the traces that result from a good spin:
TiltData running on my HTC Touch Pro.
The X-Y plane of the phone is parallel to the radial plane of the wheel, which is vertical. Most of the signal shows up as oscillations in the X-Y plane, but some Z-axis wobble is detectable.
Code is here. You’ll need Visual Studio 2008 SP1, Windows Mobile 6 SDK, and Koush’s Windows Mobile Unified Sensor API. Add Koush’s Sensors project to the TiltData Solution, compile, and deploy to your device. I don’t recommend swinging it around by the USB cable, by the way.