Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions examples/magic_wand/imu_provider.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#ifndef MAGIC_WAND_IMU_PROVIDER_H
#define MAGIC_WAND_IMU_PROVIDER_H

#ifdef NANO33_BLE_REV2
#include <Arduino_BMI270_BMM150.h>
#else
#include <Arduino_LSM9DS1.h>
#endif

#include <ArduinoBLE.h>

namespace {
Expand Down Expand Up @@ -60,15 +65,14 @@ 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];
// Read each sample, removing it from the device's FIFO buffer
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;

Expand All @@ -79,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;
}
Expand All @@ -89,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];
Expand Down
5 changes: 5 additions & 0 deletions examples/magic_wand/magic_wand.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ limitations under the License.

#include <TensorFlowLite.h>

// 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"
#include "tensorflow/lite/micro/micro_interpreter.h"
#include "tensorflow/lite/micro/micro_mutable_op_resolver.h"
Expand Down Expand Up @@ -63,6 +66,8 @@ namespace {
void setup() {
// Start serial
Serial.begin(9600);
while (!Serial);

Serial.println("Started");

// Start IMU
Expand Down
9 changes: 9 additions & 0 deletions examples/test_IMU/test_IMU.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
Requires the Arduino_LSM9DS1 library library
*/

// If you are using a Nano 33 BLE rev2, uncomment the next line:
// #define NANO33_BLE_REV2

#ifdef NANO33_BLE_REV2
#include <Arduino_BMI270_BMM150.h>
#else
#include <Arduino_LSM9DS1.h>
#endif

int imuIndex = 0; // 0 - accelerometer, 1 - gyroscope, 2 - magnetometer
bool commandRecv = false; // flag used for indicating receipt of commands from serial port
Expand All @@ -22,6 +29,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");
Expand Down