Pages: 1 [2] 3   Go Down
Author Topic: ADXL345 information/help/problem/guidance etc :)  (Read 3773 times)
0 Members and 1 Guest are viewing this topic.
Athens, Greece
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Question:

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

Code:
#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.
Logged


0
Offline Offline
Shannon Member
****
Karma: 130
Posts: 10448
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: November 10, 2012, 10:24:47 am by lesto » Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Athens, Greece
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


0
Offline Offline
Shannon Member
****
Karma: 130
Posts: 10448
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

(opened an issue about this smiley )
« Last Edit: November 10, 2012, 12:34:35 pm by lesto » Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley
« Last Edit: November 10, 2012, 04:28:01 pm by ocelotrevs » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25803
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

0
Offline Offline
Shannon Member
****
Karma: 130
Posts: 10448
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Athens, Greece
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Updated code:

Code:
 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?
« Last Edit: November 11, 2012, 04:11:20 pm by vegos » Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: November 11, 2012, 01:17:38 pm by ocelotrevs » Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Any pointers?

Middle school geometry.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Shannon Member
****
Karma: 130
Posts: 10448
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Shannon Member
****
Karma: 130
Posts: 10448
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

how you come out with 4degree?
Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25803
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Small angle sine approximation doesn't work that well for angles in degrees.
Logged

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

Pages: 1 [2] 3   Go Up
Jump to: