Skip to main content
Visitor II
July 4, 2022
Question

Can't reach 1000 Hz output data rate for H3LIS331DL Accelerometer sensor

  • July 4, 2022
  • 1 reply
  • 894 views

As the datasheet of H3LIS331DL has a 1000 Hz output data rate which means 1 reading every 1 millisecond, and that what is required in my project, I am using an I2C connection and having the period between two readings 3 to 4 milliseconds, 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;
}

The Output Result:

0693W00000QKOhhQAH.jpgcould you please help me to have 1 reading every 1 milisecond.

Thanks

    This topic has been closed for replies.

    1 reply

    Super User
    July 4, 2022

    The serial port baud rate is a limiting factor. Calculate how many chars/s you can print.

    hth

    KnarfB

    AGHAZ.1Author
    Visitor II
    July 5, 2022

    Thank you for your reply. Could you please tell me how to do it :grinning_face_with_sweat: , and is there any way to overcome the baud rate limitation so the sensor output data rate can reach 1 kHz,

    I decreased the baud rate, and the interval between two readings increased, but when I increased the baud rate, the interval would stay3 to 4 even when the baud rate on 2000000.