LIS2DH12 as movement sensor when the device can be oriented in any way, not just flat/parallel
I would like LIS2DH12 to fire Interrupt1 (to wake up the microcontroller) when the device is slightly moved. I have it working if the device/LIS2DH12 is laying flat parallel to the ground, moving it slightly fires the Interrupt. However, if the device the laying at a angle like 30 degrees, moving it slightly does not fire the Interrupt1. Is this not supported or somehow I need to specify the "rest state" so the movement can be compare to it? I am using Arduino IDE.
One example of code is attached below that only works if the device is laying flat initially. I have tried other examples with same results. I am not tied to a particular library. Please provide some arduino code that work!
#include <Wire.h>
#include "SparkFun_LIS2DH12.h"
SPARKFUN_LIS2DH12 accel;
int accelInterruptPin = 27;
void setup()
{
Serial.begin(115200);
delay(500);
Serial.println("SparkFun Accel Example");
Wire.begin();
if (!accel.begin())
{
Serial.println("Accelerometer not detected. Check address jumper and wiring. Freezing...");
while (1);
}
pinMode(accelInterruptPin, INPUT_PULLUP);
accel.setDataRate(LIS2DH12_POWER_DOWN); //Stop measurements
// Set INT_POLARITY to Active Low
accel.setIntPolarity(LOW);
// Set INT1 interrupt
accel.setInt1IA1(true);
// Set INT1 threshold and duration for any movement detection
accel.setInt1Threshold(6); // Set threshold to the smallest value for any movement
accel.setInt1Duration(9); // Set a duration to filter out noise
// Clear the interrupt
while (accel.getInt1()) delay(10); // Reading int will clear it
// Set data rate and enable interrupts
accel.setDataRate(LIS2DH12_ODR_400Hz);
accel.setInt1(true); // Enable interrupts on INT1 pin
Serial.println("Begin Interrupt Scanning");
Serial.println("Detecting any movement...");
}
void loop()
{
// Poll for the interrupt via I2C just for testing purposes
if (accel.getInt1() == true) // Reading int will clear it
{
Serial.print(millis());
Serial.println(" Movement Detected!");
}
delay(100);
}
