Hi all,
I have been working on making a gyroscope mouse with an Arduino Nano 33 BLE Sense board. I can move the mouse through simple code, such as mouse.move(20, 0), using the USBMouse library from Mbed OS. However, when I try to access other sensors on the board, such as the gyroscope, it seems that the IMU fails to initialize. This problem seems to have been reported here. The IMU.begin() function returns false if it fails to initialize, and it is returning false.
I have done some trials to try to figure out what is happening with the USBMouse and Arduino_LSM9DS1 libraries. The IMU initializes in the following code. Leaving the USBMouse object declaration in the setup does not allow the loop to run, since the red LED does not turn on. Commenting out the object declaration allows the loop to run. Adding the object declaration anywhere before the IMU.begin() causes the IMU to fail to initialize. I’m not sure why it doesn’t initialize in this case.
#include "USBMouse.h"
#include <Arduino_LSM9DS1.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
digitalWrite(LEDB, LOW);//Show setup has started
delay(5000);
digitalWrite(LEDB, HIGH);
if (!IMU.begin()) {
digitalWrite(LEDR, LOW);//LED on if IMU fails to initialize
}
else {
digitalWrite(LEDR, HIGH);//LED off if IMU initializes
}
delay(10000);
float x, y, z;
IMU.readGyroscope(x, y , z);
Serial.println(x);
Serial.println(y);
Serial.println(z);
delay(5000);
USBMouse mouse(true);//Commenting this out causes onboard RGB LED to turn red, which implies loop() is run
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(LEDR, LOW);//LED on during loop
}
Any help would be appreciated.