Xiao nRF52840 Sense IMU Parked demo With SLEEP Interrupt button

PARK_IMU_DEMO

Displays Parked message after NO movement(6 seconds) from Gyro or Accelerometer over (sensitivity settings) Displays orientation.
Push button on the Xiao expansion board fires Interrupt from pin state and continuously check if the IMU orientation deviates from its parked orientation, or if motion is present
and takes action if necessary, beep & Display orientation.
It goes to sleep after three(3) button presses and will wake up on double tap.(or another button press)
Sleep doesn’t work with BSP 2.9.2 as posted it breaks something. (NOTE:tested and working AOK with 2.9.0 & 2.9.1)
This covers several topics, adding BLE is also possible.
Polling IMU, Interrupts from IMU (double tap), Display, IO, Sleep.
HTH
GL :slight_smile: PJ

//poatched and toasted by pjg
/*******************************************************************************/
// PARK_IMU_DEMO
// Displays Parked message after NO movement(6 seconds) from Gyro or Accelerometer over (sensitivity settings)
//
// Push button on Xiao expansion board fires Interrupt from pin state
// continuously check if the IMU orientation deviates from its parked orientation or if motion is present
// and take action if necessary, beep & Display orientation.
// 
// go to sleep after three(3) button presses.
// wake up on double tap.(or another button press)
//
// Sleep doesn't work with BSP 2.9.2 as posted it breaks something. (NOTE:tested and working with 2.9.0 & 2.9.1)
//
/*******************************************************************************/
#include <LSM6DS3.h>
#include <Wire.h>
#include <U8x8lib.h>
// create an instance of the LSM6DS3 class
LSM6DS3 myIMU(I2C_MODE, 0x6A); // IMU
#define int2Pin PIN_LSM6DS3TR_C_INT1

U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* clock=*/ PIN_WIRE_SCL, /* data=*/ PIN_WIRE_SDA, /* reset=*/ U8X8_PIN_NONE);
 // OLEDs without Reset of the Display
float aX, aY, aZ, gX, gY, gZ;
const int buttonPin = 1;     // the number of the pushbutton pin
int buttonState = 0;// variable for reading the pushbutton status
uint8_t binterruptCount = 0; // Amount of received interrupts
uint8_t oldState = 0;         // variable for previous reading
int movedPos = LOW;
int BuzzerPin = A3;
uint8_t interruptCount = 0; // Amount of received interrupts
uint8_t prevInterruptCount = 0; // Interrupt Counter from last loop
int accX, accY, accZ;
int parkedOrientationX, parkedOrientationY, parkedOrientationZ;
int buzzer = BuzzerPin;

unsigned long lastMovementTime = 0;
const unsigned long parkingDuration = 8000; // 6 seconds in milliseconds
const unsigned long parkSleep = 10000; // 6 seconds in milliseconds
const unsigned long movingDuration = 1000; // 1 second
bool isParked = false;

String imuOrientation = "";// was upright
String imutemperature = "";
int orientation = -1;                        // use -1 to indicate initial state
const int orientationUpdateInterval = 1000;  // update orientation every 5 seconds
unsigned long lastOrientationUpdate = 0;
unsigned long currentMillis = millis();

