Hardware: mkr nb1500 + mkr imu shield
According to the imu shield datasheet the interrupt pin is connected to pin 0 on the nb1500.
I am trying to put the nb1500 to sleep and wake it up from an external interrupt from the imu.
Once i am moving the imu, the interrupt pin should trigger, but i am not sure it actually does. Is there a way i can check this? The variable imuTrigger in my code does detect any/no motion.
I am using the ArduinoLowPower library Arduino Low Power - Arduino Reference.
#include <Adafruit_BNO055.h>
#include "ArduinoLowPower.h"
#define BNO055_ADDRESS 0x28
#define BNO055_INT_STA 0x37
#define BNO055_PWR_MODE 0x3E
#define BNO055_OPR_MODE 0x3D
#define BNO055_ACC_NM_SET 0x16
#define BNO055_PAGE_ID 0x07
Adafruit_BNO055 bno = Adafruit_BNO055();
imu::Vector<3> acc;
const int pin = 0;
void setup() {
initializeIMU();
pinMode(LED_BUILTIN, OUTPUT);
pinMode(pin, INPUT_PULLUP);
LowPower.attachInterruptWakeup(pin, dummy, CHANGE);
}
void loop() {
// flash LED to indicate the board is on
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
// interrupt pin from imu: 64 = any motion detected, 128 = no motion detected
uint8_t imuTrigger = readByte(BNO055_ADDRESS, BNO055_INT_STA);
if (imuTrigger == 128) {
LowPower.sleep();
}
}
void dummy() {
// This function will be called once on device wakeup
// You can do some little operations here (like changing variables which will be used in the loop)
// Remember to avoid calling delay() and long running functions since this functions executes in interrupt context
}
/* ---------------------------------------------------------------------------------------------------------------------------*/
void writeByte(uint8_t address, uint8_t subAddress, uint8_t data)
{
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.write(data); // Put data in Tx buffer
Wire.endTransmission(); // Send the Tx buffer
}
uint8_t readByte(uint8_t address, uint8_t subAddress)
{
uint8_t data; // `data` will store the register data
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
Wire.requestFrom(address, (size_t) 1); // Read one byte from slave register address
data = Wire.read(); // Fill Rx buffer with result
return data; // Return data read from slave register
}
void initializeIMU()
{
bno.begin();
delay(20);
writeByte(BNO055_ADDRESS, BNO055_OPR_MODE, 0x00); // Put IMU in operation mode; 0x00 = config, 0x08 is IMU fusion mode
delay(20);
writeByte(BNO055_ADDRESS, BNO055_PWR_MODE, 0x01); // Put IMU in low power mode
Serial.println("IMU low power mode selected");
delay(20);
writeByte(BNO055_ADDRESS, BNO055_PAGE_ID, 0x01); // SELECT PAGE 1 TO CONFIGRE SETTINGS of page 1
delay(20);
// writeByte(BNO055_ADDRESS, BNO055_ACC_NM_SET, 0x7E); // 336s (~5.5 min), max duration
writeByte(BNO055_ADDRESS, BNO055_ACC_NM_SET, 0x09); // 5s usefull for testing
Serial.println("no motion to low power duration: 5s");
delay(20);
writeByte(BNO055_ADDRESS, BNO055_PAGE_ID, 0x00); // SELECT PAGE 0 TO CONFIGRE SETTINGS of page 0
delay(20);
writeByte(BNO055_ADDRESS, BNO055_OPR_MODE, 0x08); // Operation mode: IMU fusion mode
Serial.println("IMU fusion mode selected");
delay(100);
}
My code does not work. It goes to sleep, but never wakes up when moving the imu. Anyone notice what i am doing wrong?

