Go Down

Topic: Measuring tilt with an MMA7260Q accelerometer (Read 3 times) previous topic - next topic

Fabio Varesano

Ideally, when the accelerometer is flat you should read x=0g, y=0g, z=1g.

Do you have your AREF connected to a 3.3Volts source? You have also to set this in the code http://arduino.cc/en/Reference/AnalogReference
analogReference(EXTERNAL)

jraskell

Code: [Select]
Ax = x-Voff/sens;

This calculation will not produce the value you want as the order of operations is off.  Division will occur before subtraction, but you want the subtraction to occur first.  IE, offset the x value, then divide it by the sensitivity (which is not the same as dividing the offset by the sensitivity, and subtracting that value from the x value, which basically means you're just subtracting 2 from all your values).

Code: [Select]
Ax = (x-Voff)/sens;

Paranthesis have the highest order of operations, so operation inside paranthesis will always be performed before operations outside them.

deviukk


Do you have your AREF connected to a 3.3Volts source? You have also to set this in the code http://arduino.cc/en/Reference/AnalogReference
analogReference(EXTERNAL)


Whats the use of the doing that? So its not possible to use the sensor with only your laptop and an Arduino board?


Code: [Select]
Ax = x-Voff/sens;

This calculation will not produce the value you want as the order of operations is off.  Division will occur before subtraction, but you want the subtraction to occur first.  IE, offset the x value, then divide it by the sensitivity (which is not the same as dividing the offset by the sensitivity, and subtracting that value from the x value, which basically means you're just subtracting 2 from all your values).

Code: [Select]
Ax = (x-Voff)/sens;

Paranthesis have the highest order of operations, so operation inside paranthesis will always be performed before operations outside them.


Off course! Stupid mistake. Thanks!

Fabio Varesano

Quote
Whats the use of the doing that? So its not possible to use the sensor with only your laptop and an Arduino board?


Any voltage applied to the AREF pin after calling analogReference(EXTERNAL) will be taken as the reference voltage for the analog-digital converter.. this means that if you have a 3.3V voltage on the AREF pin, when you use the analog input you will get 1023 when the voltage read on it is 3.3V.

Without doing so, the default voltage (on any 16Mhz arduino) would be 5 Volts. So if you don't do the above and you expect your analog voltages to be 3.3V maximum you are loosing almost 1/3 of precision.

deviukk

Ok,

But normally this should also work without doing that thing with Aref. Just with less accuracy. But I'm just receiving crap.. I can't see what wrong in the code.. Maybe I need to do some sort of calibration?

Thx

Go Up