Hello. I am trying to get the speed of a car from an accelerometer mounted in it . I will use the formula vf=vi +/- at to calculate the speed from acceleration. (vf is the speed at this moment,vi is the initial speed or the last vf read, a is the acceleration and t is the time between 2 readings). The problem is the that i don't know how to interpreter the readings. In I2C the mma7455 will work in 8 or 10 bits? Will it be the g force that i selected /256(in 8 bit mode) or /1024 ( in 10 bit mode). Is 8 g equal to 80 m/s?
#include <Wire.h> //Include the Wire library
#include <MMA_7455.h> //Include the MMA_7455 library
#define calibratecicles 1000
MMA_7455 mySensor = MMA_7455(); //Make an instance of MMA_7455
char xVal, yVal, zVal; //Variables for the values from the sensor
void calibrate()
{
float calx=0,caly=0,calz=0;
for(int i=0;i<calibratecicles;i++)
{
xVal = mySensor.readAxis('x'); //Read out the 'x' Axis
yVal = mySensor.readAxis('y'); //Read out the 'y' Axis
zVal = mySensor.readAxis('z'); //Read out the 'z' Axis
calx=calx + float(xVal);
caly =caly + float(yVal);
calz=calz + float(zVal);
}
calx=calx/calibratecicles;
caly=caly/calibratecicles;
calz=calz/calibratecicles;
/*if(calz>0)
{calz=calz*(-1);
}
else
{
calz=abs(calz);
}
*/
mySensor.calibrateOffset(abs(calx),abs(caly),0);
}
void setup()
{
Serial.begin(9600);
// Set the sensitivity you want to use
// 2 = 2g, 4 = 4g, 8 = 8g
mySensor.initSensitivity(8);
// Calibrate the Offset, that values corespond in
// flat position to: xVal = -30, yVal = -20, zVal = +20
// !!!Activate this after having the first values read out!!!
//mySensor.calibrateOffset(5, 20, -68);
calibrate();
}
void loop()
{
xVal = mySensor.readAxis('x'); //Read out the 'x' Axis
yVal = mySensor.readAxis('y'); //Read out the 'y' Axis
zVal = mySensor.readAxis('z'); //Read out the 'z' Axis
Serial.print(xVal, DEC);
Serial.print("\t");
Serial.print(yVal, DEC);
Serial.print("\t");
Serial.println(zVal, DEC);
}