Main Content

bno055

Connect to BNO055 sensor on Arduino hardware I2C bus

Description

The bno055 object reads acceleration, angular velocity, magnetic field, and orientation in the specified mode of the BNO055 inertial measurement unit (IMU) sensor connected to the Arduino® hardware. The BNO055 is a 9 degree of freedom (DOF) inertial measurement unit (IMU) used to read acceleration, angular velocity, and magnetic field in all three dimensions.

The bno0055 object represents a connection to the device on the Arduino hardware I2C bus. Attach an BNO055 sensor to the I2C pins on the Arduino hardware. You can read the data from your sensor in MATLAB® using the object functions.

Before you use the bno055 object, create an arduino object with the I2C library. For more information, see Connect to Arduino Hardware.

Creation

Description

imu = bno055(a) creates a BNO055 sensor object with default property values. The object represents the connection to the sensor on the Arduino hardware, a.

imu = bno055(a,Name,Value) creates a BNO055 sensor object with properties using one or more Name,Value pair arguments.

Input Arguments

expand all

Connection to the Arduino hardware created using arduino. Ensure the arduino object is created with the 'I2C' library.

Example: imu = bno055(a) creates a connection to the BNO055 sensor on the Arduino object, a.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Configure the BNO055 sensor to output sensor data in NDOF or AMG mode.

When you set the operating mode to ndof, the sensor operates in NDOF. In this mode you can read calibrated values of acceleration, angular velocity and magnetic field along with Euler angles, and calibration status of the sensor.

When you set operating mode to amg, the sensor operates in Accelerometer Magnetometer Gyroscope (AMG) mode. In this mode you can read raw values of acceleration, angular velocity and magnetic field.

Example: imu = bno055(a,'OperatingMode', ‘ndof’);

Data Types: string

Specify the I2C address of a sensor when multiple sensors are connected to the same hardware board. BNO055 can have two addresses depending on the logic level on COM3 pin of the sensor. If 'COM3' is low, the address will be ‘0x28’. You can specify the I2C address in hexadecimal, decimal, or binary format.

Example: imu = bno055(a,'I2CAddress','0x28')

I2C bus number, specified as 0 or 1.

Example: imu = bno055(a, 'Bus', 1)

Data Types: double

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects.

Note

The properties SampleRate, SamplesPerRead, ReadMode, OutputFormat, TimeFormat, SamplesAvailable, and SamplesRead are available only with the Navigation Toolbox™ and Sensor Fusion and Tracking Toolbox™. These properties can be set while you create the sensor object.

The rate in Samples/s at which data is read from the sensor. In ndof mode, an internal fusion algorithm configures the bandwidth and ODR of the sensor with values from the data sheet. Hence SampleRate is fixed to 100. However, in amg mode SampleRate can be varied.

Tunable: No

Data Types: double

Number of samples read from the sensor in a single execution of the read function.

Tunable: No

Data Types: double

Specify whether to return the latest or the oldest data samples. The number of samples depends on the SamplesPerRead value. The data read from the sensor is stored in the MATLAB buffer.

  • latest

    Provides the latest data samples available in the buffer. All previous data samples in the buffer are discarded. For example, if SamplesPerRead = 3, the latest three data samples read by the sensor are returned.

    The following figure illustrates how latest data samples are returned assuming S1 is the first sensor data stored in the buffer, S2 is the second data and so on and Sn is the last data stored in the buffer and SamplesPerRead property is set to 3 during sensor object creation.

  • oldest

    Provides the oldest data samples available in the buffer. In this case, no data samples are discarded. For example, if SamplesPerRead = 3, the first three data samples read are returned for the first read, the next three data samples are returned for the second read, and so on.

    The following figure illustrates how oldest data samples are returned assuming S1 is the first sensor data stored in the buffer, S2 is the second data and so on and Sn is the last data stored in the buffer and SamplesPerRead property is set to 3 during sensor object creation.

Tunable: No

Data Types: character vector | string

This property is read-only.

Samples read from the first read. When you release the object, SamplesRead is set to 0.

Data Types: double

This property is read-only.

Samples available in the host buffer. When you release the object, SamplesAvailable is set to 0.

Data Types: double

Set the output format of the data returned by executing the read function.

