LSM9DS1: how to change sampling frequency and acceleration ranges

I wrote a (rather large) update on the LSM9DS1 library.

To change and read the sample rate (ODR= output data rate)

int setAccelODR(uint8_t range); // Sample Rate 0:off, 1:10Hz, 2:50Hz, 3:119Hz, 4:238Hz, 5:476Hz, 6:952Hz Automatic BW setting
int setGyroODR(uint8_t range); //Sampling Rate 0:off, 1:10Hz, 2:50Hz, 3:119Hz, 4:238Hz, 5:476Hz, 6:952Hz
int setMagnetODR(uint8_t range); // Sampling rate (0..7) corresponds to {0.625,1.25,2.5,5.0,10.0,20.0,40.0,80.0}Hz

float getAccelODR(); // Measured Sample Rate of the sensor.
float getGyroODR(); // Measured Sample rate of the sensor.
float getMagnetODR(); // Sampling rate of the sensor in Hz.

Accel and Gyro share their ODR, so changing one also changes the other.
setGyroODR(0); switches off the Gyro. The Accel stays on, but it's ODR value may change significantly.
setAccelODR(0); switches off both saving power.
There's no Gyro only mode.

Since the ODR is (or should be) in the orientation tracking calculation of the gyroscope, its absolute value is important.
The get... procedures of accel and gyro return a value that was measured during the set.... procedure.
It's a bit disappointing that the 952Hz setting does not work.

3 Likes