FXLS8974CF, FXLS8974_Arduino Lib and how to set thresholds and debounce values

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FXLS8974CF, FXLS8974_Arduino Lib and how to set thresholds and debounce values

65 Views
YellowJacket
Fresh Out Contributor

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); 
}
0 Kudos
Reply
0 Replies
%3CLINGO-SUB%20id%3D%22lingo-sub-2261807%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EFXLS8974CF%2C%20FXLS8974_Arduino%20Lib%20and%20how%20to%20set%20thresholds%20and%20debounce%20values%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2261807%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EGoal%3A%20Trigger%20LED_X%20(high)%20as%20soon%20as%20X%20motion%20is%20detected%2C%20stay%20high%20until%20X%20motion%20stops%26nbsp%3B%3C%2FP%3E%3CP%3EHaving%20an%20issues%20setting%20the%20Threshold%20and%20debounce%3C%2FP%3E%3CP%3EProduct%20FRDM-STBI-A8974%20Shield%20connected%20to%20Arduino%20Uno%20(3.3v)%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fwww.nxp.com%2Fdocs%2Fen%2Fdata-sheet%2FFXLS8974CF.pdf%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EFXLS8974CF%2C%203-Axis%20Low-g%20Accelerometer%2C%20data%20sheet%3C%2FA%3E%3C%2FP%3E%3CP%3EUsing%20FXLS89xx_Arduino%20Lib%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fryraki%2FFXLS89xx_Arduino%2Fblob%2Fmain%2FREADME.md%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EFXLS89xx_Arduino%2FREADME.md%20at%20main%20%C2%B7%20ryraki%2FFXLS89xx_Arduino%20%C2%B7%20GitHub%3C%2FA%3E%3C%2FP%3E%3CP%3EWhat%20I%20see%20on%20serial%3A%3C%2FP%3E%3CP%3EWHO_AM_I%20%3D%200x86%3C%2FP%3E%3CP%3E19%3C%2FP%3E%3CP%3E19%3C%2FP%3E%3CP%3EE0%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E0x86%20-%20Good%3C%2FP%3E%3CP%3E19%2C%2019%2C%20E0%20I%20believe%20is%20an%20error%20kicked%20out%20from%20the%20lib%2C%20I'm%20not%20sending%20that%20info%20to%20the%20Serial.%3C%2FP%3E%3CP%3EI'm%20not%20getting%20the%20correct%20info%20back%20on%20the%20src%20variable.%20I'm%20not%20sure%20what%20I%20am%20missing.%3C%2FP%3E%3CP%3EIf%20I%20change%20to%20the%20Z%20axes%2C%20the%20LED%20stays%20high%2C%20if%20I%20switch%20to%20the%20Y%20axes%20the%20LED%20will%20blink%20every%20now%20and%20then%2C%20the%20_XYZ%20the%20LED%20flickers%20ON%2FOFF%20really%20fast%20but%20_X__%20gives%20me%20nothing.%20I'm%20sure%20I'm%20not%20initializing%20something%20properly.%20Any%20kick%20in%20the%20right%20direction%20would%20be%20great.%3C%2FP%3E%3CP%3ECode%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-cpp%22%3E%3CCODE%3E%23include%20%22FXLS89xx_Arduino.h%22%0A%23include%20%3CWIRE.H%3E%0A%0A%23define%20FXLS8974CF_ADDR%200x18%0AFXLS89xx%20fxls89xx%3B%0A%0Aint%20LED_X%20%3D%208%3B%0Aint%20INT1_PIN%20%3D%202%3B%0A%0Avoid%20setup()%20%0A%7B%0A%20%20pinMode(LED_X%2C%20OUTPUT)%3B%0A%20%20pinMode(INT1_PIN%2C%20INPUT)%3B%0A%0A%20%20Serial.begin(115200)%3B%0A%20%20Wire.begin()%3B%0A%0A%20%20uint8_t%20whoami%20%3D%20fxls89xx.init()%3B%0A%20%20Serial.print(%22WHO_AM_I%20%3D%200x%22)%3B%0A%20%20Serial.println(whoami%2C%20HEX)%3B%0A%0A%20%20fxls89xx.wake_odr%20%3D%20FXLS89xx%3A%3A_6_25HZ%3B%0A%20%20fxls89xx.wake_pm%20%20%3D%20FXLS89xx%3A%3A_HPM%3B%0A%20%20fxls89xx.sensor_range%20%3D%20FXLS89xx%3A%3A_2G%3B%0A%20%20%0A%20%20%0A%20%20%2F%2F%20Absolute%20mode%2C%20X-axis%2C%20%C2%B125%20mg%20thresholds%2C%20debounce%3D5%20samples%0A%20%20fxls89xx.sdcd(FXLS89xx%3A%3A_ABSOLUTE%2C%20FXLS89xx%3A%3A_X__%2C%2025.0f%2C%2025.0f%2C%205)%3B%0A%7D%0A%0Avoid%20loop()%0A%7B%0A%20%20%2F%2F%20Poll%20INT1%20pin%0A%20%20if%20(digitalRead(INT1_PIN))%0A%20%20%7B%0A%20%20%20%20uint8_t%20src%3Dfxls89xx.reg_r(FXLS89xx%3A%3A_SDCD_INT_SRC1)%3B%0A%20%20%20%20%2F%2FSerial.println(src)%3B%0A%20%20%20%20if%20(src%20%26amp%3B%200x01)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20digitalWrite(LED_X%2C%20HIGH)%3B%0A%20%20%20%20%20%20Serial.println(%22Motion%20detected%20on%20X-axis!%22)%3B%0A%20%20%20%20%7D%0A%20%20if%20(src%20%26amp%3B%200x08)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20digitalWrite(LED_X%2C%20LOW)%3B%0A%20%20%20%20%20%20Serial.println(%22Motion%20ended%20on%20X-axis.%22)%3B%0A%20%20%20%20%7D%0A%20%20%7D%0A%20%20%20delay(50)%3B%20%0A%7D%3C%2FWIRE.H%3E%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E