Hardware: Arduino mkr nb1500 + imu shield (contains bno055 sensor)
I am trying to send an interrupt to the arduino once the imu detect no motion (10s in my case).
According to the bno055 datasheet this can be enabled by setting only bit 7 to 1 in the INT_MSK register.
However, an interrupt is also given by the any motion interrupt, even tho bit 6 is set 0 so should be disabled.
I also asked this question on the bosch forum, but i was wondering if anyone might have experienced something similar, or notice something else what might be the cause. I already tested a second unit, so i doubt the hardware is the problem.
#include <Adafruit_BNO055.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
#define BNO055_INT_EN 0x10
#define BNO055_INT_MSK 0x0F
#define BNO055_SYS_TRIGGER 0x3F
Adafruit_BNO055 bno = Adafruit_BNO055();
imu::Vector<3> acc;
const byte pin = 0;
volatile byte state = HIGH;
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("Serial started.....");
initializeIMU();
pinMode(LED_BUILTIN, OUTPUT);
pinMode(pin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(pin), ISR, RISING);
}
void loop() {
digitalWrite(LED_BUILTIN, state);
}
void ISR() {
// change led state
state = !state;
writeByte(BNO055_ADDRESS, BNO055_SYS_TRIGGER, 0x40); // reset sys_trigger
Serial.println("Interrupt!");
}
/* ---------------------------------------------------------------------------------------------------------------------------*/
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(40);
// Select config mode
writeByte(BNO055_ADDRESS, BNO055_OPR_MODE, 0x00);
delay(40);
/*--------------- PAGE 0 SETTINGS ---------------*/
writeByte(BNO055_ADDRESS, BNO055_PAGE_ID, 0x00); // SELECT PAGE 0 TO CONFIGRE SETTINGS of page 0
delay(40);
writeByte(BNO055_ADDRESS, BNO055_PWR_MODE, 0x01); // Put IMU in low power mode
delay(40);
/*--------------- PAGE 1 SETTINGS ---------------*/
writeByte(BNO055_ADDRESS, BNO055_PAGE_ID, 0x01); // SELECT PAGE 1 TO CONFIGRE SETTINGS of page 1
delay(40);
// Enable interrupt pin; only no motion enabled
// writeByte(BNO055_ADDRESS, BNO055_INT_EN, 0x80);
delay(40);
// Set no motion interrupt to 10s
writeByte(BNO055_ADDRESS, BNO055_ACC_NM_SET, 0x13);
delay(40);
// Enable masking interrupt pin; only no motion enabled
writeByte(BNO055_ADDRESS, BNO055_INT_MSK, 0x80);
delay(40);
// Select imu fusion mode
writeByte(BNO055_ADDRESS, BNO055_PAGE_ID, 0x00); // SELECT PAGE 0 TO CONFIGRE SETTINGS of page 0
delay(40);
writeByte(BNO055_ADDRESS, BNO055_OPR_MODE, 0x08); // Operation mode: IMU fusion mode
delay(100);
}