void setup() {    // Line 133
  Serial.begin(9600);
	   delay(2500);  //relax...Get Ready for serial port
   Serial.println();
   Serial.println();
   Serial.println("Power ON ");  // Let's BEGIN!!
   Serial.println(" Program " __FILE__ " compiled on " __DATE__ " at " __TIME__ );
   Serial.println();
   u8x8.begin();
   u8x8.setFlipMode(1);   // set number from 1 to 3, the screen word will rotary 180
    
   pinMode(LED_BUILTIN, OUTPUT);// initialize the LED pin as an output:
   pinMode(buttonPin, INPUT_PULLUP);// initialize the pushbutton pin as an input:
   attachInterrupt(digitalPinToInterrupt(buttonPin), myISR, FALLING);
   pinMode(int2Pin, INPUT);
   attachInterrupt(digitalPinToInterrupt(int2Pin), int1ISR, RISING);
   pinMode(BuzzerPin, OUTPUT);
   pinMode(LEDR, OUTPUT);
   pinMode(LEDG, OUTPUT);
   pinMode(LEDB, OUTPUT);
   startsound();       //Beep Buzzer speaker on A3
   setupblink();
   
 myIMU.settings.gyroEnabled = 1; // Gyro ON. 
   if (myIMU.begin() != 0) {
        Serial.println("IMU error");
    } else {
        Serial.println("IMU OK!");
    }
    
    u8x8.setFont(u8x8_font_8x13B_1x2_r);
    u8x8.clearDisplay();
    u8x8.setCursor(0, 1);
    u8x8.print(" Parked Demo");
    //delay(2000);
    getPosition();
}

void loop() {
  // continuously check if the IMU orientation deviates from its parked orientation
  // and take action if necessary
  // if interrupt was received in this cycle
    if (binterruptCount > prevInterruptCount) {
      Serial.println("\n Button Interrupt received!");
      setLedRGB(false, true, false); // set green only
    }
    
    prevInterruptCount = binterruptCount;
    
    if (binterruptCount >= 3) {
      // Trigger System OFF after 3 interrupts
      goToPowerOff();
    }
    
    delay(500);
    // Read accelerometer and gyroscope data
  float accX = myIMU.readFloatAccelX();
  float accY = myIMU.readFloatAccelY();
  float accZ = myIMU.readFloatAccelZ();
  float gyroX = myIMU.readFloatGyroX();
  float gyroY = myIMU.readFloatGyroY();
  float gyroZ = myIMU.readFloatGyroZ();
  // Calculate motion magnitude (you can adjust the threshold as needed)
  // Calculate motion magnitude based on accelerometer data
  float motionMagnitude = sqrt(accX * accX + accY * accY + accZ * accZ);

  // Calculate gyro motion magnitude based on gyroscope data (you can adjust the threshold as needed)
  float gyroMotionMagnitude = sqrt(gyroX * gyroX + gyroY * gyroY + gyroZ * gyroZ);
  //setLedRGB(false, false, false);  // Turn off any LED 's OFF
 // Check if there is motion (based on accelerometer or gyro data)
  if (motionMagnitude > 1.04 || gyroMotionMagnitude > 99.5) {
    // Reset the timer and update the parked state
    lastMovementTime = millis();
    isParked = false;
    // Check if the timer has elapsed (30 seconds)
    //if (millis() - lastMovementTime >= movingDuration) {
    // Handle the case where motion is detected (e.g., print or take action)
    setLedRGB(true, false, false);  // RED
    Serial.println("Motion detected");
    u8x8.clearDisplay();
    u8x8.setCursor(0, 1);
    u8x8.print("MOTION");
      tone(buzzer, 800);
      delay(800);
      noTone(buzzer);
      delay(100);
    // Print the values that exceeded the threshold
    if (motionMagnitude > 1.04) {
      Serial.print("Accelerometer Magnitude: ");
      Serial.println(motionMagnitude);
      u8x8.setCursor(0, 3);
      u8x8.print("Accel ");
      u8x8.setCursor(6, 3);
      u8x8.print(motionMagnitude);
      delay(500);

    }
    if (gyroMotionMagnitude > 99.5) {
      Serial.print("Gyro Magnitude: ");
      Serial.println(gyroMotionMagnitude);
      u8x8.setCursor(0, 3);
      u8x8.print("Gyro ");
      u8x8.setCursor(6, 3);
      u8x8.print(gyroMotionMagnitude);
    }
     getOrientation();
    //getPosition();
    //}
 } else {
    
    // Check if the timer has elapsed (6 seconds)
    // if (millis() - lastMovementTime >= parkingDuration) {
    // Check if the timer has elapsed (10 seconds) and it's not already parked
    if (!isParked && millis() - lastMovementTime >= parkingDuration) {
      // The device is considered "Parked" after 6 seconds of no motion
      //Serial.println("Device is Parked");
      // Update the parked state flag
      isParked = true;
      setLedRGB(false, false, true); // set blue led
      Serial.println(" LSM6D3 Device is Parked" __DATE__ " at " __TIME__);
      // You can add any other actions you want for the "Parked" state here
      getOrientation();
      //u8x8.clearDisplay();
     u8x8.setCursor(0, 4);
     u8x8.print("P A R K E D !");
      //getPosition();
      }
      if (!isParked && millis() - lastMovementTime >= parkSleep) {
     u8x8.clearDisplay();
     u8x8.setCursor(2, 3);
     u8x8.print("S L E E P !");
        goToPowerOff();
    }

  }
  // Your other loop code here
}

