H3LIS331DL Output data rate

As the datasheet of H3LIS331DL has a 1000 Hz output data rate which means 1 reading every 1 millisecond, and that is what required in my project, I am using an I2C connection and the information from " https://learn.sparkfun.com/tutorials/h3 … -guide/all "and the period between two readings is 3 to 4 millisecond, the code is as follow :

#include "SparkFun_LIS331.h"
#include <Wire.h>

LIS331 xl;
unsigned long startMillis;  
unsigned long currentMillis;
void setup() 
{
  Wire.begin();
  xl.setI2CAddr(0x19);    // This MUST be called BEFORE .begin() so 

   //  .begin() can communicate with the chip
  xl.begin(LIS331::USE_I2C); // Selects the bus to be used and sets
                          //  the power up bit on the accelerometer.
                          //  Also zeroes out all accelerometer
                          //  registers that are user writable.
xl.axesEnable(true);

  xl.setPowerMode(LIS331::NORMAL);
  xl.setODR(LIS331::DR_1000HZ);
  
startMillis = millis();  //initial start time
  
  
  Serial.begin(115200);
  
}

void loop() 
{
  int16_t x, y, z;
   currentMillis = millis();
    xl.readAxes(x, y, z);  // The readAxes() function transfers the
 Serial.print(currentMillis - startMillis);Serial.print(",");

    Serial.print(xl.convertToG(100,x)); Serial.print(","); // The convertToG() function
    Serial.print(xl.convertToG(100,y)); Serial.print(","); // accepts as parameters the
    Serial.println(xl.convertToG(100,z)); // Serial.println(", ");// raw value and the current
  startMillis = currentMillis;
}

could you please help me in this regard.

Thanks

Have you calculated how long it takes to print all that data, every time through loop(), at about 10 characters per millisecond?

next to Jremington’s remark: which processor board do you use? Some board drivers add more overhead-time than others…

jremington , paulvha, thank you for your reply, actually I didn’t try for characters per milliseconds, but I have calculated only for the sensor output, I used Arduino Uno and wemos d1 mini and I had the same time for both

In your program, the total time between collecting successive sets of (X, Y, Z) data (the true output data rate) includes the time it takes to print the data.

Capture.JPG
it shows the total time between two readings, it is the output result of the code above,

Note: When I decrease the baud rate, the time between two readings will be increased ( more time between two readings ) but when I increase the baud rate the maximum time I had is 3 to 4 millisecond