Skip to content

Nicla Sense ME as an I2C request-reply slave sensor, similar to the BNO055, with python API.

Notifications You must be signed in to change notification settings

werner-duvaud/nicla-sense-me-i2c

Repository files navigation

Nicla Sense ME - I2C standalone

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.

Python API

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.

Setup

Setup the Nicla Sense ME

First we need to compile and upload the software running on the sensor microcontroller.

  1. Open nicla_sense_me.ino with the Arduino IDE.
  2. Select the "Arduino Nicla Sense ME" board.
  3. Install the "Arduino_BHY2" and "ArduinoBLE" libraries from the Library Manager tab.
  4. 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 line public:.
  5. Connect the Micro USB port of the device to the computer.
  6. Click on the upload button in Arduino editor.

Host setup

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 .

I2C hardware setup

Wire 4 pin headers: Vin (5v), Ground, SCL, SDA as follows:

nicla_sense_me_i2c

Note

  • Using the onboard LED is not recommended as it is using I2C too.

Reference and useful links

About

Nicla Sense ME as an I2C request-reply slave sensor, similar to the BNO055, with python API.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published