ADXL345 bad data

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
austinlambert82
 
Posts: 1
Joined: Wed Sep 20, 2017 3:39 pm

ADXL345 bad data

Post by austinlambert82 »

I purchased an accelerometer to try to measure vehicle movements for tuning purposes. The problem is I am not getting consistent readings.

When I set it on the desk the numbers are relatively constant although not at zero (I believe it to be a calibration issue) then I move it around the desk and it again gives me approximately the numbers I should be seeing. Then I strap it to the vehicle and the numbers are all over the place. I thought it might be an over sampling problem, so I backed the samples down from 100 per second to 10.

I thought it could be an issue with vibrations transfer so we packaged the whole thing in a box full of wash cloths to dampen vibrations. While it may not get them all it should get most of them. But that is not what I see. I know that this go kart is rated to between 3 and 4Gs of lateral acceleration so there is no reason I should ever see a number above that let alone the 15G plus spikes I see.

The code is simple in purpose, it grabs the x and y accel and writes it to an sd card shield. The code and the output is a csv file in the attachment. If anyone has any advice it would be greatly appreciated.



#include <SD.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>

Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);

File myFile;
int lineNumber = 1;


void setup()
{
Serial.begin(9600);
while (!Serial) {
}


Serial.print("Initializing SD card...");
pinMode(10, OUTPUT);

if (!SD.begin(10)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");


/* Initialise the sensor */
accel.begin();

accel.setRange(ADXL345_RANGE_16_G);

SD.remove("TEST.TXT");

}

void loop()
{
lineNumber += 1;

/* Get a new sensor event */
sensors_event_t event;
accel.getEvent(&event);

/* Display the results (acceleration is measured in m/s^2) */
Serial.print(lineNumber); Serial.print(",");
Serial.print(event.acceleration.x); Serial.print(",");
Serial.print(event.acceleration.y); Serial.println(" ");



// nothing happens after setup

// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("test.txt", FILE_WRITE);

// if the file opened okay, write to it:
if (myFile) {
myFile.print(lineNumber); myFile.print(",");
myFile.print(event.acceleration.x); myFile.print(",");
myFile.print(event.acceleration.y); myFile.println(" ");
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}

delay(100);

}
Attachments
TEST.csv
(20.19 KiB) Downloaded 114 times

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: ADXL345 bad data

Post by adafruit_support_mike »

All accelerometers will measure the force of gravity when they're being supported. The only time you get a true zero reading is when they're in free-fall.

WRT the data you posted, it does seem to show reasonable clustering if you take a running average of terms:

Code: Select all

    k = 3;
    avg_x = (( avg_x * ( k - 1 )) + x ) / k;
    avg_y = (( avg_y * ( k - 1 )) + y ) / k;
Higher values of k provide more smoothing, but are slower to respond to actual changes in the input.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”