When the OutputFormat is set to timetable, the data returned has the following fields:

  • Time — Time stamps in datetime or duration format

  • Acceleration — N-by-3 array in units of m/s2

  • AngularVelocity — N-by-3 array in units of rad/s

  • MagneticField — N-by-3 array in units of µT (microtesla)

  • Orientation — N-by-3 array in units of radians

When the OutputFormat is set to matrix, the data is returned as matrices of acceleration, angular velocity, magnetic field, and time stamps. The units for the sensor readings are the same as the timetable format. The size of each matrix is N-by-3.

N is the number of samples per read specified by SamplesPerRead. The three columns of each field represent the measurements in x, y, and z axes.

Tunable: No

Data Types: character vector | string

Set the format of the time displayed when the sensor data is read.

  • datetime — Displays the date and time at which the data is read.

  • duration — Displays the time elapsed in seconds after the sensor object is locked. The sensor object gets locked at the first call of the read function either after the object creation or after the execution of the release function.

Tunable: Yes

Data Types: character vector | string

Usage

Create Connection to BNO055 in NDOF Mode

Create an arduino object and include the I2C library.

a = arduino('COM4', 'Uno', 'Libraries', 'I2C');

Create the sensor object.

imu = bno055(a,'OperatingMode','ndof')
imu = 

  bno055 with properties: 

                      OperatingMode: "ndof" 

                         I2CAddress: 40 ("0x28")
                                Bus: 0 
                             SCLPin: "A5" 
                             SDAPin: "A4" 

Create Connection to BNO055 in NDOF Mode (with Navigation Toolbox or Sensor Fusion and Tracking Toolbox)

Create an arduino object and include the I2C library.

a = arduino('COM4', 'Uno', 'Libraries', 'I2C');

Create the sensor object.

imu = bno055(a,'OperatingMode','ndof','SamplesPerRead',5,'ReadMode','Latest')
imu = 

  bno055 with properties: 

                      OperatingMode: "ndof" 

                         I2CAddress: 40 ("0x28")
                                Bus: 0 
                             SCLPin: "A5" 
                             SDAPin: "A4" 

                         SampleRate: 100 (Samples/s)
                     SamplesPerRead: 5 
                           ReadMode: "latest"	 
                        SamplesRead: 0	 
                   SamplesAvailable: 0	 

Show all properties, functions

Create Connection to BNO055 in AMG Mode

Create an arduino object and include the I2C library.

a = arduino('COM4', 'Uno', 'Libraries', 'I2C');

Create a sensor object.

imu = bno055(a,'OperatingMode','amg')
imu = 

  bno055 with properties: 

                      OperatingMode: "amg" 

                         I2CAddress: 40 ("0x28")
                                Bus: 0 
                             SCLPin: "A5" 
                             SDAPin: "A4" 

Create Connection to BNO055 in AMG Mode (with Navigation Toolbox or Sensor Fusion and Tracking Toolbox)

Create an arduino object and include the I2C library.

a = arduino('COM4', 'Uno', 'Libraries', 'I2C');

Create a sensor object with properties available only with the Sensor Fusion and Tracking Toolbox.

imu = bno055(a,'OperatingMode','amg','SampleRate',50,'SamplesPerRead',5,'ReadMode','latest')
imu = 

  bno055 with properties: 

                      OperatingMode: "amg" 

                         I2CAddress: 40 ("0x28")
                                Bus: 0 
                             SCLPin: "A5" 
                             SDAPin: "A4" 

                         SampleRate: 50 (Samples/s)
                     SamplesPerRead: 5 
                           ReadMode: "latest"	 
                        SamplesRead: 0	 
                   SamplesAvailable: 0	 

Show all properties, functions

Object Functions

Use these functions to read the sensor data:

infoRead output data rate and bandwidth setting of sensor
readRead acceleration, angular velocity, magnetic field, time, and overrun data
readAccelerationRead one sample of acceleration from sensor
readAngularVelocityRead one sample of angular velocity from sensor
readCalibrationStatusRead calibration status of sensor
readMagneticFieldRead one sample of magnetic field strength from sensor
readOrientationRead orientation data from sensor
releaseRelease the BNO055 object
flushFlush the host buffer

More About

expand all

See Also

| |

Introduced in R2020a