7 years, 5 months ago.

change the g value of ADXL345

i use this code to measurement 3 axis https://developer.mbed.org/users/peterswanson87/code/ADXL345_I2C/

but i can't find where i can change the g value. it just says it's +-16g sensor where i can change to +-2g? Thanks very much

1 Answer

7 years, 5 months ago.

The range is set by the last two bits in the data format register (see Register 0x31—DATA_FORMAT (Read/Write) on page 26 of the datasheet here.

Since there are multiple settings in that register you can't just write to it without risking changing something else. You could look through the driver code and work out what the correct value should be but in this case being lazy is probably the best approach.

Read the current value of the register, change only the bits you care about and then write the modified value back. That way you're not going to have any unexpected impact.

unsigned char controlReg = accelerometer.getDataFormatControl(); // get control register
controlReg &= ~0x03; // clear the range bits
controlReg |= 0x00;     // set the range bits : 0 = 2g, 1 = 4g, 2 = 8g, 3 = 16g anything else very bad,
accelerometer.setDataFormatControl(controlReg); // write the new value to the device.

Accepted Answer

Thanks very much!!

posted by jajn HA 02 Nov 2016