//------------------------ ISR's --------------------//

void myISR() {        // Pressed Button Interrupt //
  binterruptCount++;
  buttonState = LOW;
  ;
}
void int1ISR() {      // Moved Interrupt changed //
  interruptCount++;
  movedPos = HIGH;
  ;
}


// -------------------- Utilities ------------------------- //
void setupDoubleTapInterrupt(bool enable) {
  //uint8_t error = 0;
  //uint8_t dataToWrite = 0;

  // Double Tap Config
  myIMU.writeRegister(LSM6DS3_ACC_GYRO_CTRL1_XL, 0x60);
  myIMU.writeRegister(LSM6DS3_ACC_GYRO_TAP_CFG1, 0x8E);
  myIMU.writeRegister(LSM6DS3_ACC_GYRO_TAP_THS_6D, 0x85);  // Changed the value to 0x01 for increased sensitivity was 85 Set tap threshold 8C,03 in demo
  //myIMU.writeRegister(LSM6DS3_ACC_GYRO_TAP_THS_6D, tapThreshold);
  myIMU.writeRegister(LSM6DS3_ACC_GYRO_INT_DUR2, 0x7F);  // Set Duration, Quiet and Shock time windows 7F
  myIMU.writeRegister(LSM6DS3_ACC_GYRO_WAKE_UP_THS, 0x80); // Single & double-tap enabled (SINGLE_DOUBLE_TAP = 1)
  if (enable) {
     Serial.println("Double Tap WakeUp ON!");
    myIMU.writeRegister(LSM6DS3_ACC_GYRO_MD1_CFG, 0x08);  // Enable the double-tap interrupt
  } else {
    myIMU.writeRegister(LSM6DS3_ACC_GYRO_MD1_CFG, 0x00);  // Disable the double-tap interrupt
    Serial.println("Double Tap OFF");
  }
}
void getOrientation() {
  // Check if it's time to update the orientation
  if (millis() - lastOrientationUpdate >= orientationUpdateInterval) {
    lastOrientationUpdate = millis();

    // read the acceleration data
    aX = myIMU.readFloatAccelX();
    aY = myIMU.readFloatAccelY();
    aZ = myIMU.readFloatAccelZ();

    // determine the orientation
    int newOrientation;
    if (abs(aX) > abs(aY) && abs(aX) > abs(aZ)) {
      newOrientation = (aX > 0) ? 1 : 0;
    } else if (abs(aY) > abs(aZ)) {
      newOrientation = (aY > 0) ? 2 : 3;
    } else {
      newOrientation = (aZ > 0) ? 4 : 5;
    }
     u8x8.clearDisplay();
     u8x8.setCursor(0, 1);
    // print the orientation if it changed
    if (newOrientation != orientation) {
      Serial.print("3D Position:-->");
      
      orientation = newOrientation;
      switch (orientation) {
        //Serial.println (orientation);
        case 0:
          Serial.println("Ass UP ");
          imuOrientation = ("Ass UP ");
          u8x8.print("Ass UP ");
          break;
        case 1:
        Serial.println("UPRIGHT");
          imuOrientation = ("UPRIGHT");
          u8x8.print("UPRIGHT");
          break;
        case 2:
          Serial.println("SIDEWAYS LEFT");
          imuOrientation = ("SIDEWAYS LEFT");
          u8x8.print("SIDEWAYS LEFT");
          break;
        case 3:
          Serial.println("SIDEWAYS RIGHT");
          imuOrientation = ("SIDEWAYS RIGHT ");
          u8x8.print("SIDEWAYS RIGHT");
          break;
        case 4:
          Serial.println("TOP UP");
          imuOrientation = ("TOP UP");
          u8x8.print("TOP UP");
          break;
        case 5:
          Serial.println("TOP DOWN");
          imuOrientation = ("TOP DOWN");
          u8x8.print("TOP DOWN");
          break;
      }
    }
    orientation = -1;  // use -1 to indicate initial state
  }
  //updateBatteryLevel(); Worked along time ago? but the BSP broke that too.
}
void getPosition(){
    //Accelerometer
    Serial.print("\nAccelerometer:\n");
    Serial.print(" X1 = ");
    Serial.println(myIMU.readFloatAccelX(), 4);
    Serial.print(" Y1 = ");
    Serial.println(myIMU.readFloatAccelY(), 4);
    Serial.print(" Z1 = ");
    Serial.println(myIMU.readFloatAccelZ(), 4);

    //Gyroscope
    Serial.print("\nGyroscope:\n");
    Serial.print(" X1 = ");
    Serial.println(myIMU.readFloatGyroX(), 4);
    Serial.print(" Y1 = ");
    Serial.println(myIMU.readFloatGyroY(), 4);
    Serial.print(" Z1 = ");
    Serial.println(myIMU.readFloatGyroZ(), 4);

    //Thermometer
    Serial.print("\nThermometer:\n");
    Serial.print(" Degrees C1 = ");
    Serial.println(myIMU.readTempC(), 4);
    Serial.print(" Degrees F1 = ");
    Serial.println(myIMU.readTempF(), 4);

    delay(500);
}



