I am using ADXL345 accelerometer with Adafruit_ADXL345 library for vibration measurement. The communication mode is I2C and it is working well at lower frequencies. When I increase the vibrations, there comes a limit (this limiting value is approximately +-1.5g on either axis) at which accelerometer stops plotting data serially. I thought it may be due to loose connections and I took another ADXL345 and soldered its contacts with hoop up wires but it behaved the same way at higher vibrations. Here is the code that I’m using.
#include <DueTimer.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
/* Assign a unique ID to this sensor at the same time */
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12);
int i=0;
struct measure
{
int timestamp;
float x; // ACC in x direction
float y; //ACC in y direction
float z; //ACC in z direction
};
sensors_event_t event;
struct measure measurements;
int timestamp = 0;
void firstHandler(){
/* Feeding the array with data*/
accel.getEvent(&event);
measurements.timestamp = timestamp++;
measurements.x = event.acceleration.x;
measurements.y = event.acceleration.y;
measurements.z = event.acceleration.z;
if(measurements.timestamp%2==0)
digitalWrite(LED_BUILTIN, HIGH);
else
digitalWrite(LED_BUILTIN, LOW);
/* Sending the array with data through serial*/
Serial.print(measurements.timestamp);
Serial.print(",");
Serial.print(measurements.x+0.06);
Serial.print(",");
Serial.print(measurements.y+0.7);
Serial.print(",");
Serial.println(measurements.z-10.10);
}
void setup(){
Serial.begin(115200);
Timer3.attachInterrupt(firstHandler).start(5000); // Every 5ms
//Timer5.start();
Serial.println("Accelerometer Test"); Serial.println("");
/* Initialise the sensor */
if(!accel.begin())
{
/* There was a problem detecting the ADXL345 ... check your connections */
Serial.println("Ooops, no ADXL345 detected ... Check your wiring!");
while(1);
}
accel.setDataRate(ADXL345_DATARATE_3200_HZ);
accel.setRange(ADXL345_RANGE_16_G);
pinMode(LED_BUILTIN, OUTPUT);
delay(2000);
}
void loop(){
}