I'm able to run the basic sketch for AXDL345, However, I noticed that the sketch freezes up after the first movement.
I tried to simplify the sketch to just monitor for activity and inactivity.
As you can see from the Serial Monitor display...
Port open
inactivity
inactivity
activity
activity
activity
activity
activity
activity
activity
activity
activity
activity
activity
activity
activity
activity
activi
The last printout is not even completed. Then nothing comes after.
//Arduino 1.0+ Only!
//Arduino 1.0+ Only!
#include <Wire.h>
#include <ADXL345.h>
ADXL345 adxl; //variable adxl is an instance of the ADXL345 library
void setup(){
Wire.begin();
Serial.begin(9600);
adxl.powerOn();
//set activity/ inactivity thresholds (0-255)
adxl.setActivityThreshold(75); //62.5mg per increment
adxl.setInactivityThreshold(75); //62.5mg per increment
adxl.setTimeInactivity(10); // how many seconds of no activity is inactive?
//look of activity movement on this axes - 1 == on; 0 == off
adxl.setActivityX(1);
adxl.setActivityY(1);
adxl.setActivityZ(1);
//look of inactivity movement on this axes - 1 == on; 0 == off
adxl.setInactivityX(1);
adxl.setInactivityY(1);
adxl.setInactivityZ(1);
//setting all interupts to take place on int pin 1
adxl.setInterruptMapping( ADXL345_INT_ACTIVITY_BIT, ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_INACTIVITY_BIT, ADXL345_INT1_PIN );
//register interupt actions - 1 == on; 0 == off
adxl.setInterrupt( ADXL345_INT_ACTIVITY_BIT, 1);
adxl.setInterrupt( ADXL345_INT_INACTIVITY_BIT, 1);
}
void loop(){
int x,y,z;
adxl.readAccel(&x, &y, &z); //read the accelerometer values and store them in variables x,y,z
byte interrupts = adxl.getInterruptSource();
//inactivity
if(adxl.triggered(interrupts, ADXL345_INACTIVITY)){
Serial.println("inactivity");
//add code here to do when inactivity is sensed
}
//activity
if(adxl.triggered(interrupts, ADXL345_ACTIVITY)){
Serial.println("activity");
//add code here to do when activity is sensed
}
}
Why is it freezing?