void startsound() {
  tone(buzzer, 890);
  delay(220);
  noTone(buzzer);
  delay(20);
  tone(buzzer, 800);
  delay(220);
  noTone(buzzer);
  delay(20);
  tone(buzzer, 990);
  delay(420);
  noTone(buzzer);
}

void setupblink() {

  setLedRGB(false, true, false);  // Red
  delay(1000);
  setLedRGB(true, false, false);  // Green
  delay(1000);
  setLedRGB(false, false, true);  // Blue
  delay(1000);
  setLedRGB(false, false, false);  // OFF
}

void setLedRGB(bool red, bool green, bool blue) {
  if (!blue) { digitalWrite(LEDB, HIGH); } else { digitalWrite(LEDB, LOW); }
  if (!green) { digitalWrite(LEDG, HIGH); } else { digitalWrite(LEDG, LOW); }
  if (!red) { digitalWrite(LEDR, HIGH); } else { digitalWrite(LEDR, LOW); }
}

// -------------------- System ------------------------- //
void goToPowerOff() {
  //sleepFlash();
  setLedRGB(false, false, false);
  setupDoubleTapInterrupt(true);  // not needed here, if already applied..
  delay(1000);                    // delay seems important to apply settings, before going to System OFF
   Serial.println("S L E E P !");
   u8x8.clearDisplay();
     u8x8.setCursor(2, 3);
     u8x8.print("S L E E P !");
  //Ensure interrupt pin from IMU is set to wake up device
  nrf_gpio_cfg_sense_input(digitalPinToInterrupt(int2Pin), NRF_GPIO_PIN_PULLDOWN, NRF_GPIO_PIN_SENSE_HIGH);
  delay(2000);               // delay seems important to apply settings, before going to System OFF
  NRF_POWER->SYSTEMOFF = 1;  // Trigger System OFF
}
///the end

Complier Output

FQBN: Seeeduino:mbed:xiaonRF52840Sense
Using board 'xiaonRF52840Sense' from platform in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1
Using core 'arduino' from platform in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1

