A brief post wherein I talk about connecting the Gemma to the accelerometer.
Neck bone connected to the…
Okay. So as you can see from my little sketch above, the Gemma’s GND, D1, and Vout will be connected to the NeoPixel while GND, D2, D0, and 3Vo will be connected to the accelerometer.
Accepting the accelerometer
The Flora Accelerometer contains two sensors inside: a fancy magnetometer that senses the direction of the strongest magnetic force (usually magnetic north) and also a 3-axis accelerometer that reads how fast it is accelerating in 3D space. For my purposes, I’m only concerned about the latter.
50 Shades of Gemma
The accelerometer has a digital I²C interface. This means that it uses two lines, known as Serial Data (SDL) and Serial Clock (SCL). The clock line is used to synchronize the data between the “master” and “slave.” I think it's because "talking" over this data line is like talking to someone over Google Hangouts: only one person can speak at at time or else the echo-blocker or whatever will mute you and the call descends into chaos. Same here. Only one device can send data at a time. The master device drives the clock line, telling the slave when it should pipe up and the slave device responds. In this case, the Gemma is the master and the accelerometer is the slave. Whipchya!
Reading into things...
My Assistant and I read through the spec sheet for the accelerometer chip in order to find the right addresses for the program to look for the data from the accelerometer and in the code it ended up looking like this:
#define ACCEL_ADDR (0x32 >> 1)
#define OUT_X_L_A 0x28
#define OUT_X_H_A 0x29
#define OUT_Y_L_A 0x2a
#define OUT_Y_H_A 0x2b
#define OUT_Z_L_A 0x2c
#define OUT_Z_H_A 0x2d
#define CTRL_REG1_A 0x20
But I'll write more about all that on Saturday when I talk about my attempts at serial debugging. Till then, Whipchya!