Remarks

Bno055
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Motion.Bno055

BNO055 is a 9-axis absolute orientation sensor. The three sensors (accelerometer, gyroscope and magnetometer) are measured with a 32-bit cortex M0 microcontroller. The BNO055 is controlled via I2C.

Purchasing

Code Example

Bno055 sensor;

public override Task Initialize()
{
    Console.WriteLine("Initialize...");

    // create the sensor driver
    sensor = new Bno055(Device.CreateI2cBus());

    // classical .NET events can also be used:
    sensor.Updated += (sender, result) =>
    {
        Console.WriteLine($"Accel: [X:{result.New.Acceleration3D?.X.MetersPerSecondSquared:N2}," +
            $"Y:{result.New.Acceleration3D?.Y.MetersPerSecondSquared:N2}," +
            $"Z:{result.New.Acceleration3D?.Z.MetersPerSecondSquared:N2} (m/s^2)]");

        Console.WriteLine($"Gyro: [X:{result.New.AngularVelocity3D?.X.DegreesPerSecond:N2}," +
            $"Y:{result.New.AngularVelocity3D?.Y.DegreesPerSecond:N2}," +
            $"Z:{result.New.AngularVelocity3D?.Z.DegreesPerSecond:N2} (degrees/s)]");

        Console.WriteLine($"Compass: [X:{result.New.MagneticField3D?.X.Tesla:N2}," +
            $"Y:{result.New.MagneticField3D?.Y.Tesla:N2}," +
            $"Z:{result.New.MagneticField3D?.Z.Tesla:N2} (Tesla)]");

        Console.WriteLine($"Gravity: [X:{result.New.GravityVector?.X.MetersPerSecondSquared:N2}," +
            $"Y:{result.New.GravityVector?.Y.MetersPerSecondSquared:N2}," +
            $"Z:{result.New.GravityVector?.Z.MetersPerSecondSquared:N2} (meters/s^2)]");

        Console.WriteLine($"Quaternion orientation: [X:{result.New.QuaternionOrientation?.X:N2}," +
            $"Y:{result.New.QuaternionOrientation?.Y:N2}," +
            $"Z:{result.New.QuaternionOrientation?.Z:N2}]");

        Console.WriteLine($"Euler orientation: [heading: {result.New.EulerOrientation?.Heading:N2}," +
            $"Roll: {result.New.EulerOrientation?.Roll:N2}," +
            $"Pitch: {result.New.EulerOrientation?.Pitch:N2}]");

        Console.WriteLine($"Linear Accel: [X:{result.New.LinearAcceleration?.X.MetersPerSecondSquared:N2}," +
            $"Y:{result.New.LinearAcceleration?.Y.MetersPerSecondSquared:N2}," +
            $"Z:{result.New.LinearAcceleration?.Z.MetersPerSecondSquared:N2} (meters/s^2)]");

        Console.WriteLine($"Temp: {result.New.Temperature?.Celsius:N2}C");
    };

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Bno055.CreateObserver(
        handler: result => Console.WriteLine($"Observer: [x] changed by threshold; new [x]: X:{result.New.Acceleration3D?.X.MetersPerSecondSquared:N2}, old: X:{result.Old?.Acceleration3D?.X.MetersPerSecondSquared:N2}"),
        // only notify if there's a greater than 1 micro tesla on the Y axis

        filter: result =>
        {
            if (result.Old is { } old)
            { //c# 8 pattern match syntax. checks for !null and assigns var.
                return ((result.New.Acceleration3D - old.Acceleration3D)?.Y > new Acceleration(1, AU.MetersPerSecondSquared));
            }
            return false;
        });
    sensor.Subscribe(consumer);

    return Task.CompletedTask;
}

public async override Task Run()
{ 
    await ReadConditions();

    sensor.StartUpdating(TimeSpan.FromMilliseconds(500));
}

