ADXL337 calibration

Hi folks,

I am trying to calibrate my sparkfun adxl337 accelerometer. I am changing these values from the example sketch:

scaledX = mapf(rawX, 0, 1028, -scale, scale);
scaledY = mapf(rawY, 0, 1023, -scale, scale);
scaledZ = mapf(rawZ, 0, 921.35, -scale, scale);

What I noticed is that when I calibrate the +scale, the -scale is also changed and vice versa. So after calibrating the + scale to 921.35, I went to calibrate the -scale and then the +scale values were changed and my scaled readings are no longer accurate. I was wondering if anyone has any insight as to fixing this.

Thanks so much,

Aidan S Burke

adxl337.ino (2.6 KB)

Your explanation of the problem is very unclear. Please explain more clearly how you are trying to calibrate the sensor, post the code corresponding to an attempt, and state what goes wrong.

"-scale" and "scale" refer to the [u]same[/u] variable, so changing the value of "scale" changes both entries in the function call.

But scale should be 3 for your sensor.

I’m sorry that I was unclear. The code I am using in below. I’m using a 3.3V arduino so boolean micro_is_5V = false; .

These are the ranges for scaling raw data for 3.3V arduino:

scaledX = mapf(rawX, 0, 1023, -scale, scale);
scaledY = mapf(rawY, 0, 1023, -scale, scale);
scaledZ = mapf(rawZ, 0, 1023, -scale, scale);

Currently, when I use these ranges, my data looks like this:

Raw:

X: 520
Y: 504
Z: 614

Scaled:

X: 0.05 g
Y: -0.04
Z: 0.60 g

My question is: How can I offset the ranges (currently 0, 1023) to calibrate my sensor?

Thank you so much and I apologize for being unclear earlier.

-Aidan

adxl337.ino (2.59 KB)

Sorry, I have no idea what your "raw data" represent.

The first thing you need to do is understand the raw data. Just run the example program and look ONLY at the raw data from the analog pins.

How do those data change for different orientations of the sensor? The PCB should have the axes X, Y and Z indicated on it somewhere.

You can calibrate the sensor by writing down the value reported for each axis, X, Y or Z, when the sensor is held still, and the axis is exactly perpendicular to the Earth's surface, i.e straight up or down. By definition, the value reported is equivalent to +/- 1 g. Explained in this tutorial: https://learn.adafruit.com/adxl345-digital-accelerometer/programming?view=all

Thank you for your response. I am trying to change these values:

scaledX = mapf(rawX, 0, 1023, -scale, scale); scaledY = mapf(rawY, 0, 1023, -scale, scale); scaledZ = mapf(rawZ, 0, 1023, -scale, scale);

in order to calibrate my sensor.

If possible, I'd rather change these values that using a different library that is not for my sensor.

If anyone else is familiar with this method of scaling accelerometers, I would greatly appreciate some guidance.

Best,

Aidan

I don't know what you mean by "change these values". Please state exactly which values you want to change, and your basis for changing them (that is, what values should they be). The zero values in the map function are certainly wrong.

I suggest to read some of the excellent on-line tutorials on calibrating an accelerometer, like this one, or the one I already linked in reply #3 above.

The most accurate method of accelerometer and magnetometer calibration is described in this exhaustive tutorial.

I appreciate the tutorials that you linked, however I want to work with the library that I have.

By "change these values" I mean change the integers 0 and 1023 to calibrate my accelerometer. I was able to change them individually to zero the accelerometer in one orientation, but it was not the exact opposite when flipped over.

Library? What library? I assume you mean the code you have. The links you were provided are sketches (programs) to give you the data you seem to be looking for. Every sensor will vary slightly from nominal values. The nice thing about the calibration software is when done correctly it gives you good numbers for your module, what you have. Then you can apply those numbers in your code. In the one sample they average 10 readings for each axis which comes in handy for getting good accurate data.

“I was able to change them individually to zero the accelerometer in one orientation, but it was not the exact opposite when flipped over”.

Exactly which is why you want good raw data tagged to your specific accelerometer.

Ron

but it was not the exact opposite when flipped over.

Then you are doing the calibration incorrectly.

The code you have is just about the worst possible place to start, but have fun anyway!