Skip to content

Commit 449392b

Browse files
authored
Merge pull request #16 from facchinm/nano33ble_rev2
feat: make library compatible with Nano 33 BLE Sense rev2
2 parents 11ec739 + c8427a1 commit 449392b

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

examples/magic_wand/imu_provider.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#ifndef MAGIC_WAND_IMU_PROVIDER_H
22
#define MAGIC_WAND_IMU_PROVIDER_H
33

4+
#ifdef NANO33_BLE_REV2
5+
#include <Arduino_BMI270_BMM150.h>
6+
#else
47
#include <Arduino_LSM9DS1.h>
8+
#endif
9+
510
#include <ArduinoBLE.h>
611

712
namespace {
@@ -60,15 +65,14 @@ namespace {
6065
*new_accelerometer_samples = 0;
6166
*new_gyroscope_samples = 0;
6267
// Loop through new samples and add to buffer
63-
while (IMU.accelerationAvailable()) {
68+
if (IMU.accelerationAvailable()) {
6469
const int gyroscope_index = (gyroscope_data_index % gyroscope_data_length);
6570
gyroscope_data_index += 3;
6671
float* current_gyroscope_data = &gyroscope_data[gyroscope_index];
6772
// Read each sample, removing it from the device's FIFO buffer
6873
if (!IMU.readGyroscope(
6974
current_gyroscope_data[0], current_gyroscope_data[1], current_gyroscope_data[2])) {
7075
Serial.println("Failed to read gyroscope data");
71-
break;
7276
}
7377
*new_gyroscope_samples += 1;
7478

@@ -79,7 +83,6 @@ 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;
8386
}
8487
*new_accelerometer_samples += 1;
8588
}
@@ -89,7 +92,7 @@ namespace {
8992
// Keep track of whether we stored any new data
9093
int new_samples = 0;
9194
// Loop through new samples and add to buffer
92-
while (IMU.gyroscopeAvailable()) {
95+
if (IMU.gyroscopeAvailable()) {
9396
const int index = (gyroscope_data_index % gyroscope_data_length);
9497
gyroscope_data_index += 3;
9598
float* data = &gyroscope_data[index];

examples/magic_wand/magic_wand.ino

Lines changed: 5 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 you are using a Nano 33 BLE rev2, uncomment the 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"
@@ -63,6 +66,8 @@ namespace {
6366
void setup() {
6467
// Start serial
6568
Serial.begin(9600);
69+
while (!Serial);
70+
6671
Serial.println("Started");
6772

6873
// Start IMU

examples/test_IMU/test_IMU.ino

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
Requires the Arduino_LSM9DS1 library library
77
*/
88

9+
// If you are using a Nano 33 BLE rev2, uncomment the next line:
10+
// #define NANO33_BLE_REV2
11+
12+
#ifdef NANO33_BLE_REV2
13+
#include <Arduino_BMI270_BMM150.h>
14+
#else
915
#include <Arduino_LSM9DS1.h>
16+
#endif
1017

1118
int imuIndex = 0; // 0 - accelerometer, 1 - gyroscope, 2 - magnetometer
1219
bool commandRecv = false; // flag used for indicating receipt of commands from serial port
@@ -22,6 +29,8 @@ void setup() {
2229
while (1);
2330
}
2431

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

0 commit comments

Comments
 (0)