Hallo zusammen, ich will ich mit einem NodeMcu und ADXL345 Beschleunigungswerte messen und z.B über 1 min eine Effektivwert-Berechnung durch die Formel a_hvx=sqrt((1/N)*sum(x^2)) durchführen. SPI ist hier als Kommunikationsprotkoll verwendet mit einer Abtastrate von 1600 Hz.
Mein Problem ist dass ich mehr Werte pro Sekunde bekomme(Siehe das angehängte Bild). Normelerweise sollte ich 1600 Werte pro Sekunde bekommen. Die Bandbreite habe ich auf 800 Hz programmtechnisch eingestellt(Siehe Code unten).
CodeBox C
Mein Problem ist dass ich mehr Werte pro Sekunde bekomme(Siehe das angehängte Bild). Normelerweise sollte ich 1600 Werte pro Sekunde bekommen. Die Bandbreite habe ich auf 800 Hz programmtechnisch eingestellt(Siehe Code unten).
CodeBox C
#include <SparkFun_ADXL345.h> // SparkFun ADXL345 Library /*********** COMMUNICATION SELECTION ***********/ /* Comment Out The One You Are Not Using */ ADXL345 adxl = ADXL345(5); // USE FOR SPI COMMUNICATION, ADXL345(CS_PIN); void setup(){ Serial.begin(9600); // Start the serial terminal Serial.println("SparkFun ADXL345 Accelerometer Hook Up Guide Example"); Serial.println(); adxl.powerOn(); // Power on the ADXL345 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.set_bw(ADXL345_BW_800); // set the Band width 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(){ // Accelerometer Readings 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++) { adxl.readAccel(&x,&y,&z); // Read the accelerometer values and store them in variables declared above x,y,z 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); }