It is driving me crazy for a week now.... ![]()
I am trying to read ADXL345 only when activated interrupt is sent. All the remaining time my arduino needs to spend sleeping.
But.. it's working only for a few moments and only after complete power down prior to test - i need to literally unplug it to reset everything. Like ADXL stops dead. After a few moments of working.
I do not know how to solve that. It's working ok if i remove the sleep command.
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
#include <LowPower.h>
#include <SparkFun_ADXL345.h> // SparkFun ADXL345 Library
/*********** COMMUNICATION SELECTION ***********/
/* Comment Out The One You Are Not Using */
//ADXL345 adxl = ADXL345(10); // USE FOR SPI COMMUNICATION, ADXL345(CS_PIN);
ADXL345 adxl = ADXL345(); // USE FOR I2C COMMUNICATION
boolean volatile intADXL = false;
double roll;
double pitch;
double xyz[3];
/****************** INTERRUPT ******************/
/* Uncomment If Attaching Interrupt */
int interruptPin = 3; // Setup pin 2 to be the interrupt pin (for most Arduino Boards)
/******************** SETUP ********************/
/* Configure ADXL345 Settings */
void setupADXL() {
pinMode(interruptPin, INPUT);
attachInterrupt(digitalPinToInterrupt(interruptPin), ADXL_ISR, RISING); // Attach Interrupt
adxl.powerOn(); // Power on the ADXL345
adxl.setRangeSetting(4); // Give the range settings
adxl.setRate(100);
adxl.setInterruptLevelBit(0);
adxl.setNoFifo(); //custom - disable FIFO - bypass mode
adxl.setActivityXYZ(1, 1, 1); // Set to activate movement detection in the axes "adxl.setActivityXYZ(X, Y, Z);" (1 == ON, 0 == OFF)
adxl.setActivityThreshold(17); // 62.5mg per increment // Set activity // Inactivity thresholds (0-255)
adxl.setImportantInterruptMapping(2, 2, 2, 1, 2); // Sets "adxl.setEveryInterruptMapping(single tap, double tap, free fall, activity, inactivity);"
adxl.InactivityINT(0);
adxl.ActivityINT(1);
adxl.FreeFallINT(0);
adxl.doubleTapINT(0);
adxl.singleTapINT(0);
}
void setup() {
Serial.begin(9600); // Start the serial terminal
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
bb();
setupADXL();
}
void loop() {
roll = (atan2(-xyz[1], xyz[2]) * 180.0) / M_PI;
pitch = (atan2(xyz[0], sqrt(xyz[1] * xyz[1] + xyz[2] * xyz[2])) * 180.0) / M_PI;
Serial.print ("Roll = " + (String)roll); Serial.println (" |Pitch = " + (String)pitch);
if (!intADXL) {
Serial.println ("powering down");
delay (500);
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
}
if (intADXL)
{
intADXL = false;
byte interrupts = 0;
interrupts = adxl.getInterruptSource();
//Activity
if (adxl.triggered(interrupts, ADXL345_ACTIVITY)) {
Serial.println("*** ACTIVITY ***");
bb();
adxl.get_Gxyz(xyz);
}
}
}
void bb() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(10); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
}
void ADXL_ISR() {
intADXL = true;
}