Skip to content

Commit 269c80a

Browse files
committed
feat: make library compatible with Nano 33 BLE Sense rev2
* Needs arduino-libraries/Arduino_BMI270_BMM150#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
1 parent 11ec739 commit 269c80a

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

examples/magic_wand/imu_provider.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#define MAGIC_WAND_IMU_PROVIDER_H
33

44
#include <Arduino_LSM9DS1.h>
5+
#ifdef NANO33_BLE_REV2
6+
#include <Arduino_BMI270_BMM150.h>
7+
#endif
8+
59
#include <ArduinoBLE.h>
610

711
namespace {
@@ -60,15 +64,15 @@ namespace {
6064
*new_accelerometer_samples = 0;
6165
*new_gyroscope_samples = 0;
6266
// Loop through new samples and add to buffer
63-
while (IMU.accelerationAvailable()) {
67+
if (IMU.accelerationAvailable()) {
6468
const int gyroscope_index = (gyroscope_data_index % gyroscope_data_length);
6569
gyroscope_data_index += 3;
6670
float* current_gyroscope_data = &gyroscope_data[gyroscope_index];
6771
// Read each sample, removing it from the device's FIFO buffer
6872
if (!IMU.readGyroscope(
6973
current_gyroscope_data[0], current_gyroscope_data[1], current_gyroscope_data[2])) {
7074
Serial.println("Failed to read gyroscope data");
71-
break;
75+
//break;
7276
}
7377
*new_gyroscope_samples += 1;
7478

@@ -79,7 +83,7 @@ namespace {
7983
if (!IMU.readAcceleration(
8084
current_acceleration_data[0], current_acceleration_data[1], current_acceleration_data[2])) {
8185
Serial.println("Failed to read acceleration data");
82-
break;
86+
//break;
8387
}
8488
*new_accelerometer_samples += 1;
8589
}

examples/magic_wand/magic_wand.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ limitations under the License.
1212

1313
#include <TensorFlowLite.h>
1414

15+
// if using Nano BLE rev2, uncomment next line
16+
// #define NANO33_BLE_REV2
17+
1518
#include "tensorflow/lite/micro/micro_error_reporter.h"
1619
#include "tensorflow/lite/micro/micro_interpreter.h"
1720
#include "tensorflow/lite/micro/micro_mutable_op_resolver.h"

examples/test_IMU/test_IMU.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*/
88

99
#include <Arduino_LSM9DS1.h>
10+
// if using Nano BLE rev2, uncomment next line
11+
// #include <Arduino_BMI270_BMM150.h>
1012

1113
int imuIndex = 0; // 0 - accelerometer, 1 - gyroscope, 2 - magnetometer
1214
bool commandRecv = false; // flag used for indicating receipt of commands from serial port
@@ -22,6 +24,8 @@ void setup() {
2224
while (1);
2325
}
2426

27+
IMU.setContinuousMode();
28+
2529
Serial.println("Welcome to the IMU test for the built-in IMU on the Nano 33 BLE Sense\n");
2630
Serial.println("Available commands:");
2731
Serial.println("a - display accelerometer readings in g's in x, y, and z directions");

0 commit comments

Comments
 (0)