Pages: [1]   Go Down
 Author Topic: ADXL335 Accelerometer  (Read 686 times) 0 Members and 1 Guest are viewing this topic.
0
Offline
Newbie
Karma: 0
Posts: 4
Arduino rocks
 « on: May 26, 2011, 12:49:41 pm » Bigger Smaller Reset

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
 Logged

Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
 « Reply #1 on: May 27, 2011, 05:40:36 am » Bigger Smaller Reset

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).
 Logged

Pete, it's a fool looks for logic in the chambers of the human heart.

New Jersey
Offline
Edison Member
Karma: 24
Posts: 2354
 « Reply #2 on: May 27, 2011, 06:10:41 am » Bigger Smaller Reset

What readings does the ADC give you when you place the device at the angles you consider to be 0, 90 and -90?
 Logged

Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
 « Reply #3 on: May 27, 2011, 06:37:39 am » Bigger Smaller Reset

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?
 Logged

Pete, it's a fool looks for logic in the chambers of the human heart.

0
Offline
Newbie
Karma: 0
Posts: 4
Arduino rocks
 « Reply #4 on: May 27, 2011, 05:32:25 pm » Bigger Smaller Reset

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.

 Logged

New Jersey
Offline
Edison Member
Karma: 24
Posts: 2354
 « Reply #5 on: May 28, 2011, 06:51:34 am » Bigger Smaller Reset

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.
 Logged

Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
 « Reply #6 on: May 28, 2011, 07:41:12 am » Bigger Smaller Reset

Quote
you can start by assuming that your accelerometer's response is linear (it isn't)
It is.
The sine function isn't though.
 Logged

Pete, it's a fool looks for logic in the chambers of the human heart.

Offline
Jr. Member
Karma: 0
Posts: 65
 « Reply #7 on: June 07, 2011, 10:34:27 am » Bigger Smaller Reset

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:
//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?

 « Last Edit: June 07, 2011, 10:39:46 am by btsp » Logged

Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
 « Reply #8 on: June 07, 2011, 11:31:54 am » Bigger Smaller Reset

What do your intermediate values show?
 Logged

Pete, it's a fool looks for logic in the chambers of the human heart.

Offline
Jr. Member
Karma: 0
Posts: 65
 « Reply #9 on: June 07, 2011, 11:48:11 am » Bigger Smaller Reset

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

 « Last Edit: June 07, 2011, 12:09:07 pm by btsp » Logged

 Pages: [1]   Go Up