Detecting libraries used...
C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\tools\arm-none-eabi-gcc\7-2017q4/bin/arm-none-eabi-g++ -c -w -g3 -nostdlib @C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE/defines.txt @C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE/cxxflags.txt -DARDUINO_ARCH_NRF52840 -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -w -x c++ -E -CC -DARDUINO=10607 -DARDUINO_SEEED_XIAO_NRF52840_SENSE -DARDUINO_ARCH_MBED -DARDUINO_ARCH_MBED -DARDUINO_LIBRARY_DISCOVERY_PHASE=1 -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino/api/deprecated -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino/api/deprecated-avr-comp -iprefixC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino @C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE/includes.txt C:\Users\Dude\AppData\Local\Temp\arduino\sketches\ABEBA9F6BA0EA428F3A91164B8980FE1\sketch\sketch_sep5a_PARK_IMU_copy_Posted.ino.cpp -o nul
Alternatives for LSM6DS3.h: [Seeed Arduino [email protected]]
ResolveLibrary(LSM6DS3.h)
  -> candidates: [Seeed Arduino [email protected]]
C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\tools\arm-none-eabi-gcc\7-2017q4/bin/arm-none-eabi-g++ -c -w -g3 -nostdlib @C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE/defines.txt @C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE/cxxflags.txt -DARDUINO_ARCH_NRF52840 -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -w -x c++ -E -CC -DARDUINO=10607 -DARDUINO_SEEED_XIAO_NRF52840_SENSE -DARDUINO_ARCH_MBED -DARDUINO_ARCH_MBED -DARDUINO_LIBRARY_DISCOVERY_PHASE=1 -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE -Id:\Arduino_projects\libraries\Seeed_Arduino_LSM6DS3 -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino/api/deprecated -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino/api/deprecated-avr-comp -iprefixC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino @C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE/includes.txt C:\Users\Dude\AppData\Local\Temp\arduino\sketches\ABEBA9F6BA0EA428F3A91164B8980FE1\sketch\sketch_sep5a_PARK_IMU_copy_Posted.ino.cpp -o nul
Alternatives for Wire.h: [Wire]
ResolveLibrary(Wire.h)
  -> candidates: [Wire]
C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\tools\arm-none-eabi-gcc\7-2017q4/bin/arm-none-eabi-g++ -c -w -g3 -nostdlib @C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE/defines.txt @C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE/cxxflags.txt -DARDUINO_ARCH_NRF52840 -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -w -x c++ -E -CC -DARDUINO=10607 -DARDUINO_SEEED_XIAO_NRF52840_SENSE -DARDUINO_ARCH_MBED -DARDUINO_ARCH_MBED -DARDUINO_LIBRARY_DISCOVERY_PHASE=1 -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE -Id:\Arduino_projects\libraries\Seeed_Arduino_LSM6DS3 -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\libraries\Wire -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino/api/deprecated -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino/api/deprecated-avr-comp -iprefixC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino @C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE/includes.txt C:\Users\Dude\AppData\Local\Temp\arduino\sketches\ABEBA9F6BA0EA428F3A91164B8980FE1\sketch\sketch_sep5a_PARK_IMU_copy_Posted.ino.cpp -o nul
Alternatives for U8x8lib.h: [[email protected]]
ResolveLibrary(U8x8lib.h)
  -> candidates: [[email protected]]
