Hey guys,
I hope you can help me solving the subjects problem.
The Sensor is configured to do an interrupt to wake up the arduino --> set pin to HIGH until interrupt is cleard. The last interrupt is cleard and new started right before going to sleep, but if there is a new interrupt while dropping off, the arduino won't come back anytime.
Is there a solution to get around this?
#include <Wire.h>
#include <ADXL345.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
ADXL345 adxl; //variable adxl is an instance of the ADXL345 library
void setup(){
Serial.begin(115200);
pinMode(13, OUTPUT);
pinMode(2, INPUT); // Make digital 2 an input
//set up sensor
adxl.powerOn();
//set activity/ inactivity thresholds (0-255)
adxl.setActivityThreshold(20); //62.5mg per increment
adxl.setInactivityThreshold(20); //62.5mg per increment
adxl.setTimeInactivity(10); // how many seconds of no activity is inactive?
adxl.setDoubleTapLatency(80); //1.25ms per increment
adxl.setDoubleTapWindow(200); //1.25ms per increment
//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);
//look of tap movement on this axes - 1 == on; 0 == off
adxl.setTapDetectionOnX(1);
adxl.setTapDetectionOnY(1);
adxl.setTapDetectionOnZ(1);
//set values for what is a tap, and what is a double tap (0-255)
adxl.setTapThreshold(20); //62.5mg per increment
adxl.setTapDuration(200); //625?s per increment
//set values for what is considered freefall (0-255)
adxl.setFreeFallThreshold(7); //(5 - 9) recommended - 62.5mg per increment
adxl.setFreeFallDuration(45); //(20 - 70) recommended - 5ms per increment
//setting all interupts to take place on int pin 1
//I had issues with int pin 2, was unable to reset it
adxl.setInterruptMapping( ADXL345_INT_SINGLE_TAP_BIT, ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_FREE_FALL_BIT, ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_ACTIVITY_BIT, ADXL345_INT1_PIN );
//register interupt actions - 1 == on; 0 == off
adxl.setInterrupt( ADXL345_INT_SINGLE_TAP_BIT, 0);
adxl.setInterrupt( ADXL345_INT_DOUBLE_TAP_BIT, 0);
adxl.setInterrupt( ADXL345_INT_FREE_FALL_BIT, 0);
adxl.setInterrupt( ADXL345_INT_ACTIVITY_BIT, 0);
adxl.setInterrupt( ADXL345_INT_INACTIVITY_BIT, 0);
}
void sleepNow() // here we put the arduino to sleep
{
Serial.println("off");
digitalWrite(13,LOW);
delay(100);
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
sleep_enable();
attachInterrupt(0, wakeUp, CHANGE);
byte interrupts = adxl.getInterruptSource(); //read and clear interrupt
//start sensor doing interrupts
adxl.setInterrupt( ADXL345_INT_SINGLE_TAP_BIT, 1);
adxl.setInterrupt( ADXL345_INT_DOUBLE_TAP_BIT, 1);
adxl.setInterrupt( ADXL345_INT_FREE_FALL_BIT, 1);
adxl.setInterrupt( ADXL345_INT_ACTIVITY_BIT, 1);
sleep_mode();
sleep_disable(); // first thing after waking from sleep:
detachInterrupt(0);
}
void wakeUp()
{
}
void loop(){
//going to sleep
sleepNow();
Serial.println("on");
digitalWrite(13,HIGH);
// stop sensor-interrupt
adxl.setInterrupt( ADXL345_INT_SINGLE_TAP_BIT, 0);
adxl.setInterrupt( ADXL345_INT_DOUBLE_TAP_BIT, 0);
adxl.setInterrupt( ADXL345_INT_FREE_FALL_BIT, 0);
adxl.setInterrupt( ADXL345_INT_ACTIVITY_BIT, 0);
adxl.setInterrupt( ADXL345_INT_INACTIVITY_BIT, 0);
//DOING STUFF HERE
}
Best gegards
Eicca