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