Hi, I have been trying to run the FIFO example provided by this library along with the attachInterrupt() function provided by Arduino. The Fifo code on its own runs very well, but it doesn't actually change the state of the pin INT1 on the ADXL345 -> D3 on the Arduino Pro Mini. It always remains HIGH.
Here's my code:
#include <Wire.h>
#include <ADXL345.h>
#include <LowPower.h>
ADXL345 adxl;
const byte interruptPin = 3;
void setup() {
Serial.begin(115200);
// put your setup code here, to run once:
adxl.powerOn();
adxl.setLowPower(1);
//look of activity movement on this axes - 1 == on; 0 == off
adxl.setActivityX(1);
adxl.setActivityY(1);
adxl.setActivityZ(1);
//setting all interrupts to take place on int pin 1
adxl.setInterruptMapping(ADXL345_INT_WATERMARK_BIT, ADXL345_INT1_PIN);
//register interrupt actions - 1 == on; 0 == off
adxl.setInterrupt( ADXL345_INT_DATA_READY_BIT, 0 );
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);
adxl.setInterrupt( ADXL345_INT_WATERMARK_BIT, 1);
//setting lowest sampling rate
adxl.setRate(12.5);
//setting device into FIFO mode
adxl.setMode(ADXL345_MODE_FIFO);
//set watermark for Watermark interrupt
adxl.setWatermark(25);
}
void wakeUp()
{
Serial.println("I just woke up...");
}
void loop() {
// put your main code here, to run repeatedly:
adxl.getInterruptSource(); // reading interrupt status flags
Serial.println("Going to sleep...");
attachInterrupt(digitalPinToInterrupt(interruptPin), wakeUp, CHANGE);
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
detachInterrupt(digitalPinToInterrupt(interruptPin));
int x[25], y[25], z[25];
byte fifoentries, intEvent;
fifoentries = adxl.getFifoEntries();
intEvent = adxl.getInterruptSource(); // reading interrupt status flags
if (adxl.triggered(intEvent, ADXL345_WATERMARK) ) // if watermark interrupt occured
{
Serial.println("Watermark interrupt triggered. Fetching data now." );
if (fifoentries != 0) {
// burst read will cause the fifo to empty
adxl.burstReadXYZ(&x[0], &y[0], &z[0], fifoentries); // reading all samples of FIFO
for (int i = 0; i < fifoentries; i = i + 5) //Printing only every 5th sample to prevent spam on console
{
Serial.print("FIFO data sample: ");
Serial.print(i);
Serial.print(", x: ");
Serial.print(x[i]);
Serial.print(", y: ");
Serial.print(y[i]);
Serial.print(", z: ");
Serial.println(z[i]);
}
}
}
}
I have tried to read the value of D3 using digitalRead(3) at various points in the loop and it always returns HIGH, shouldn't it be LOW when the program starts and then switch to HIGH once the watermark interrupt is set, then go back to LOW when the FIFO buffer is cleared?
Hi, I have been trying to run the FIFO example provided by this library along with the attachInterrupt() function provided by Arduino. The Fifo code on its own runs very well, but it doesn't actually change the state of the pin INT1 on the ADXL345 -> D3 on the Arduino Pro Mini. It always remains HIGH.
Here's my code:
I have tried to read the value of D3 using digitalRead(3) at various points in the loop and it always returns HIGH, shouldn't it be LOW when the program starts and then switch to HIGH once the watermark interrupt is set, then go back to LOW when the FIFO buffer is cleared?