protected async Task ReadConditions()
{
    var result = await sensor.Read();
    Console.WriteLine("Initial Readings:");
    Console.WriteLine($"Accel: [X:{result.Acceleration3D?.X.MetersPerSecondSquared:N2}," +
        $"Y:{result.Acceleration3D?.Y.MetersPerSecondSquared:N2}," +
        $"Z:{result.Acceleration3D?.Z.MetersPerSecondSquared:N2} (m/s^2)]");

    Console.WriteLine($"Gyro: [X:{result.AngularVelocity3D?.X.DegreesPerSecond:N2}," +
        $"Y:{result.AngularVelocity3D?.Y.DegreesPerSecond:N2}," +
        $"Z:{result.AngularVelocity3D?.Z.DegreesPerSecond:N2} (degrees/s)]");

    Console.WriteLine($"Compass: [X:{result.MagneticField3D?.X.Tesla:N2}," +
        $"Y:{result.MagneticField3D?.Y.Tesla:N2}," +
        $"Z:{result.MagneticField3D?.Z.Tesla:N2} (Tesla)]");

    Console.WriteLine($"Gravity: [X:{result.GravityVector?.X.MetersPerSecondSquared:N2}," +
        $"Y:{result.GravityVector?.Y.MetersPerSecondSquared:N2}," +
        $"Z:{result.GravityVector?.Z.MetersPerSecondSquared:N2} (meters/s^2)]");

    Console.WriteLine($"Quaternion orientation: [X:{result.QuaternionOrientation?.X:N2}," +
        $"Y:{result.QuaternionOrientation?.Y:N2}," +
        $"Z:{result.QuaternionOrientation?.Z:N2}]");

    Console.WriteLine($"Euler orientation: [heading: {result.EulerOrientation?.Heading:N2}," +
        $"Roll: {result.EulerOrientation?.Roll:N2}," +
        $"Pitch: {result.EulerOrientation?.Pitch:N2}]");

    Console.WriteLine($"Linear Accel: [X:{result.LinearAcceleration?.X.MetersPerSecondSquared:N2}," +
        $"Y:{result.LinearAcceleration?.Y.MetersPerSecondSquared:N2}," +
        $"Z:{result.LinearAcceleration?.Z.MetersPerSecondSquared:N2} (meters/s^2)]");

    Console.WriteLine($"Temp: {result.Temperature?.Celsius:N2}C");
}

Sample project(s) available on GitHub

Wiring Example

The following diagram shows the BNO055 configured for bas

Characteristic Locus
Inheritance System.Object > Bno055
Implements IAccelerometer IGyroscope ITemperatureSensor
Namespace Meadow.Foundation.Sensors.Motion
Assembly Bno055.dll

Syntax

public class Bno055 : ByteCommsSensorBase<(Acceleration3D? Acceleration3D, AngularVelocity3D? AngularVelocity3D, MagneticField3D? MagneticField3D, Quaternion? QuaternionOrientation, Acceleration3D? LinearAcceleration, Acceleration3D? GravityVector, EulerAngles? EulerOrientation, Units.Temperature? Temperature)>, IAccelerometer, IGyroscope, ITemperatureSensor

Constructors

Bno055(II2cBus, Bno055.Addresses)

Create a new BNO055 object using the default parameters for the component.

Declaration
public Bno055(II2cBus i2cBus, Bno055.Addresses address = default(Bno055.Addresses))

Parameters

Type Name Description
II2cBus i2cBus

I2C bus (default = 400 KHz).

Bno055.Addresses address

Address of the BNO055 (default = 0x28).

Bno055(II2cBus, Byte)

Create a new BNO055 object using the default parameters for the component.

Declaration
public Bno055(II2cBus i2cBus, byte address)

Parameters

Type Name Description
II2cBus i2cBus

I2C bus (default = 400 KHz).

System.Byte address

Address of the BNO055 (default = 0x28).

Properties

Acceleration3D

Current Acceleration

Declaration
public Acceleration3D? Acceleration3D { get; }

Property Value

Type Description
System.Nullable<Acceleration3D>

AngularVelocity3D

Current Angular Velocity

Declaration
public AngularVelocity3D? AngularVelocity3D { get; }

Property Value

Type Description
System.Nullable<AngularVelocity3D>

EulerOrientation

Current Euler Orientation

