Read orientation data from sensor



[readVal,timestamp] = readOrientation(BNO055Sensor) returns the Euler angles that is the azimuth, pitch and roll of the sensor.


collapse all

Create an arduino object.

arduinoObj = arduino("COM7","MKR1000","Libraries","Adafruit/BNO055")
arduinoObj = 
  arduino with properties:

                  Port: 'COM7'
                 Board: 'MKR1000'
         AvailablePins: {'D0-D14', 'A0-A6'}
  AvailableDigitalPins: {'D0-D14', 'A0-A6'}
      AvailablePWMPins: {'D0-D8', 'D10', 'A3-A4'}
   AvailableAnalogPins: {'A0-A6'}
    AvailableI2CBusIDs: [0]
AvailableSerialPortIDs: [1]
             Libraries: {'Adafruit/BNO055', 'I2C'}

Create a BNO055Sensor object.

BNO055Sensor = addon(arduinoObj,'Adafruit/BNO055')
BNO055Sensor = 
  BNO055 with properties:

               SCLPin: 'D12'
               SDAPin: 'D11'
                  Bus: 0
           I2CAddress: 40 ('0x28')

Calibrate the sensor using steps mentioned in this Calibrate BNO055 Sensors.

while (toc < 120)
    [status,timestamp] = readCalibrationStatus(BNO055Sensor); 
    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(BNO055Sensor)
readVal = 1×3

    6.2046    3.0729   -0.3011

timestamp = datetime
   30-Jul-2019 14:09:57.615

Input Arguments

collapse all

BNO055 sensor connection, specified as an addon object.

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 1-by-3 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

Introduced in R2019b