# Couldn't get a calibrated value for ADXL 345 accelerometer

i measured min and max points according this link. Programming and Calibration | ADXL345 Digital Accelerometer | Adafruit Learning System

got those :
21:45:08.028 -> Accel Minimums: -15.73 -15.85 0.00
21:45:08.028 -> Accel Maximums: 8.47 7.65 63.59

my code:

``````  Serial.print("X: "); Serial.print((((event.acceleration.x - (-15.73))* 19.62)/8.47) + (-9.81) ); Serial.print("  ");
Serial.print("Y: "); Serial.print((((event.acceleration.y - (-15.85))* 19.62)/7.65) + (-9.81) ); Serial.print("  ");
Serial.print("Z: "); Serial.print((((event.acceleration.z)* 19.62)/63.59) + (-9.81) ); Serial.print("  ");Serial.println("m/s^2 ");
``````

still having uncalibrated measurments , where am i making a mistake ? Thanks.

Please use code tags when posting code.

You have not applied the offsets or scale correctly, so please re-read the instructions in the tutorial. Remove the "-9.81" term. It should not be there.

``````Serial.print("X: "); Serial.print((((event.acceleration.x - (-15.73))* 19.62)/8.47) + (-9.81) );
``````

This is a better description of the "six point" calibration method.

Those numbers are WAY off. After measuring in all 6 directions the maximums should be close to 1.00 and minimums should be close to -1.00. Even if the scale factor is bad the readings should be +/-N for all three axes since all three are measuring the same acceleration due to gravity.

23:12:59.199 -> Accel Minimums: -15.85 -16.04 0.00
23:12:59.245 -> Accel Maximums: 8.71 7.73 64.06

i don't understand why, how about i try one point scaling, or a different wiring ? Thanks

You should be making SIX measurements. For each measurement, the axis that is vertical should show a value close to 1.00 or -1.00. The other two axes are horizontal and should read near 0.

Follow the link you posted. Start at "Calibration Method:" and work through the steps.

i know, i mean i made six measurements for each ten, fifteen set of measurements according to link that i posted. but nothing changes.

You are probably making a mistake (or two).

Post the code you used to make the measurements, using code tags please. You should be reading the RAW accelerometer values. Those will be integers and won't look anything like the numbers you posted.

If you are getting results that far from normal (+1, -1) I would suspect that you accelerometer has been broken by severe impact. Time to buy a new one.

i am using the basic code given at the link

``````#include <Wire.h>

/* Assign a unique ID to this sensor at the same time */

float AccelMinX = 0;
float AccelMaxX = 0;
float AccelMinY = 0;
float AccelMaxY = 0;
float AccelMinZ = 0;
float AccelMaxZ = 0;

void setup(void)
{
Serial.begin(9600);
Serial.println("");

/* Initialise the sensor */
if(!accel.begin())
{
/* There was a problem detecting the ADXL345 ... check your connections */
while(1);
}
}

void loop(void)
{
while (!Serial.available()){}  // wait for a character

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

if (accelEvent.acceleration.x < AccelMinX) AccelMinX = accelEvent.acceleration.x;
if (accelEvent.acceleration.x > AccelMaxX) AccelMaxX = accelEvent.acceleration.x;

if (accelEvent.acceleration.y < AccelMinY) AccelMinY = accelEvent.acceleration.y;
if (accelEvent.acceleration.y > AccelMaxY) AccelMaxY = accelEvent.acceleration.y;

if (accelEvent.acceleration.z < AccelMinZ) AccelMinZ = accelEvent.acceleration.z;
if (accelEvent.acceleration.z > AccelMaxZ) AccelMaxZ = accelEvent.acceleration.z;

Serial.print("Accel Minimums: "); Serial.print(AccelMinX); Serial.print("  ");Serial.print(AccelMinY); Serial.print("  "); Serial.print(AccelMinZ); Serial.println();
Serial.print("Accel Maximums: "); Serial.print(AccelMaxX); Serial.print("  ");Serial.print(AccelMaxY); Serial.print("  "); Serial.print(AccelMaxZ); Serial.println();

while (Serial.available())
{
Serial.read();  // clear the input buffer
}
}
``````

i changed the wiring and got these final measurements
00:04:15.005 -> Accel Minimums: -15.89 -16.04 0.00
00:04:15.051 -> Accel Maximums: 9.30 7.61 20.04

current circuit:
GND - GND
VCC - 5V
SCL - SCL
SDA -SDA