Declaration
public EulerAngles? EulerOrientation { get; }

Property Value

Type Description
System.Nullable<EulerAngles>

GravityVector

Current Gravity Vector

Declaration
public Acceleration3D? GravityVector { get; }

Property Value

Type Description
System.Nullable<Acceleration3D>

IsAccelerometerCalibrated

Get the accelerometer calibration status.

Declaration
public bool IsAccelerometerCalibrated { get; }

Property Value

Type Description
System.Boolean

IsFullyCalibrated

Is the system fully calibrated?

Declaration
public bool IsFullyCalibrated { get; }

Property Value

Type Description
System.Boolean

Remarks

The sensor is fully calibrated if the system, accelerometer, gyroscope and megnetometer are all calibrated.

IsGyroscopeCalibrated

Get the gyroscope calibration status.

Declaration
public bool IsGyroscopeCalibrated { get; }

Property Value

Type Description
System.Boolean

IsInFusionMode

Check if sensor is currently working in Fusion mode.

Declaration
public bool IsInFusionMode { get; }

Property Value

Type Description
System.Boolean

IsMagnetometerCalibrated

Get the magnetometer status.

Declaration
public bool IsMagnetometerCalibrated { get; }

Property Value

Type Description
System.Boolean

IsSystemCalibrated

Get the system calibration status.

Declaration
public bool IsSystemCalibrated { get; }

Property Value

Type Description
System.Boolean

LinearAcceleration

Current Linear Acceleration

Declaration
public Acceleration3D? LinearAcceleration { get; }

Property Value

Type Description
System.Nullable<Acceleration3D>

MagneticField3D

Current Magnetic Field

Declaration
public MagneticField3D? MagneticField3D { get; }

Property Value

Type Description
System.Nullable<MagneticField3D>

OperatingMode

Get / set the current operating mode for the sensor.

Declaration
public byte OperatingMode { get; set; }

Property Value

Type Description
System.Byte

Remarks

Mode change takes 7-19 ms.

PowerMode

Get or set the power mode for the sensor.

Declaration
public byte PowerMode { get; set; }

Property Value

Type Description
System.Byte

QuaternionOrientation

Current Quaternion Orientation

Declaration
public Quaternion? QuaternionOrientation { get; }

Property Value

Type Description
System.Nullable<Quaternion>

Temperature

Current Temperature value

Declaration
public Units.Temperature? Temperature { get; }

Property Value

Type Description
System.Nullable<Units.Temperature>

TemperatureSource

Select the source of the Temperatute property.

Declaration
public Bno055.Sensor TemperatureSource { get; set; }

Property Value

Type Description
Bno055.Sensor

Methods

ConvertReadingToEulerAngles(Int32, Double)

Convert the sensor readings into an orientation in Euler angles

Declaration
protected EulerAngles ConvertReadingToEulerAngles(int start, double divisor)

Parameters

Type Name Description
System.Int32 start

First of the sensor readings to convert

System.Double divisor

Divisor to apply to the sensor data

Returns

Type Description
EulerAngles

EulerAngles object containing the orientation informaiton

DisplayRegisters()

Read all of the registers and display their values on the Debug output.

Declaration
public void DisplayRegisters()

GetReadings(Int32, Double)

Convert a section of the sensor data into a tuple

Declaration
protected (double X, double Y, double Z) GetReadings(int start, double divisor)

Parameters

Type Name Description
System.Int32 start

Start of the data in the sensorReadings member variable

System.Double divisor

Divisor

Returns

Type Description
System.ValueTuple<System.Double, System.Double, System.Double>

RaiseEventsAndNotify(IChangeResult<(Nullable<Acceleration3D> Acceleration3D, Nullable<AngularVelocity3D> AngularVelocity3D, Nullable<MagneticField3D> MagneticField3D, Nullable<Quaternion> QuaternionOrientation, Nullable<Acceleration3D> LinearAcceleration, Nullable<Acceleration3D> GravityVector, Nullable<EulerAngles> EulerOrientation, Nullable<Units.Temperature> Temperature)>)

Raise events for subcribers and notify of value changes

