With regards to the Adafruit LSM9DS1 breakout: enter link description here

And using the Library: enter link description here

I am trying to increase the sample rate, or speed of this chip. I am using a Sparkfun Pro Micro 5V

With the adafruit library, you need to request accelerometer, gyro, magnetometer and temperature at once, and all I need is the accelerometer values. I am hoping by figuring out how to request only the accel values it will speed up the loop. But also, there must be another setting that could speed up the sample rate?

Any help would be appreciated!

my code currently:

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LSM9DS1.h>
#include <Adafruit_Sensor.h>  // not used in this demo but required!
Adafruit_LSM9DS1 lsm = Adafruit_LSM9DS1();
#define LSM9DS1_SCK A5
#define LSM9DS1_MISO 12
#define LSM9DS1_MOSI A4
#define LSM9DS1_XGCS 6
#define LSM9DS1_MCS 5

void setupSensor()
  // 1.) Set the accelerometer range

  // 2.) Set the magnetometer sensitivity

  // 3.) Setup the gyroscope

double accelX = 0;
double accelY = 0;
double accelZ = 0;
double rms = 0;

void setup() 
  // Try to initialize and warn if we couldn't detect the chip
  if (!lsm.begin())
    Serial.println("Oops ... unable to initialize the LSM9DS1. Check your 
    while (1);
  Serial.println("Found LSM9DS1 9DOF");
  delay(5000);//program stabilization

void loop() 
  sensors_event_t a, m, g, temp;
  lsm.getEvent(&a, &m, &g, &temp); 
  accelX = a.acceleration.x;
  accelY = a.acceleration.y;
  accelZ = a.acceleration.z;
  rms = (accelX*accelX)+(accelY*accelY)+(accelZ*accelZ);

2 Answers 2


Check the header of the library,

you will find readAccel readMag readGyro and readTemp in separate public functions and looking at the implementation of read it just calls those 4 in sequence. readAccel will update the accelData member field.

So you can just call lsm.readAccel() in the loop and then grab lsm.accelData directly and ignore the rest.

void loop() 
  accelX = lsm.accelData.x;
  accelY = lsm.accelData.y;
  accelZ = lsm.accelData.z;
  rms = (accelX*accelX)+(accelY*accelY)+(accelZ*accelZ);
  • Thanks! I'll try this out, hopefully it will speed up the sampling a bit
    – MattG
    Jul 9, 2019 at 19:52
  • This worked, the sample rate is significantly faster now that I implemented the code above from @ratchet freak
    – MattG
    Jul 10, 2019 at 13:04
  • @MattG having looked at the code in a bit more detail it looked like getEvent also did a read(). So your original code was doing a full read twice and only using the data for half the samples actually read. Jul 10, 2019 at 13:08
  • that makes sense, it is significantly faster now that I implemented your suggestions. Thanks again.
    – MattG
    Jul 11, 2019 at 15:34

Here is a link to the LSM9DS1 datasheet. In Chapter 3 it describes how to put the device in Accelerometer-only mode. At a quick scan of it, I believe there was timing information also, but at least knowing how to do it, you could then make your own timing measurements.

  • I see you can put the device into accel mode only, but unfortunately I don't understand how to actually implement the instructions. Is this something that would be changed in the library files?
    – MattG
    Jul 9, 2019 at 19:53
  • In the Adafruit library's Adafruit_LSM9DS1.h at line 243 are a handful of functions to read individual sensors (Sensor& getAccel ( void ) { return _accelSensor; }, for instance). To get the timing benefit, you may need to put the device in accel-only mode, which, yes, will need some study of the library .cpp file to figure out how to do it or where to add the capability. I also see that there are some data-rate selections available. But that's about all I know of this device. Any more will need looking at the library code and the datasheet.
    – JRobert
    Jul 10, 2019 at 12:11
  • ok, thanks for the input and help on this @jrobert !
    – MattG
    Jul 11, 2019 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.