Use the Nicla Sense ME sensor as an I2C request-reply slave sensor, similar to the BNO055.
The BHI260AP combined with the BMM150 offers a modern absolute orientation IMU sensor with onchip sensor fusion. Making the Nicla Sense ME board a good successor to the BNO055.
This repository holds the arduino code to run on the Nicla Sense ME microprocesseur and a small Python library using the busio library to talk to the sensor over I2C.
Features:
- Warm start with your custom calibration config.
- Absolute orientation (heading to north, pitch, roll).
- Raw acceleration, gyroscope, magnetometer.
- Rotation quaternion.
- Linear acceleration.
- Temperature.
- Pressure.
- Gaz.
- Activity.
- BSEC.
- 200Hz sensor data over i2c.
- Simple code easily hackable.
Runs on Nvidia Jetson, Raspberry Pi and MicroPython boards.
import json
from nicla_sense_me_i2c import NiclaSenseMe
import board
import busio
i2c = busio.I2C(board.SCL, board.SDA)
sensor = NiclaSenseMe(i2c)
# Calib obtained with sensor.get_calib() after calibration.
with open('calib.json') as calib_file:
calib = json.load(calib_file)
# Warm start with sensor already calibrated.
sensor.send_calib(**calib)
sensor.start()
while True:
heading, pitch, roll = sensor.orientation() # In degrees. [0, 360], [-180, 180], [-90, 90]
acc_x, acc_y, acc_z = sensor.acceleration() # In earth g.
lin_acc_x, lin_acc_y, lin_acc_z = sensor.linear_acceleration() # In earth g.
gyr_x, gyr_y, gyr_z = sensor.gyroscope() # In degrees/second.
mag_x, mag_y, mag_z = sensor.magnetometer() # In µT.
qx, qy, qz, qw = sensor.quaternion() # Quaternion.
temp = sensor.temperature() # In degrees celsius.
print(f"{heading=:.2f}, {pitch=:.2f}, {roll=:.2f}")
See also example.py.
First we need to compile and upload the software running on the sensor microcontroller.
- Open
nicla_sense_me.ino
with the Arduino IDE. - Select the "Arduino Nicla Sense ME" board.
- Install the "Arduino_BHY2" and "ArduinoBLE" libraries from the Library Manager tab.
- Edit the library file "BoschSensortec.h" located at "Documents/Arduino/libraries/Arduino_BHY2/src/BoschSensortec.h" and move the line
struct bhy2_dev _bhy2;
after the linepublic:
. - Connect the Micro USB port of the device to the computer.
- Click on the upload button in Arduino editor.
Install the python library on the host to communicate with the sensor:
git clone https://github.com/werner-duvaud/nicla-sense-me-i2c.git
cd nicla-sense-me-i2c
pip install .
Wire 4 pin headers: Vin (5v), Ground, SCL, SDA as follows:
- Using the onboard LED is not recommended as it is using I2C too.