ADXL345 data +/-

Hello

I am beginner. I am start playing with ADXL345.

I did used sample code from S,F 's web and modified to print just 3 axis data.

When the chip is Face up, X and Y should be +0g and Z should be +1g per spec sheet.

Serialprint shows both X and Y are “+”, but “-” for the Z axis.

What I am doing wrong?

I added conversion fomular to get angle to test the reading.

I turned chip 90deg side way that way I want to use.

Unfortunately "+ " " - " on X axis changes at middle of angle when I swing up-down.

So it shows " + "90 (1 pin down) stays "+ "approx 50 and change to “-” after that thru 0 and up to 90 (1 pin up)

+90… +60 … -5#…-30 …-10 … -0 … -10 … -30 …-90

I’m looking for to read +90++++ 0 ------90

Is this relate to issue of Z been opposit from the beginning?

The Z-axis is up out of the chip. Earth’s gravity is down, therefore the reading when the chip is up and level on the Z-axis is -1g.

Reading out the raw 3d data is a good idea to work out the math manually. Depending on what you want to call "0 angle, you need to possibly change signs (±) and use the correct axis in the numerator/denominator for the trig.

Thank you for the comment, but as I wrote in 4th line, I did read raw g number.

I say face up means silkscreen up, solder side down to the earth. then Z should be “+” 1g.

I am getting “-” instead of “+”.

Are you saying I have to change manually?

I thought the chip will create correct +/- per gravity.

I don’t care 0 deg shows + or - due to i am going to use only 1 digit. +0.01 will show + and -0.01 will show -

That is fine, but I don’t understand why it changes at some middle angle.

The chip actually measures the difference between the force applied to the chip package and the force applied to the sensor itself, which you can think of as a small spring and mass inside the chip.

So, if the chip is sitting still on a table, the table is pushing “up” on the package and the spring+mass and package are being pulled down by the Earth’s gravity. As a result, the chip reports a positive force in the up direction, equal to 1 g. If you experiment a bit, you should see that the signs on X, Y and Z are consistent with that view.

Another consequence of thinking about the sensor this way, is that if the chip is freely falling, it reports 0 g. The forces acting on the package and the spring+mass inside are identical and cancel out.

Thank you Mr Remington, but I am not getting answer for why +/- flips at middle.

May be people are not getting rotation that what I am using. I did tested 0g condition on the table. “X and Y are 0 plus little offset”

Now I am using it as Solder/silkscreen vertically to the ground.

9 - 3 o’clock as horizontal X axis and swing 6 to 12 o’clock. (vertically)

X axis saids from 6:00 to around 7:30 are positive, but it changes negative after 7:30 instead of stay positive till 9:00.

If it stays posi or neg for 90 deg swing, then I am fine. I just rotate PCB 180 deg for what I wnat to see(- for 9 to 12), but I don’t understand that it changes middle.

Any idea?

You need to calibrate the sensor. It has offsets and gain errors on each axis that need to be compensated.

Do you see the same magnitude on the Z axis (except for sign) when you flip the sensor over? I’ll bet you don’t.

My favorite procedure for calibrating accelerometers, which is also the best, can be found at http://sailboatinstruments.blogspot.com … ation.html

The procedure was developed for magnetometers but it works perfectly well for accelerometers, providing that you hold the sensor still while each data point is being collected.