Hello everyone, I want to measure acceleration values with a NodeMcu and ADXL345 and e.g. perform an effective value calculation over 1 min using the formula a_hvx = sqrt ((1 / N) * sum (x ^ 2)). SPI is used here as a communication protocol with a sampling rate of 1600 Hz.
My problem is that I get more values per second (see image). I should normally get 1600 values per second. I programmatically set the bandwidth to 800 Hz (see code).

``````#include <SparkFun_ADXL345.h>         // SparkFun ADXL345 Library

/*********** COMMUNICATION SELECTION ***********/
/*    Comment Out The One You Are Not Using    */

void setup(){

Serial.begin(9600);                 // Start the serial terminal
Serial.println("SparkFun ADXL345 Accelerometer Hook Up Guide Example");
Serial.println();

adxl.setRangeSetting(16);           // Give the range settings
// Accepted values are 2g, 4g, 8g or 16g
// Higher Values = Wider Measurement Range
// Lower Values = Greater Sensitivity
adxl.setSpiBit(0);                  // Configure the device to be in 4 wire SPI mode when set to '0' or 3 wire SPI mode when set to 1
// Default: Set to 1
// SPI pins on the ATMega328: 11, 12 and 13 as reference in SPI Library

}

void loop(){

int x,y,z;
int  t, f_rate,i;

int xsum= 0.0, ysum= 0.0, zsum= 0.0;
float a_hvx, a_hvy, a_hvz, cons, N;
f_rate= 1600 ;                // Data rate
t= 1 ;                        // measurement time
N= t*f_rate;                  // calculate the samples during current time (t)
//  int arr[N+1];
cons=  1/N;
for (i=0; i< N; i++)
{

xsum += pow(x,2);
ysum += pow(y,2);
zsum += pow(z,2);
}

Serial.print("xsum = ");
Serial.print(xsum);
Serial.print(", ");
Serial.print("ysum = ");
Serial.print(ysum);
Serial.print(", ");
Serial.print("zsum = ");
Serial.print(zsum);
Serial.print(", ");
a_hvx= sqrt(cons*xsum);
a_hvy= sqrt(cons*ysum);
a_hvz= sqrt(cons*zsum);
Serial.print("a_hvx = ");
Serial.print(a_hvx);
Serial.print(", ");
Serial.print("a_hvy = ");
Serial.print(a_hvy);
Serial.print(", ");
Serial.print("a_hvz = ");
Serial.println(a_hvz);

}
``````

My problem is that I get more values per second (see image below).

There's no image below. External links to temporary internet storage is not the way to post pictures to this forum. Attach the picture to your post!

Please edit your post and change the "quote" tags to "code" tags!

I have some doubts that an 16bit signed integer can hold 1600 values of the square of a sensor value.