Go Down

### Topic: ADXL335 Accelerometer (Read 3643 times)previous topic - next topic

#### rolando_rocha

##### May 26, 2011, 07:49 pm
Hi,
I have readed some posts with tilt measurement of ADXL335 accelerometer and i can't find the solution to calculate inclination angle.
Because i use Arduino Duemilanone with 3.3v and i read http://www.freescale.com/files/sensors/doc/app_note/AN3107.pdf, to calculate the inclination angle I have to use this formula:

angle=asin((Vout - 1650) / 330)

This is correct? I don't thing so, because the result is always 0.
Furthermore, my reads from x and y is about 324 and 345, so, with this values never i have a positive value.

Can you help me please, find the solution?

Rolando Rocha
From Portugal

#### AWOL

#1
##### May 27, 2011, 12:40 pm
Quote
angle=asin((Vout - 1650) / 330)

This is correct? I don't thing so, because the result is always 0.
Furthermore, my reads from x and y is about 324 and 345, so, with this values never i have a positive value.

I'm guessing here that the "1650" is in millivolts, not raw ADC counts (0...1023).
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### wildbill

#2
##### May 27, 2011, 01:10 pm
What readings does the ADC give you when you place the device at the angles you consider to be 0, 90 and -90?

#### AWOL

#3
##### May 27, 2011, 01:37 pm
Quick back-of-a-beermat calculation from the values given (324 to 345):

345 / 1024 * 5 = 1685mV
324 / 1024 * 5 = 1580mV

Does that help the calculation?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### rolando_rocha

#4
##### May 28, 2011, 12:32 am
Hi AWOL,
Thank you for your help... I think that i need explore more about reading analog values from Arduino. I think that the Arduinos Forum (http://didier.longueville.free.fr/arduinoos/?p=1389) will help me.
But... one more question. The raw values that i receive from X axis are:

-90º - 256
0º - 321
90º - 385

Is correct make a Lookup Table? I have to calculate the factor from 321 to 385 and from 321 to 256, and then make the calc.
Thank's again.

#### wildbill

#5
##### May 28, 2011, 01:51 pm
Depending on how accurate you need to be, you can start by assuming that your accelerometer's response is linear (it isn't) and use the map function thus:
angle=map(rawXAxisValue,256,385,-90,90)

May be sufficient, otherwise you will need better math or a lookup table as you suggest.

#### AWOL

#6
##### May 28, 2011, 02:41 pm
Quote
you can start by assuming that your accelerometer's response is linear (it isn't)

It is.
The sine function isn't though.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### btsp

#7
##### Jun 07, 2011, 05:34 pmLast Edit: Jun 07, 2011, 05:39 pm by btsp Reason: 1
I am using the ADXL335 as well i go the code from somewhere else i forget where,

I am getting my readings, but they never reach 90 degrees in the X and Y...only goes up to the 87-88 area.

Is this due to the Min and MAx values i sub in?

If i dont have the exact range of the axis, then will this do this?

here is the calculations i use
Code:
Code: [Select]
`//convert read values to degrees -90 to 90  int g0x;  int g0y;  int g0z;  g0x = ((maxValx - minValx)/2)+minValx;  g0y = ((maxValy - minValy)/2)+minValy;  g0z = ((maxValz - minValz)/2)+minValz;    int fx = (xRead - g0x);  int fy = (yRead - g0y);  int fz = (zRead - g0z);    float ax = fx*(3.3/(1024.0*((maxValx-minValx))/180));  //The 3.3V supply volt is divided by 1024 steps from the A/D converter. This value is divided by the sensitivity in X axis  float ay = fy*(3.3/(1024.0*((maxValy-minValy))/180));  //The 3.3V supply volt is divided by 1024 steps from the A/D converter. This value is divided by the sensitivity in Y axis  float az = fz*(3.3/(1024.0*((maxValz-minValz))/180));  //The 3.3V supply volt is divided by 1024 steps from the A/D converter. This value is divided by the sensitivity in Z axis    float rho = 0;             //MyAngle in X Axis  float phi = 0;             //MyAngle in Y Axis  float theta = 0;           //MyAngle in Z Axis  rho =   atan(ax/sqrt(pow(ay,2)+pow(az,2)))*(360/(2*3.1415));  //Calculate the X , Y ,Z angle.  phi =   atan(ay/sqrt(pow(ax,2)+pow(az,2)))*(360/(2*3.1415));  // this used (360/(2*3.1415) to convert radians to degrees.  theta = atan(sqrt(pow(ay,2)+pow(ax,2))/az)*(360/(2*3.1415));    `

the sensitivity of the chip is
300mv per g TYP.
330mv per g Max

Any suggestions to why it never reaches 90?

#### AWOL

#8
##### Jun 07, 2011, 06:31 pm
What do your intermediate values show?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### btsp

#9
##### Jun 07, 2011, 06:48 pmLast Edit: Jun 07, 2011, 07:09 pm by btsp Reason: 1
im not sure what you mean by intermediate values?

Im guessing the values from the accelerometer without conversion?

x: min 270 max 404

y: min 399 max 261

Go Up