Goal: Trigger LED_X (high) as soon as X motion is detected, stay high until X motion stops
Having an issues setting the Threshold and debounce
Product FRDM-STBI-A8974 Shield connected to Arduino Uno (3.3v) FXLS8974CF, 3-Axis Low-g Accelerometer, data sheet
Using FXLS89xx_Arduino Lib FXLS89xx_Arduino/README.md at main · ryraki/FXLS89xx_Arduino · GitHub
What I see on serial:
WHO_AM_I = 0x86
19
19
E0
0x86 - Good
19, 19, E0 I believe is an error kicked out from the lib, I'm not sending that info to the Serial.
I'm not getting the correct info back on the src variable. I'm not sure what I am missing.
If I change to the Z axes, the LED stays high, if I switch to the Y axes the LED will blink every now and then, the _XYZ the LED flickers ON/OFF really fast but _X__ gives me nothing. I'm sure I'm not initializing something properly. Any kick in the right direction would be great.
Code:
#include "FXLS89xx_Arduino.h"
#include <Wire.h>
#define FXLS8974CF_ADDR 0x18
FXLS89xx fxls89xx;
int LED_X = 8;
int INT1_PIN = 2;
void setup()
{
pinMode(LED_X, OUTPUT);
pinMode(INT1_PIN, INPUT);
Serial.begin(115200);
Wire.begin();
uint8_t whoami = fxls89xx.init();
Serial.print("WHO_AM_I = 0x");
Serial.println(whoami, HEX);
fxls89xx.wake_odr = FXLS89xx::_6_25HZ;
fxls89xx.wake_pm = FXLS89xx::_HPM;
fxls89xx.sensor_range = FXLS89xx::_2G;
// Absolute mode, X-axis, ±25 mg thresholds, debounce=5 samples
fxls89xx.sdcd(FXLS89xx::_ABSOLUTE, FXLS89xx::_X__, 25.0f, 25.0f, 5);
}
void loop()
{
// Poll INT1 pin
if (digitalRead(INT1_PIN))
{
uint8_t src=fxls89xx.reg_r(FXLS89xx::_SDCD_INT_SRC1);
//Serial.println(src);
if (src & 0x01)
{
digitalWrite(LED_X, HIGH);
Serial.println("Motion detected on X-axis!");
}
if (src & 0x08)
{
digitalWrite(LED_X, LOW);
Serial.println("Motion ended on X-axis.");
}
}
delay(50);
}