I'm currently working on a system that calculates the velocity by integrating the values of the acceleration.
I'm using the ADXL345 accelerometer with a ESP32, and so far, everything's going good, i'm getting correlated velocity and what not.
What i'm really confused about is the data rate, i've asked on another post and got a really good answer, but now i want to know that, if my output data rate from my acceleoremter is 100Hz should i synchronize it with my arduino code to get the data every 10 ms?
for(int i=0; i<340; i++)
{
Wire.beginTransmission(0x53);
Wire.write(0x34);
Wire.endTransmission();
Wire.requestFrom(0x53, 2);
values_y0[i] = Wire.read();
values_y1[i] = Wire.read();
delay(8);
} // the loop takes 3,11 seconds to finish
for(int i=0; i<340; i++)
{
values_y1[i] = values_y1[i] & 0x03;
y = (values_y1[i] << 8) + values_y0[i];
if(y > 512)
{
y = y - 1023;
}
values_y[i] = y * 0.004 * 9.8;
// some filtering
if(values_y[i] <= 0.16 && values_y[i] >= -0.16)
{
values_y[i] = 0;
}
}
for (int i=0; i<340; i++)
{
Serial.println(values_y[i]);
}}
I take 340 data points from the accelerometer, put them in an array and then work on them. The first loop does that, and it takes 3,11 seconds to finish which means 109Hz.