C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\tools\arm-none-eabi-gcc\7-2017q4/bin/arm-none-eabi-g++ -c -w -g3 -nostdlib @C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE/defines.txt @C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE/cxxflags.txt -DARDUINO_ARCH_NRF52840 -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -w -x c++ -E -CC -DARDUINO=10607 -DARDUINO_SEEED_XIAO_NRF52840_SENSE -DARDUINO_ARCH_MBED -DARDUINO_ARCH_MBED -DARDUINO_LIBRARY_DISCOVERY_PHASE=1 -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE -Id:\Arduino_projects\libraries\Seeed_Arduino_LSM6DS3 -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\libraries\Wire -Id:\Arduino_projects\libraries\U8g2\src -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino/api/deprecated -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino/api/deprecated-avr-comp -iprefixC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino @C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE/includes.txt C:\Users\Dude\AppData\Local\Temp\arduino\sketches\ABEBA9F6BA0EA428F3A91164B8980FE1\sketch\sketch_sep5a_PARK_IMU_copy_Posted.ino.cpp -o nul
C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\tools\arm-none-eabi-gcc\7-2017q4/bin/arm-none-eabi-g++ -c -w -g3 -nostdlib @C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE/defines.txt @C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE/cxxflags.txt -DARDUINO_ARCH_NRF52840 -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -w -x c++ -E -CC -DARDUINO=10607 -DARDUINO_SEEED_XIAO_NRF52840_SENSE -DARDUINO_ARCH_MBED -DARDUINO_ARCH_MBED -DARDUINO_LIBRARY_DISCOVERY_PHASE=1 -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE -Id:\Arduino_projects\libraries\Seeed_Arduino_LSM6DS3 -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\libraries\Wire -Id:\Arduino_projects\libraries\U8g2\src -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino/api/deprecated -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino/api/deprecated-avr-comp -iprefixC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino @C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE/includes.txt d:\Arduino_projects\libraries\Seeed_Arduino_LSM6DS3\LSM6DS3.cpp -o nul
Alternatives for SPI.h: [SPI]
ResolveLibrary(SPI.h)
  -> candidates: [SPI]
C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\tools\arm-none-eabi-gcc\7-2017q4/bin/arm-none-eabi-g++ -c -w -g3 -nostdlib @C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE/defines.txt @C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE/cxxflags.txt -DARDUINO_ARCH_NRF52840 -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -w -x c++ -E -CC -DARDUINO=10607 -DARDUINO_SEEED_XIAO_NRF52840_SENSE -DARDUINO_ARCH_MBED -DARDUINO_ARCH_MBED -DARDUINO_LIBRARY_DISCOVERY_PHASE=1 -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE -Id:\Arduino_projects\libraries\Seeed_Arduino_LSM6DS3 -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\libraries\Wire -Id:\Arduino_projects\libraries\U8g2\src -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\libraries\SPI -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino/api/deprecated -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino/api/deprecated-avr-comp -iprefixC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino @C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE/includes.txt d:\Arduino_projects\libraries\Seeed_Arduino_LSM6DS3\LSM6DS3.cpp -o nul
C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\tools\arm-none-eabi-gcc\7-2017q4/bin/arm-none-eabi-g++ -c -w -g3 -nostdlib @C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE/defines.txt @C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE/cxxflags.txt -DARDUINO_ARCH_NRF52840 -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -w -x c++ -E -CC -DARDUINO=10607 -DARDUINO_SEEED_XIAO_NRF52840_SENSE -DARDUINO_ARCH_MBED -DARDUINO_ARCH_MBED -DARDUINO_LIBRARY_DISCOVERY_PHASE=1 -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE -Id:\Arduino_projects\libraries\Seeed_Arduino_LSM6DS3 -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\libraries\Wire -Id:\Arduino_projects\libraries\U8g2\src -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\libraries\SPI -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino/api/deprecated -IC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino/api/deprecated-avr-comp -iprefixC:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\cores\arduino @C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\variants\SEEED_XIAO_NRF52840_SENSE/includes.txt C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\libraries\Wire\Wire.cpp -o nul

