The CHB has an on-board Freescale MMA7455L 3-axis accelerometer, datasheet here, which can be accessed over the I²C bus. Not long after the Chumby Hackers Board was released Adafruit published a tutorial explaining how to access the accelerometer over i2c.
I’ve added some i2c tools to the OpenEmbedded image, so as well as compiling the tools in the Adafruit tutorial, you can use the packaged i2c tools (i2cdetect, i2cget, i2cset, i2c) to talk to the accelerometer.
i2cdetect tool will give you information about
the i2c bus device:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Enable the Accelerometer
The accelerometer is at bus address $1d (decimal 29). The Adafruit tutorial explains that i2c encodes 7-bit addresses in the high 7 bits, so we shift this up 1 bit giving an effective address of 58.
Register $16 (decimal 22) controls the mode of the accelerometer and at power-up it is in standby mode. The lower two bits set the mode as follows:
- 00 : standby mode
- 01 : measurement mode
- 10 : level detection mode
- 11 : pulse detection mode
The next two bits define the sensitivity:
- 00 : 8g range, 16 LSB/g
- 01 : 2g range, 64 LSB/g
- 10 : 4g range, 32 LSB/g
So put it into measurement mode, 2g range, we write 0000 0101 binary (5 decimal) to register $16 (decimal 22) at bus address 58.
The easiest way to read the accelerometer data is to use the mma7455.c example from the Adafruit tutorial. For convenience you can download the file from here.
Save that file as
mma7455.c, and Compile it as follows:
When you run the compiled binary, you should see something like this:
1 2 3 4 5 6 7 8 9
Now pick up the device and wave it at your office-mates. Watch the numbers change. Say woo-hoo.