Problem with accelerometer value read via C API

Hi Filip,

  1. When stationary detection is disabled the Accelerometer is unconfigured after the reset. The sensor is inactive and you will need to configure it. The “av” command configures it so that explains your observation.

Please refer to the sensor documentation for more details:

This is an example:

write_reg8(LIS2DX_CTRL_REG1, 0);
write_reg8(LIS2DX_CTRL_REG5, LIS2DX_BOOT);
write_reg8(LIS2DX_CTRL_REG1, LIS2DX_ODR_50 | LIS2DX_ZEN | LIS2DX_YEN | LIS2DX_XEN);
write_reg8(LIS2DX_CTRL_REG2, 0);
write_reg8(LIS2DX_CTRL_REG3, LIS2DX_I1_ZYXDA);
write_reg8(LIS2DX_CTRL_REG4, LIS2DX_HR | LIS2DX_FS_2G);
write_reg8(LIS2DX_CTRL_REG6, 0);

  1. The raw values are 16-bit so you should read 2 bytes for each axis, e.g.

x = read_reg16(LIS2DX_OUT_X_L);
y = read_reg16(LIS2DX_OUT_Y_L);
z = read_reg16(LIS2DX_OUT_Z_L);

Cheers,
TDK

2 Likes