Main Content


Read orientation data from BNO055 sensor

Since R2019b

Add-On Required: This feature requires the MATLAB Support Package for Arduino Hardware add-on.



[readVal,timestamp] = readOrientation(bno055) returns the Euler angles that is the azimuth, pitch and roll of the BNO055 sensor in ndof operating mode.


Read Orientation from Sensor

Create an arduino object

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

Create the BNO055 sensor object.

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

Calibrate the sensor using steps mentioned in Calibrate BNO055 Sensors

while (toc < 120)
    [status,timestamp] = readCalibrationStatus(imu); 
    if strcmpi(status.System,'full') && strcmpi(status.Magnetometer,'full') && strcmpi(status.Accelerometer,'full') && strcmpi(status.Gyroscope,'full')
        break; %System is calibrated proceed further

Read orientation data.

[readVal,timestamp]  = readOrientation(imu)
readVal = 3×1

    6.2046    3.0729   -0.3011

timestamp = datetime datetime
   21-Jul-2020 14:09:57.615

Input Arguments

collapse all

BNO055 sensor object created in the ndof operating mode with the default or specified properties.

Output Arguments

collapse all

The following illustration shows the default orientation of the x-, y-, and z- axes of the BNO055 sensor.

Orientation of the sensor, returned as a 3-by-1 vector. The elements of the vector represent the orientation using three angular quantities in radians - azimuth (rotation around z- axis), roll (rotation around y- axis), and pitch (rotation around x- axis) of the sensor.

Angular QuantityDescriptionRange in Radians
AzimuthAngle between y- axis of the sensor and magnetic north[0,2pi]
PitchAngle between z- axis and y- axis of the sensor[-pi,pi]
RollAngle between z- axis and x- axis of the sensor[-pi/2,pi/2]

Data Types: double

The time at which MATLAB® receives the orientation from the sensor, specified as a datetime.

Data Types: datetime

More About

collapse all

Code Generation Using MATLAB Function Block

  • Use readOrientation in a MATLAB Function block with the Simulink® Support Package for Arduino® Hardware to generate code that can be deployed on Arduino Hardware.

  • readOrientation returns zeroes if the sensor is not calibrated. Ensure you calibrate the sensor before using it in the ndof operating mode. See Calibrate BNO055 Sensors for the steps.

Version History

Introduced in R2019b