From 269c80aecbc10a35c1547777a971b9ddca6fb98b Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 20 Oct 2025 16:12:49 +0200 Subject: [PATCH 1/3] feat: make library compatible with Nano 33 BLE Sense rev2 * Needs https://github.com/arduino-libraries/Arduino_BMI270_BMM150/pull/56 to properly handle BMI270 in FIFO mode * The user should define NANO33_BLE_REV2 as early as possible to include the proper libraries (fixed the examples) * `while (IMU.accelerationAvailable())` replaced with `if (IMU.accelerationAvailable())`, shouldn't change anything in existing code since Arduino_LSM9DS1 was always returing only one sample --- examples/magic_wand/imu_provider.h | 10 +++++++--- examples/magic_wand/magic_wand.ino | 3 +++ examples/test_IMU/test_IMU.ino | 4 ++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/examples/magic_wand/imu_provider.h b/examples/magic_wand/imu_provider.h index a2d0cd5..15b9e0f 100644 --- a/examples/magic_wand/imu_provider.h +++ b/examples/magic_wand/imu_provider.h @@ -2,6 +2,10 @@ #define MAGIC_WAND_IMU_PROVIDER_H #include +#ifdef NANO33_BLE_REV2 +#include +#endif + #include namespace { @@ -60,7 +64,7 @@ namespace { *new_accelerometer_samples = 0; *new_gyroscope_samples = 0; // Loop through new samples and add to buffer - while (IMU.accelerationAvailable()) { + if (IMU.accelerationAvailable()) { const int gyroscope_index = (gyroscope_data_index % gyroscope_data_length); gyroscope_data_index += 3; float* current_gyroscope_data = &gyroscope_data[gyroscope_index]; @@ -68,7 +72,7 @@ namespace { if (!IMU.readGyroscope( current_gyroscope_data[0], current_gyroscope_data[1], current_gyroscope_data[2])) { Serial.println("Failed to read gyroscope data"); - break; + //break; } *new_gyroscope_samples += 1; @@ -79,7 +83,7 @@ namespace { if (!IMU.readAcceleration( current_acceleration_data[0], current_acceleration_data[1], current_acceleration_data[2])) { Serial.println("Failed to read acceleration data"); - break; + //break; } *new_accelerometer_samples += 1; } diff --git a/examples/magic_wand/magic_wand.ino b/examples/magic_wand/magic_wand.ino index 5c4e0de..4e89c1e 100644 --- a/examples/magic_wand/magic_wand.ino +++ b/examples/magic_wand/magic_wand.ino @@ -12,6 +12,9 @@ limitations under the License. #include +// if using Nano BLE rev2, uncomment next line +// #define NANO33_BLE_REV2 + #include "tensorflow/lite/micro/micro_error_reporter.h" #include "tensorflow/lite/micro/micro_interpreter.h" #include "tensorflow/lite/micro/micro_mutable_op_resolver.h" diff --git a/examples/test_IMU/test_IMU.ino b/examples/test_IMU/test_IMU.ino index 4b3d646..2148597 100644 --- a/examples/test_IMU/test_IMU.ino +++ b/examples/test_IMU/test_IMU.ino @@ -7,6 +7,8 @@ */ #include +// if using Nano BLE rev2, uncomment next line +// #include int imuIndex = 0; // 0 - accelerometer, 1 - gyroscope, 2 - magnetometer bool commandRecv = false; // flag used for indicating receipt of commands from serial port @@ -22,6 +24,8 @@ void setup() { while (1); } + IMU.setContinuousMode(); + Serial.println("Welcome to the IMU test for the built-in IMU on the Nano 33 BLE Sense\n"); Serial.println("Available commands:"); Serial.println("a - display accelerometer readings in g's in x, y, and z directions"); From 40b247d17fc2d9696b85aaa841c78befe4b7361f Mon Sep 17 00:00:00 2001 From: seanmabli Date: Sat, 22 Nov 2025 12:16:24 -0500 Subject: [PATCH 2/3] Small changes --- examples/magic_wand/imu_provider.h | 7 +++---- examples/magic_wand/magic_wand.ino | 4 +++- examples/test_IMU/test_IMU.ino | 9 +++++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/examples/magic_wand/imu_provider.h b/examples/magic_wand/imu_provider.h index 15b9e0f..d7d6ad7 100644 --- a/examples/magic_wand/imu_provider.h +++ b/examples/magic_wand/imu_provider.h @@ -1,9 +1,10 @@ #ifndef MAGIC_WAND_IMU_PROVIDER_H #define MAGIC_WAND_IMU_PROVIDER_H -#include #ifdef NANO33_BLE_REV2 #include +#else +#include #endif #include @@ -72,7 +73,6 @@ namespace { if (!IMU.readGyroscope( current_gyroscope_data[0], current_gyroscope_data[1], current_gyroscope_data[2])) { Serial.println("Failed to read gyroscope data"); - //break; } *new_gyroscope_samples += 1; @@ -83,7 +83,6 @@ namespace { if (!IMU.readAcceleration( current_acceleration_data[0], current_acceleration_data[1], current_acceleration_data[2])) { Serial.println("Failed to read acceleration data"); - //break; } *new_accelerometer_samples += 1; } @@ -93,7 +92,7 @@ namespace { // Keep track of whether we stored any new data int new_samples = 0; // Loop through new samples and add to buffer - while (IMU.gyroscopeAvailable()) { + if (IMU.gyroscopeAvailable()) { const int index = (gyroscope_data_index % gyroscope_data_length); gyroscope_data_index += 3; float* data = &gyroscope_data[index]; diff --git a/examples/magic_wand/magic_wand.ino b/examples/magic_wand/magic_wand.ino index 4e89c1e..87a6cb7 100644 --- a/examples/magic_wand/magic_wand.ino +++ b/examples/magic_wand/magic_wand.ino @@ -12,7 +12,7 @@ limitations under the License. #include -// if using Nano BLE rev2, uncomment next line +// If you are using a Nano BLE rev2, uncomment the next line: // #define NANO33_BLE_REV2 #include "tensorflow/lite/micro/micro_error_reporter.h" @@ -66,6 +66,8 @@ namespace { void setup() { // Start serial Serial.begin(9600); + while (!Serial); + Serial.println("Started"); // Start IMU diff --git a/examples/test_IMU/test_IMU.ino b/examples/test_IMU/test_IMU.ino index 2148597..571bdc7 100644 --- a/examples/test_IMU/test_IMU.ino +++ b/examples/test_IMU/test_IMU.ino @@ -6,9 +6,14 @@ Requires the Arduino_LSM9DS1 library library */ +// If you are using a Nano BLE rev2, uncomment the next line: +// #define NANO33_BLE_REV2 + +#ifdef NANO33_BLE_REV2 +#include +#else #include -// if using Nano BLE rev2, uncomment next line -// #include +#endif int imuIndex = 0; // 0 - accelerometer, 1 - gyroscope, 2 - magnetometer bool commandRecv = false; // flag used for indicating receipt of commands from serial port From c8427a1bc5128179860c7ae9025a252e62741225 Mon Sep 17 00:00:00 2001 From: seanmabli Date: Sat, 22 Nov 2025 12:47:29 -0500 Subject: [PATCH 3/3] Small changes --- examples/magic_wand/magic_wand.ino | 2 +- examples/test_IMU/test_IMU.ino | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/magic_wand/magic_wand.ino b/examples/magic_wand/magic_wand.ino index 87a6cb7..3729a65 100644 --- a/examples/magic_wand/magic_wand.ino +++ b/examples/magic_wand/magic_wand.ino @@ -12,7 +12,7 @@ limitations under the License. #include -// If you are using a Nano BLE rev2, uncomment the next line: +// If you are using a Nano 33 BLE rev2, uncomment the next line: // #define NANO33_BLE_REV2 #include "tensorflow/lite/micro/micro_error_reporter.h" diff --git a/examples/test_IMU/test_IMU.ino b/examples/test_IMU/test_IMU.ino index 571bdc7..23df532 100644 --- a/examples/test_IMU/test_IMU.ino +++ b/examples/test_IMU/test_IMU.ino @@ -6,7 +6,7 @@ Requires the Arduino_LSM9DS1 library library */ -// If you are using a Nano BLE rev2, uncomment the next line: +// If you are using a Nano 33 BLE rev2, uncomment the next line: // #define NANO33_BLE_REV2 #ifdef NANO33_BLE_REV2