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
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:
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.
The threshold value is used to determine the value the accel needs to read before triggering an interrupt. When that interrupt happens you are expected to read out the actual register to get a more accurate value (i guess). So yes threshold value of 20 corresponds with 0.15g