I'm trying this prodject with Arduino UNO and ADXL345,
The problem is that i get this read out in seriell monitor:
Reset
3.72 -0.10 -0.23 Reset
Reset time
Reset
Reset time
Reset
Reset time
Reset
-8.12 0.10 0.35 Reset
2.83 -0.10 -0.94 Reset
Reset time
I'm only interested in getting the jump height displayed in meters is this possibel with this code?
/* ============================================
Uses I2Cdev device library : http://www.i2cdevlib.com
*/
// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#include "Wire.h"
// I2Cdev and ADXL345 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include "I2Cdev.h"
#include "ADXL345.h"
// Declare objects
ADXL345 accel;
// Defines
#define G_MS2 9.80665
void setup() {
// join I2C bus (I2Cdev library doesn't do this automatically)
Wire.begin();
Serial.begin( 115200 );
// Initialize device and setup
Serial.println( "Initializing I2C devices..." );
accel.initialize();
accel.setRate( ADXL345_RATE_200 );
accel.setRange( ADXL345_RANGE_2G );
// verify connection
Serial.println( "Testing device connections..." );
Serial.println( accel.testConnection() ? "ADXL345 connection successful" : "ADXL345 connection failed" );
}
void loop() {
// Variables declaration
float ax, ay, az, speedZOld, speedZThreshold, speedZ, positionZ, speedDelta;
unsigned long timerAccumulation, timerSerial; // the timer
unsigned long INTERVAL = 5; // the repeat interval
unsigned long INTERVAL_SERIAL = 2000;
unsigned long i;
speedZOld = 0;
speedZ = 0;
positionZ = 0;
speedDelta = 0;
speedZThreshold = 0.1;
// Start timers
timerAccumulation = millis();
timerSerial = timerAccumulation;
Serial.println( "\t\tStarting main loop" );
while (1) {
// Compute data
i = millis()-timerAccumulation;
if ( i > INTERVAL ) {
timerAccumulation += INTERVAL; // Reset timer
az = accel.getAccelerationZ();
az = (az-231) * G_MS2 / 256.0; // Convertion to m/s2
speedZ += az * i/1e3; // Integration to get speed
// distance moved in deltaTime, s = 1/2 a t^2 + vt
double sz = 0.5 * az * i * i/1e6 + speedZ * i/1e3;
positionZ += sz;
}
if ( abs( speedZ ) < speedZThreshold ) { // If speed is behind given threshold, discard it to avoid noise accumulation
if ( abs( speedZOld ) > speedZThreshold ) { // If previous speed was high, it was moving
if ( abs( positionZ ) > 0.15 ) { // If we moved more than 0.15 cm, display it
Serial.print( az ); Serial.print( "\t" );
Serial.print( speedZ ); Serial.print( "\t" );
Serial.print( positionZ );
}
positionZ = 0;
speedZ = 0;
Serial.println( "\tReset" );
}
}
speedZOld = speedZ;
if ( (millis()-timerSerial) > INTERVAL_SERIAL ) { // Periodic reset to clear values from noise
Serial.println( "\tReset time" );
timerSerial += INTERVAL_SERIAL;
positionZ = 0;
speedZ = 0;
}
}
}
Please Help.