and i don't think it's broken because i recently bought it and first time using.

I really dislike and recommend to avoid the bloated Adafruit libraries, because they attempt to scale the data without knowing the corrections required for your particular unit.

Remove those libraries and try another. You might consider the Sparkfun or the gabriel-ns library.

In either case, MAKE SURE that you are reading the RAW accelerometer values, not scaled values. For the Sparkfun library, follow the hookup guide and use this routine to get the RAW data:

``````ADXL345::readAccel(int *x, int *y, int *z)
``````

i used Sparkfun library calibration code, followed the steps mentioned and i obtained
`New Calibrated Values: 0 9 9`
so the question: what i am going to with these ?

Those look bogus. If your block is resting on one of its sides, one axis should read +1g or -1g and the other two should read 0g. NONE should read 9g.

What Accel Minimums and Accel Maximums do you get after taking a single measurement on all 6 sides?

so the question: what i am going to with these ?

Nothing, because those values make no sense.

Help us help you. Please post the RAW accelerometer data, from the Sparkfun library, for EACH of the six calibration orientations.

For example:
"Z pointing up" x, y, z values
"Z pointing down" x, y, z values
"Y pointing up" x, y, z values
etc.

Sorry for being this painful,

``````"Z pointing up" -13, -16, 202
"Z pointing down" -12, -13, 134
"X pointing up" 27, -13, 169
"X pointing down" -51, -14, 169
"Y pointing up" -13, 24, 173
"Y pointing down" -12, -51, 169
``````

Also, sparkfun calibration script, From top to below --> (+Z,-Z,+X,-X,+Y,-Y)

``````20:33:52.642 -> SparkFun ADXL345 Accelerometer Breakout Calibration
20:33:52.642 ->
20:33:52.642 -> Send any character to display values.
20:34:12.910 ->
20:34:12.910 -> Accel Minimums: -101  -130  0
20:34:12.960 -> Accel Maximums: 0  0  511
20:34:12.960 ->
20:34:12.960 -> Send any character to display values.
20:34:21.123 ->
20:34:21.123 -> Accel Minimums: -101  -130  0
20:34:21.172 -> Accel Maximums: 0  0  511
20:34:21.172 ->
20:34:21.172 -> Send any character to display values.
20:34:28.192 ->
20:34:28.192 -> Accel Minimums: -101  -130  0
20:34:28.241 -> Accel Maximums: 212  0  511
20:34:28.241 ->
20:34:28.286 -> Send any character to display values.
20:34:33.706 ->
20:34:33.706 -> Accel Minimums: -402  -130  0
20:34:33.755 -> Accel Maximums: 212  0  511
20:34:33.755 ->
20:34:33.755 -> Send any character to display values.
20:34:51.724 ->
20:34:51.724 -> Accel Minimums: -402  -130  0
20:34:51.772 -> Accel Maximums: 212  194  511
20:34:51.772 ->
20:34:51.772 -> Send any character to display values.
20:34:57.628 ->
20:34:57.628 -> Accel Minimums: -402  -405  0
20:34:57.677 -> Accel Maximums: 212  194  511
20:34:57.718 ->
20:34:57.718 -> Send any character to display values.

``````

by the way my circuit is slightly different from shown at Sparkfun page. My circuit only consists:
GND - GND , VCC - 5V ,SCL - SCL , SDA -SDA , nothing else.

The sensor is clearly not working correctly, as the Z axis reading is always large and positive regardless of orientation. It is either defective or has been damaged.

Note that the sensor chip is 3.3V MAXIMUM, and you should have level shifters on the I2C lines, when used with a 5V Arduino. Best to use a 3.3V Arduino with a 3.3V sensor, then there are no voltage mismatch worries.

i changed 5V to 3.3V and redid the previous raw data measurement just to be sure. But nothing changed. My breakout:

Also broken Z axis is not a big problem for me, i only need one horizontal axis to be calibrated.

Is it too much trouble to post a link to the sensor module?

i changed 5V to 3.3V

The damage has already been done.

It is not clear that the X or Y axes are working. If you have chosen the +/- 2g scale, you would expect much larger numbers in those positions (e.g. roughly 250 and -250 for up and down, respectively).

it is on range 16g.
i thought you asked the circuit. sensor module page is in another language clearly you wouldn't understand but it says 2V - 3.6V for range.
Let's assume they working even if they don't i only need a data range. so what should i do, this already took so long can you paste me a suitable code?