Issue with XIAO BLE SENSE and internal IMU

I, sorry for my bad english, it’s not my born language… I want to use the internal IMU to wake up the XIAO BLE SENSE when it detect movements. But i’m in trouble with, the proper way to put the BLE SENSE into sleep mode and use imu to wake it up. I’m working on arduino IDE and i tried some exmples code that i found somewhere like this one

and nothing is working…

Someone here have the same issues?

Welcome… PJGlasso may be able to help you with this problem… he is the expert with the XIAO BLE

Hi there,
What BSP are you using? (board Support package) the first 3 lines of the compiler output.
2.9.1 is used for this demo to work.
Roll back to that and try again.
The code posted works as advertised.
HTH
GL :slight_smile: PJ
:v:

for 2.9.2 to work with this demo code, change the Interrupt line to use the GPIO pin number, great example of how the newer breaks the older but using the Original GPIO pin numbering works… LOL go figure
anyway change it to this: for 2.9.2

//#define int2Pin PIN_LSM6DS3TR_C_INT1
#define int2Pin P0_11
It worked with BSP 2.9.2.
1 Like

Hello, I was using version 2.9.0 and the code worked fine but when I wanted to change the interrupt detection method from double tap to wake_up nothing happened. I think there’s a configuration problem in the IMU. I relied on the documentation provided (AN4650_DM00157511.pdf) but nothing worked… I switched to 2.9.2, and modified the #define int2Pin line as you indicated. Here’s my code as it stands

Hi there,
So there are a number of omissions and variation in this interpretation of the demo code.
Some key parameters. We like to “Teach a man to fish” in most instance’s, but this time I know the material and you would be smart to see what the edits are in order to understand.
this code works with the BSP 2.9.2 and the edit for INT pin.(indicated earlier)
Runs for 10 seconds 'ish and prints
1.02
Going to sleep…
Double Tap WakeUp ON!
sleeps & disconnects. corresponding double tap wakes it up. (rinse, repeat)

#include <LSM6DS3.h>
#include <Wire.h>

// Créer une instance de la classe LSM6DS3
LSM6DS3 myIMU(I2C_MODE, 0x6A);

//#define int2Pin PIN_LSM6DS3TR_C_INT1
#define int2Pin P0_11

uint8_t interruptCount = 0; // Amount of received interrupts
int movedPos = LOW;
unsigned long lastMovementTime = 0;
const unsigned long sleepDuration = 10000; // 10 seconds in milliseconds

void setup() {
// Initialisation de la communication série pour le débogage
Serial.begin(9600);
delay(2500);
pinMode(int2Pin, INPUT);
attachInterrupt(digitalPinToInterrupt(int2Pin), int1ISR, RISING);
pinMode(LED_BUILTIN, OUTPUT);
myIMU.settings.gyroEnabled = 1;
myIMU.settings.accelEnabled = 1;
// Initialisation du capteur
if (myIMU.begin() != 0) {
Serial.println("rreur d’initialisation du capteur !");
} else {
Serial.println("Capteur initialisé avec succès.");
}
digitalWrite(LED_BUILTIN, LOW);
}

void loop() {

// Read accelerometer data
float accX = myIMU.readFloatAccelX();
float accY = myIMU.readFloatAccelY();
float accZ = myIMU.readFloatAccelZ();

// Calculate motion magnitude based on accelerometer data
float motionMagnitude = sqrt(accX * accX + accY * accY + accZ * accZ);

// Check if there is motion
if (motionMagnitude > 1.06) {
// Reset the timer
lastMovementTime = millis();
Serial.println(motionMagnitude);
} else {
// Check if the timer has elapsed (10 seconds)
Serial.println(motionMagnitude);
if (millis() - lastMovementTime >= sleepDuration) {
goToPowerOff();
}
}
}

void setupDoubleTapInterrupt(bool enable) {
//uint8_t error = 0;
//uint8_t dataToWrite = 0;
 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 int1ISR() {      // Moved Interrupt changed //
  interruptCount++;
  movedPos = HIGH;
  ;
}
// -------------------- System ------------------------- //
void goToPowerOff() {
Serial.println("Going to sleep…");
setupDoubleTapInterrupt(true); // not needed here, if already applied…
delay(2500);
digitalWrite(LED_BUILTIN, HIGH);
nrf_gpio_cfg_sense_input(digitalPinToInterrupt(int2Pin), NRF_GPIO_PIN_PULLDOWN, NRF_GPIO_PIN_SENSE_HIGH);
delay(2000);

NRF_POWER->SYSTEMOFF = 1; // Trigger System OFF
}

HTH
GL :slight_smile: PJ :v:

keyboard and the floor… :slight_smile:

1 Like