.....EDIT for Brevity.....
"C:\\Users\\Dude\\AppData\\Local\\Arduino15\\packages\\Seeeduino\\tools\\arm-none-eabi-gcc\\7-2017q4/bin/arm-none-eabi-objcopy" -O binary "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\ABEBA9F6BA0EA428F3A91164B8980FE1/sketch_sep5a_PARK_IMU_copy_Posted.ino.elf" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\ABEBA9F6BA0EA428F3A91164B8980FE1/sketch_sep5a_PARK_IMU_copy_Posted.ino.bin"
"C:\\Users\\Dude\\AppData\\Local\\Arduino15\\packages\\Seeeduino\\tools\\arm-none-eabi-gcc\\7-2017q4/bin/arm-none-eabi-objcopy" -O ihex -R .eeprom "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\ABEBA9F6BA0EA428F3A91164B8980FE1/sketch_sep5a_PARK_IMU_copy_Posted.ino.elf" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\ABEBA9F6BA0EA428F3A91164B8980FE1/sketch_sep5a_PARK_IMU_copy_Posted.ino.hex"
"C:\\Users\\Dude\\AppData\\Local\\Arduino15\\packages\\Seeeduino\\hardware\\mbed\\2.9.1/tools/adafruit-nrfutil/win32/adafruit-nrfutil.exe" dfu genpkg --dev-type 0x0052 --application "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\ABEBA9F6BA0EA428F3A91164B8980FE1/sketch_sep5a_PARK_IMU_copy_Posted.ino.hex" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\ABEBA9F6BA0EA428F3A91164B8980FE1/sketch_sep5a_PARK_IMU_copy_Posted.ino.zip"
Zip created at C:\Users\Dude\AppData\Local\Temp\arduino\sketches\ABEBA9F6BA0EA428F3A91164B8980FE1/sketch_sep5a_PARK_IMU_copy_Posted.ino.zip

Using library Seeed Arduino LSM6DS3 at version 2.0.3 in folder: D:\Arduino_projects\libraries\Seeed_Arduino_LSM6DS3 
Using library Wire in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\libraries\Wire (legacy)
Using library U8g2 at version 2.34.22 in folder: D:\Arduino_projects\libraries\U8g2 
Using library SPI in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.1\libraries\SPI (legacy)
"C:\\Users\\Dude\\AppData\\Local\\Arduino15\\packages\\Seeeduino\\tools\\arm-none-eabi-gcc\\7-2017q4/bin/arm-none-eabi-size" -A "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\ABEBA9F6BA0EA428F3A91164B8980FE1/sketch_sep5a_PARK_IMU_copy_Posted.ino.elf"
Sketch uses 106080 bytes (13%) of program storage space. Maximum is 811008 bytes.
Global variables use 46152 bytes (19%) of dynamic memory, leaving 191416 bytes for local variables. Maximum is 237568 bytes.

Monitor OUTPUT…

Power ON 
 Program D:\Arduino_projects\sketch_sep5a_PARK_IMU_copy_Posted\sketch_sep5a_PARK_IMU_copy_Posted.ino compiled on Oct 26 2023 at 12:58:21

IMU OK!

Accelerometer:
 X1 = -0.0737
 Y1 = -0.0137
 Z1 = 1.0214

Gyroscope:
 X1 = 0.6300
 Y1 = -2.6600
 Z1 = -0.9800

Thermometer:
 Degrees C1 = 33.2070
 Degrees F1 = 91.7727
 LSM6D3 Device is ParkedOct 26 2023 at 12:58:21
3D Position:-->TOP UP
(when moved)
----
Motion detected
Gyro Magnitude: 129.31
3D Position:-->TOP UP
Motion detected
Accelerometer Magnitude: 1.04
3D Position:-->TOP UP
 LSM6D3 Device is ParkedOct 26 2023 at 12:58:21
3D Position:-->TOP UP

 Button Interrupt received!

 Button Interrupt received!

 Button Interrupt received!
Double Tap WakeUp ON!
S L E E P !

Power On (BLUE LED ON…when Parked)


Motion (moved)

SLEEP…

1 Like

This is really a good project! Thank you for sharing :smile:

1 Like

Hi there, & thanks,
Just to put a bow on this , Thanx to Msfujino he discovered if I use the GPIO number for the attach interupt function in the code and, IT does compile and WORKs perfectly with BSP 2.9.2 So
much thanx to the Code & Power ninja :ninja: for the support.
as You where,
GL :slight_smile: PJ :v: