Yep, This seems to work....
// initialise accelerometer
void AccelSetup(void)
{
Wire.beginTransmission(0x1D);
Wire.send(0x20); // CTRL_REG1 20h
// 11: device on, 01: decimate by 128, 0: normal mode, 111: all axis enabled
Wire.send(0x87); // device on, 40Hz, normal mode, all axis' enabled
Wire.endTransmission();
}
// get the accelerometer values
void GetAccelValues(void)
{
byte bytearray[6]; // low, high;
int cnt;
// trnsmit to device with address 0x1D or 0011101b
// send the sub address for the register we want to read
// this is for the OUTX_L register
// masking the register address with 0x80 enables auto
// increment for subsequent reads
Wire.beginTransmission(0x1D);
Wire.send(0x28|0x80);
Wire.endTransmission();
// now do a transfer reading all six bytes
Wire.requestFrom(0x1D,6);
cnt=0;
while(cnt<6)
{
if(Wire.available())
{
bytearray[cnt]=Wire.receive();
cnt++;
}
}
XAccel=bytearray[1];
XAccel<<=8;
XAccel+=bytearray[0];
YAccel=bytearray[3];
YAccel<<=8;
YAccel+=bytearray[2];
ZAccel=bytearray[5];
ZAccel<<=8;
ZAccel+=bytearray[4];
// z axis acceleration, all set.
// Perfectly still and with the z-axis parallel to the ground, it should be about 1024-ish
// (I find in practice it is around 1019.)
// When the z-axis is orthogonal to the ground, it should be zero.
// 1024 is +1g acceleration, or normal gravity
// 2048 is +2g
// 0 is 0g
}