Go Down

Topic: ADXL337 calibration (Read 74 times) previous topic - next topic


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


Mar 26, 2020, 03:49 pm Last Edit: Mar 26, 2020, 03:59 pm by jremington
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 same 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:


X: 520
Y: 504
Z: 614


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.



Mar 26, 2020, 10:37 pm Last Edit: Mar 26, 2020, 10:41 pm by jremington
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

Go Up