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
[quote=]
#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
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);
pinMode(LED_BUILTIN, OUTPUT);
myIMU.settings.gyroEnabled = 1;
myIMU.settings.accelEnabled = 1;
// Initialisation du capteur
if (myIMU.begin() != 0) {
Serial.println(“Erreur 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, 0x00);
myIMU.writeRegister(LSM6DS3_ACC_GYRO_WAKE_UP_THS, 0x02);
myIMU.writeRegister(LSM6DS3_ACC_GYRO_WAKE_UP_DUR , 0x00);
if (enable) {
Serial.println(“Double Tap WakeUp ON!”);
//myIMU.writeRegister(LSM6DS3_ACC_GYRO_MD1_CFG, 0x08); // Enable the double-tap interrupt
myIMU.writeRegister(LSM6DS3_ACC_GYRO_MD1_CFG, 0x20); // Enable the double-tap interrupt
} else {
myIMU.writeRegister(LSM6DS3_ACC_GYRO_MD1_CFG, 0x00); // Disable the double-tap interrupt
Serial.println(“Double Tap OFF”);
}
}
// -------------------- 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
}
[/quote]