Declaration
protected override void RaiseEventsAndNotify(IChangeResult<(Acceleration3D? Acceleration3D, AngularVelocity3D? AngularVelocity3D, MagneticField3D? MagneticField3D, Quaternion? QuaternionOrientation, Acceleration3D? LinearAcceleration, Acceleration3D? GravityVector, EulerAngles? EulerOrientation, Units.Temperature? Temperature)> changeResult)

Parameters

Type Name Description
IChangeResult<System.ValueTuple<System.Nullable<Acceleration3D>, System.Nullable<AngularVelocity3D>, System.Nullable<MagneticField3D>, System.Nullable<Quaternion>, System.Nullable<Acceleration3D>, System.Nullable<Acceleration3D>, System.Nullable<EulerAngles>, System.ValueTuple<System.Nullable<Units.Temperature>>>> changeResult

The updated sensor data

ReadSensor()

Reads data from the sensor

Declaration
protected override Task<(Acceleration3D? Acceleration3D, AngularVelocity3D? AngularVelocity3D, MagneticField3D? MagneticField3D, Quaternion? QuaternionOrientation, Acceleration3D? LinearAcceleration, Acceleration3D? GravityVector, EulerAngles? EulerOrientation, Units.Temperature? Temperature)> ReadSensor()

Returns

Type Description
Task<System.ValueTuple<System.Nullable<Acceleration3D>, System.Nullable<AngularVelocity3D>, System.Nullable<MagneticField3D>, System.Nullable<Quaternion>, System.Nullable<Acceleration3D>, System.Nullable<Acceleration3D>, System.Nullable<EulerAngles>, System.ValueTuple<System.Nullable<Units.Temperature>>>>

The latest sensor reading

StartUpdating(Nullable<TimeSpan>)

Start updating

Declaration
public override void StartUpdating(TimeSpan? updateInterval = null)

Parameters

Type Name Description
System.Nullable<TimeSpan> updateInterval

The time between updates

StopUpdating()

Stop reading data

Declaration
public override void StopUpdating()

Events

Acceleration3DUpdated

Raised when the acceleration value changes

Declaration
public event EventHandler<IChangeResult<Acceleration3D>> Acceleration3DUpdated

Event Type

Type Description
EventHandler<IChangeResult<Acceleration3D>>

AngularVelocity3DUpdated

Raised when the angular velocity value changes

Declaration
public event EventHandler<IChangeResult<AngularVelocity3D>> AngularVelocity3DUpdated

Event Type

Type Description
EventHandler<IChangeResult<AngularVelocity3D>>

EulerOrientationUpdated

Raised when the euler orientation value changes

Declaration
public event EventHandler<IChangeResult<EulerAngles>> EulerOrientationUpdated

Event Type

Type Description
EventHandler<IChangeResult<EulerAngles>>

GravityVectorUpdated

Raised when the gravity vector acceleration value changes

Declaration
public event EventHandler<IChangeResult<Acceleration3D>> GravityVectorUpdated

Event Type

Type Description
EventHandler<IChangeResult<Acceleration3D>>

LinearAccelerationUpdated

Raised when the linear acceleration value changes

Declaration
public event EventHandler<IChangeResult<Acceleration3D>> LinearAccelerationUpdated

Event Type

Type Description
EventHandler<IChangeResult<Acceleration3D>>

MagneticField3DUpdated

Raised when the magetic field value changes

Declaration
public event EventHandler<IChangeResult<MagneticField3D>> MagneticField3DUpdated

Event Type

Type Description
EventHandler<IChangeResult<MagneticField3D>>

QuaternionOrientationUpdated

Raised when the quaernion orientation value changes

Declaration
public event EventHandler<IChangeResult<Quaternion>> QuaternionOrientationUpdated

Event Type

Type Description
EventHandler<IChangeResult<Quaternion>>

TemperatureUpdated

Raised when the temperature value changes

Declaration
public event EventHandler<IChangeResult<Units.Temperature>> TemperatureUpdated

Event Type

Type Description
EventHandler<IChangeResult<Units.Temperature>>