Showing results for 
Search instead for 
Did you mean: 

H3LIS331DL: Getting terrible readings

Associate III

I'm experimenting with this accelerometer and I'm having some very disputable results while the device is sitting still.

I'm using ST's library code, but I will detail what I am doing here:

h3lis331dl_full_scale_set(&dev_ctx, H3LIS331DL_100g);
h3lis331dl_data_rate_set(&dev_ctx, H3LIS331DL_ODR_1kHz);
h3lis331dl_axis_x_data_set(&dev_ctx, 1);
h3lis331dl_axis_y_data_set(&dev_ctx, 1);
h3lis331dl_axis_z_data_set(&dev_ctx, 1);
	while (1) {
		/* Read output only if new value is available */
		h3lis331dl_reg_t reg;
		h3lis331dl_status_reg_get(&dev_ctx, &reg.status_reg);
		if (reg.status_reg.zyxda) {
			/* Read acceleration data */
			memset(data_raw_acceleration, 0x00, 3 * sizeof(int16_t));
			h3lis331dl_acceleration_raw_get(&dev_ctx, data_raw_acceleration);
			acceleration_mg[0] = h3lis331dl_from_fs100_to_mg(data_raw_acceleration[0]);
			acceleration_mg[1] = h3lis331dl_from_fs100_to_mg(data_raw_acceleration[1]);
			acceleration_mg[2] = h3lis331dl_from_fs100_to_mg(data_raw_acceleration[2]);
			serprintf("ax: %4.1f ay:%4.1f az:%4.1f  [mg]",
					acceleration_mg[0], acceleration_mg[1], acceleration_mg[2]);

My output is all over the place:

ax: 588.0 ay:-245.0 az:1274.0  [mg]
ax:  0.0 ay:-196.0 az:882.0  [mg]
ax: 931.0 ay:-441.0 az:1715.0  [mg]
ax: 882.0 ay:49.0 az:1372.0  [mg]
ax: 147.0 ay:-98.0 az:980.0  [mg]
ax: 686.0 ay:-245.0 az:980.0  [mg]
ax: 441.0 ay:-1078.0 az:1323.0  [mg]
ax: 98.0 ay:-294.0 az:931.0  [mg]
ax: 490.0 ay:-49.0 az:1176.0  [mg]
ax: 588.0 ay:-196.0 az:1372.0  [mg]
ax: 539.0 ay:-490.0 az:1323.0  [mg]
ax: 637.0 ay:98.0 az:1225.0  [mg]
ax: 49.0 ay:-196.0 az:1568.0  [mg]
ax: 637.0 ay:-196.0 az:1176.0  [mg]
ax: 294.0 ay:49.0 az:1421.0  [mg]
ax: 1029.0 ay:49.0 az:980.0  [mg]
ax: 931.0 ay: 0.0 az:1568.0  [mg]
ax: 490.0 ay:-49.0 az:1274.0  [mg]
ax: 882.0 ay:-98.0 az:1470.0  [mg]
ax: 147.0 ay:-196.0 az:980.0  [mg]
ax: 147.0 ay: 0.0 az:588.0  [mg]
ax: 882.0 ay:-343.0 az:1568.0  [mg]
ax: 490.0 ay:49.0 az:1127.0  [mg]
ax: 539.0 ay:-343.0 az:1421.0  [mg]
ax: 196.0 ay:-98.0 az:980.0  [mg]

1) Sitting flat and still I would expect closer values to 0,0,1000

2) All the values are bouncing around substantially.

Even if I bias out the readings they are still terrible (no code, but I bias for 1000 readings and subtract that from the readings to achieve close to 0,0,1000)

ax_bias: 438.2
ay_bias: -215.6
az_bias: -242.8
ax:  2.8 ay:-617.4 az:1467.8  [mg]
ax: 100.8 ay:117.6 az:1124.8  [mg]
ax: -291.2 ay:-470.4 az:1614.8  [mg]
ax: 100.8 ay:-176.4 az:2202.8  [mg]
ax: -95.2 ay:264.6 az:2055.8  [mg]
ax:  2.8 ay:-176.4 az:1467.8  [mg]
ax: -389.2 ay:117.6 az:1516.8  [mg]
ax: -438.2 ay:-78.4 az:1663.8  [mg]
ax: -536.2 ay:264.6 az:1222.8  [mg]
ax: -438.2 ay:264.6 az:1565.8  [mg]
ax: -144.2 ay:607.6 az:1565.8  [mg]
ax: -193.2 ay:-225.4 az:1222.8  [mg]
ax: -340.2 ay:313.6 az:1369.8  [mg]
ax: -144.2 ay:-29.4 az:1761.8  [mg]
ax:  2.8 ay:-323.4 az:1957.8  [mg]
ax: -242.2 ay:-617.4 az:1271.8  [mg]
ax:  2.8 ay:-127.4 az:1565.8  [mg]
ax: 149.8 ay:19.6 az:1320.8  [mg]


Hmmm, 100 g full scale so you are seeing ~0.5% accuracy...I agree it should probably be better but 0, 0, 1000 is probably not realistic. At 2 g FS with a standard ST sensor like an LSM6DSM I would expect up to ~10 millig jitter, so 500 millig at 50x the full scale range is not crazy wrong...


What is the low pass filter setting? Should probably be ~200 Hz at 1 kHz sample rate. Does this change anything?

Associate III

@KWine​ When you look at it that way (with respect to the jitter) it does make sense and seem to scale.

On this device the LP filter cannot be set. But it's set automatically based on the data rate.