Go Down

### Topic: ADXL345 information/help/problem/guidance etc :) (Read 8877 times)previous topic - next topic

#### vegos

#15
##### Nov 10, 2012, 01:17 pm
Question:

To measure G forces, I'm using that code:

Code: [Select]
`#include "ADXL345.h"ADXL345 accel;...  accel.powerOn();  accel.setFullResBit(1);  accel.setRangeSetting(8);  accel.get_Gxyz(xyz);  `

Is it correct? When I'm changing from 8 to 2 or to 4 for example, I get different readings. I just want the upper limit to be more than 4 Gs.
Antonis.

:: http://www.moschatoweather.eu :: www.slr.gr ::

#### lestofante

#16
##### Nov 10, 2012, 04:22 pmLast Edit: Nov 10, 2012, 04:24 pm by lesto Reason: 1
with setRangeSetting you are setting the upper (and lowest) limit. because the value are 10bit (form 0 to 1024), changing the limit also change the precision of the reading...

with limit of 2, a read of 512 (zero)+(512/2=256) is 1G. BUT at limit 8, 1G it is 512+(512/8=64)

(value are just example, they can be wrong. for example, al 16G the sensor can use 16bit precision.
Guida per principianti http://playground.arduino.cc/Italiano/newbie
Unoffical Telegram group https://t.me/genuino

#### vegos

#17
##### Nov 10, 2012, 04:47 pm

with setRangeSetting you are setting the upper (and lowest) limit. because the value are 10bit (form 0 to 1024), changing the limit also change the precision of the reading...

with limit of 2, a read of 512 (zero)+(512/2=256) is 1G. BUT at limit 8, 1G it is 512+(512/8=64)

(value are just example, they can be wrong. for example, al 16G the sensor can use 16bit precision.

That means after reading the values (I'm using this library) I have to convert them?

Here is reading procedure of the library:

Code: [Select]
`void ADXL345::get_Gxyz(double *xyz){  int i;  int xyz_int[3];  readAccel(xyz_int);  for(i=0; i<3; i++){    xyz[i] = xyz_int[i] * gains[i];  }}`

It looks like it multiplies the result with gains (for the 3 axis). I need to do further calculations, like the ones you suggest?
Antonis.

:: http://www.moschatoweather.eu :: www.slr.gr ::

#### lestofante

#18
##### Nov 10, 2012, 06:25 pmLast Edit: Nov 10, 2012, 06:34 pm by lesto Reason: 1
yes, but technically the library is wrong.
every time you change the range, the array gains should change accordingly..

but it is not implemented, so you can make the gain calculation by yourself and use the setGain function.

Guida per principianti http://playground.arduino.cc/Italiano/newbie
Unoffical Telegram group https://t.me/genuino

#### ocelotrevs

#19
##### Nov 10, 2012, 10:25 pmLast Edit: Nov 10, 2012, 10:28 pm by ocelotrevs Reason: 1
How sensitive is this sensor in recording tilt.
I've had a look at the data sheets, and it just says less than 1 degree.
Does anyone know if there's anything more specific than this. Like 0.5 degrees.
Or would 1 degree be enough to go with.
The reason I'm asking is because I need to choose a motor for a self leveling platform, and the sensitivity of the sensor will dictate the motor I choose.

Thanks

#### AWOL

#20
##### Nov 10, 2012, 11:08 pm
Quote
How sensitive is this sensor

The datasheet says 4mg / LSB, which I make to be a bit less than 0.04 ms-2 on the most sensitive +/- 2g range. (4 / 1024 = 0.00390625)
"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.

#### lestofante

#21
##### Nov 11, 2012, 01:49 pm

I've had a look at the data sheets, and it just says less than 1 degree.

the datasheet talk about gravity, not about degree. you have to do the math
Guida per principianti http://playground.arduino.cc/Italiano/newbie
Unoffical Telegram group https://t.me/genuino

#### vegos

#22
##### Nov 11, 2012, 05:27 pmLast Edit: Nov 11, 2012, 10:11 pm by vegos Reason: 1
Updated code:

Code: [Select]
`  accel.setFullResBit(1);  accel.setRangeSetting(8);....  int *x,*y,*z;  accel.readAccel(x,y,z);    xyz[0]=(*x*0.0078);  xyz[1]=(*y*0.0078);  xyz[2]=(*z*0.0078); `

(0.0078 = 8/(2^10) - I guess that's correct for scaling 8Gs ? Is it?
Antonis.

:: http://www.moschatoweather.eu :: www.slr.gr ::

#### ocelotrevs

#23
##### Nov 11, 2012, 07:13 pmLast Edit: Nov 11, 2012, 07:17 pm by ocelotrevs Reason: 1

I've had a look at the data sheets, and it just says less than 1 degree.

the datasheet talk about gravity, not about degree. you have to do the math

Unfortunately, I have no idea where to even start with trying to work that out.
Any pointers?
All the terminology is new to me.

#### dhenry

#24
##### Nov 11, 2012, 09:54 pm
Quote
Any pointers?

Middle school geometry.

#### ocelotrevs

#25
##### Nov 12, 2012, 10:45 am

Quote
Any pointers?

Middle school geometry.

That was never my strong point.
Do we need to relate the bit resolution in terms of a g unit, then relate that to a degree value. So a 10 bit resolution gives a sensitivity of 0.1 degree of sensitivity.
Or does it relate to the mg/LSB value. So if a value of 4mg/LSB is given, then the sensitivity is 0.25 degrees?

#### lestofante

#26
##### Nov 12, 2012, 11:47 am
we can calculate orientation (from -90° to 90°) on one axes by

asin(val);

where val HAVE to be from -1 to 1, so

maxValue = 1024
half=maxValue/2; //because we have value from 0 to 1024, 0 is -G, 1024is +G and 512 is 0G
val = (rawRead-half)/half; //the /zero assure that we will have a result in range of -1, +1

(notice you have to use acos if this axis is parallel to gravity vector, so asin for x and y, acos for Z)

now we have to set our precision. with a precision of +-4g, 1g = 512/4 = 128LSB so 1LSB = 1/128 G
precision now is asin(0) - asin(1/128)
asin of 0 is 0 (how convenient!)
asin of (1/128) is 0.44°, so 0.44° is your precision

but we don't need 4g, because any value above 1G is just noise from acceleration, so we can use the lowest resolution witch is +-2G, 1G= 512/2=256LSB, so 1LSB=1/256
asin(1/256) = 0.22°
Guida per principianti http://playground.arduino.cc/Italiano/newbie
Unoffical Telegram group https://t.me/genuino

#### dhenry

#27
##### Nov 12, 2012, 05:25 pm
The number to look for is the sensitivity figure. This particular chip has the max sensitivity ratings of 256lsb/g, so each "bit" corresponds to 1/256g. or 90/256 ~= 0.4 degree, in theory.

In reality, you would be lucky to get to within 2-3 degrees.

#### lestofante

#28
##### Nov 12, 2012, 05:39 pm
how you come out with 4degree?
Guida per principianti http://playground.arduino.cc/Italiano/newbie
Unoffical Telegram group https://t.me/genuino

#### AWOL

#29
##### Nov 12, 2012, 06:28 pm
Small angle sine approximation doesn't work that well for angles in degrees.
"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.

Go Up