From cc645b65a94d6052b527365c4b4ff3ca242749a1 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Mon, 13 Feb 2023 16:00:02 +0100 Subject: [PATCH] nrf/boards/arduino_nano_33_ble_sense: Add support for REV-2 chipset. These changes allow the firmware to support both the REV-1 and REV-2 versions of the board: - Freeze the new device drivers used in REV-2. - Add a board-level module that abstracts the IMU chipset. --- .../arduino_nano_33_ble_sense/manifest.py | 4 ++ .../arduino_nano_33_ble_sense/modules/imu.py | 45 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 ports/nrf/boards/arduino_nano_33_ble_sense/modules/imu.py diff --git a/ports/nrf/boards/arduino_nano_33_ble_sense/manifest.py b/ports/nrf/boards/arduino_nano_33_ble_sense/manifest.py index 8396e0249c..1e35ae8c4d 100644 --- a/ports/nrf/boards/arduino_nano_33_ble_sense/manifest.py +++ b/ports/nrf/boards/arduino_nano_33_ble_sense/manifest.py @@ -2,3 +2,7 @@ include("$(PORT_DIR)/modules/manifest.py") require("hts221") require("lps22h") require("lsm9ds1") +require("bmm150") +require("bmi270") +require("hs3003") +freeze("./modules") diff --git a/ports/nrf/boards/arduino_nano_33_ble_sense/modules/imu.py b/ports/nrf/boards/arduino_nano_33_ble_sense/modules/imu.py new file mode 100644 index 0000000000..50a36a1976 --- /dev/null +++ b/ports/nrf/boards/arduino_nano_33_ble_sense/modules/imu.py @@ -0,0 +1,45 @@ +""" +IMU module for Arduino Nano BLE 33 SENSE (REV1 and REV2). + +Example usage: + +import time +import imu +from machine import Pin, I2C + +bus = I2C(1, scl=Pin(15), sda=Pin(14)) +imu = imu.IMU(bus) + +while (True): + print('Accelerometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.accel())) + print('Gyroscope: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.gyro())) + print('Magnetometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*imu.magnet())) + print("") + time.sleep_ms(100) +""" + +import time + + +class IMU: + def __init__(self, bus): + """Initalizes Gyro, Accelerometer and Magnetometer using default values.""" + if 0x68 in bus.scan(): + from bmm150 import BMM150 + from bmi270 import BMI270 + + magnet = BMM150(bus) + self.imu = BMI270(bus, bmm_magnet=magnet) + else: + from lsm9ds1 import LSM9DS1 + + self.imu = LSM9DS1(bus) + + def gyro(self): + return self.imu.gyro() + + def accel(self): + return self.imu.accel() + + def magnet(self): + return self.imu.magnet()