Hello,
I know that there are dozens of threads related to this accelerometer but all of the responses that I see talk about angles and inclinations.
I'm trying to measure the G forces in a car. It doesn't matter which direction, I just want to measure the maximum G forces applied for that instant.
I've tried mutiple snippets of code but nonw of them worked as expected.
My last attempt was made using this library:
http://code.google.com/p/mma7361-library/downloads/detail?name=AcceleroMMA7361_v0.8b.zip
But still couldn't get somewhere. I tried to use a function called getTotalVector () and use the difference between the actual and previous call to calculate the actual G forces but I don0t think it is working as expected
This is how the accelerometer is connected to the arduino:
X -> A0
Y -> A1
z -> A2
GND -> GND
3.3 -> 3.3
SL -> 3.3
G0 is not used and so is the Sensitivity selector ( LOW = 1.5G ).
And this is the piece of code I'm trying to use (ignore some of the pins I'm passing in the begin function because, just as I told you before, I'm not using them even though I need to point them to initialize the library):
#include <AcceleroMMA7361.h>
AcceleroMMA7361 accelero;
int x;
int y;
int z;
double G;
int current=0;
void setup()
{
Serial.begin(9600);
accelero.begin(13, 12, 11, 10, A0, A1, A2);
accelero.setARefVoltage(3.3); //sets the AREF voltage to 3.3V
accelero.setSensitivity(HIGH); //sets the sensitivity to +/-6G
accelero.setAveraging(100);
accelero.calibrate();
}
void loop()
{
// g = [mV/analogRead unit] * ([units] - ([Aref/2]) / [mvPerG]
current = abs(current - accelero.getTotalVector());
G = 3.22 * ((current - 3.3 / 2) / 2450);
x = accelero.getXAccel();
y = accelero.getYAccel();
z = accelero.getZAccel();
Serial.print("\nx: ");
Serial.print(x);
Serial.print(" \ty: ");
Serial.print(y);
Serial.print(" \tz: ");
Serial.print(z);
Serial.print("\tG*10^-2");
Serial.print( " -> " );
Serial.print( G );
delay(500); //make it readable
}
The G formula was copied from another post in this forum and it is giving me the following results:
Calibrating MMA7361011..................................................
DONE
x: 0 y: -8 z: 101 G10^-2 -> 0.13
x: 0 y: -5 z: 97 G10^-2 -> 0.01
x: 0 y: -6 z: 100 G10^-2 -> 0.11
x: 0 y: -4 z: 97 G10^-2 -> 0.00
x: 1 y: -6 z: 100 G10^-2 -> 0.12
x: 0 y: -4 z: 97 G10^-2 -> -0.00
x: 1 y: -8 z: 99 G10^-2 -> 0.12
x: -1 y: -5 z: 96 G10^-2 -> 0.00
x: 1 y: -9 z: 99 G10^-2 -> 0.12
x: -3 y: -7 z: 98 G10^-2
Then I flip the accelerometer, put it on a table without any movement and the last column gives-me high values:
x: 115 y: 592 z: 5 G10^-2 -> 0.34
x: 118 y: 600 z: 10 G10^-2 -> 0.46
x: 107 y: 601 z: 7 G10^-2 -> 0.34
x: 103 y: 604 z: 8 G10^-2 -> 0.46
x: 103 y: 606 z: 7 G10^-2 -> 0.34
x: 104 y: 609 z: 11 G10^-2 -> 0.47
x: 105 y: 609 z: 8 G10^-2 -> 0.34
x: 105 y: 607 z: 10 G10^-2 -> 0.47
x: 98 y: 610 z: 8 G10^-2 -> 0.33
x: 105 y: 615 z: 8 G10^-2 -> 0.48
x: 95 y: 614 z: 9 G10^-2 -> 0.33
x: 96 y: 613 z: 8 G10^-2 -> 0.47
Obviously I'm not calculating this correctly, the question is, how can I do it?