# LSM9DS1 Threshold to g mapping

Hi,

I am using LSM9DS1 accelrometer and want to know what is the relation between threshold value and g. I am using scale as ±2 G
So what will be the value for threshold to set it for more than .5 g

Here is my understanding, pls confirm if this is correct?
As we have 0-255 values for threshold, which is absolute of +/- 2 g i.e 2 divided in to 256 values. Hence factor becomes .007843

Now threshold of 20 would mean 20*.007843 = 0.156862745 g

Is that correct ?

Thanks
Sambhav

Without really thinking into it, there is a bit in your reasoning that does appear to be off

When you are dealing with +/- 2g your total range would be 4g

1 Like

Hi ScruffR,

I read on community that threshold for accelerometer is taken on absolute value. so if threshold is 20 that would mean +/- g force of same value will account for that thresold. May be I am not correct.

I am with @ScruffR; your total range for this accelerometer is from -2g to +2g, mapping to 0…255. I.e., when at rest (0 g), I would expect this sensor to give me a value of 127 or 128. Now if you’re not interested in the direction of acceleration you could certainly stick it into the abs() function and get only positive numbers out, but the output of abs() would range 0…127.

Poking through the LSM91DS1 for a minute, I see it says it uses 16bit resolution so the real output ranges from 0 to 65535 and zero sitting at 32767

Yeah Joost, I also got confused by that because, in LSM9DS1 library, threshold is defined as unsigned 8 bit int, which can only accept values from 0-255

Are you referring to this library: https://github.com/sparkfun/SparkFun_LSM9DS1_Particle_Library ?

This lib confirms the accelerometers are indeed stored as 16 bit signed values. To read the accel values, you first call readAccel() on the object you instantiated before, then the member variables (ax, ay, az) are updated. Are you prehaps confused by the return value from readAccel() which is defined as:

`uint8_t LSM9DS1::readAccel()`

The uint8_t is not the accelerometer value but a status code. It seems if the status code is non-zero the values are good. There is also another method you may use:

`int16_t LSM9DS1::readAccel(lsm9ds1_axis axis)`

That returns the axis of interest directly as the return value.

Notice that according to the library code (which I spend very little time with) you will need to calibrate your readings with the calibrate() method. It does not say which mechanical input you need to provide during calibration, or if instead you need to keep it still. The calibration routine seems to average a bunch of samples but it does not let you control how many or the time interval in between - so you may still have a very flakey calibration depending on the specific mechanical setup. May not be a problem to you, afterall these MEMS accels are not very sensitive.

Hi Joost,

I am using interrupt from accelerometer and defining the threshold for that as per below
https://github.com/sparkfun/LSM9DS1_Breakout/blob/master/Libraries/Arduino/examples/LSM9DS1_Interrupts/LSM9DS1_Interrupts.ino (it is for Adruino, but functions are same for particle)

// Set accelerometer scale to +/-2g
imu.settings.accel.scale = 2;

// 4. Configure accelerometer threshold:
// - 20: Threshold (raw value from accel)
// Multiply this value by 128 to get threshold value.
// (20 = 2600 raw accel value)
// - X_AXIS: Write to X-axis threshold
// - 10: duration (based on ODR)
// - false: wait (wait [duration] before interrupt goes low)
imu.configAccelThs(20, X_AXIS, 1, false);

Now the first parameter is threshold value which is 8 bit integer accepting values from 0-255 and 20 would nean something near to .15 g if we set scale to 2. Whats your thought ?