Main Content


Read magnetic field strength at current location of sensor



[data,timestamp] = readMagneticField(BNO055Sensor) returns the magnetic field strength in microtesla(µT) along x-, y-, and z- axes.


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.Magnetometer,'full')
        break; %If Magnetometer is calibrated proceed further

Read magnetic field strength data.

[data,timestamp] = readMagneticField(BNO055Sensor)
data = 1×3

    9.5625   18.1875   23.0625

timestamp = datetime datetime
   29-Jul-2019 15:00:24.753

Input Arguments

collapse all

BNO055 sensor connection, specified as an addon object.

Output Arguments

collapse all

Magnetic field strength data in microtesla(µT) along the x-,y-, and z- axes, returned as a 1-by-3 vector.

Data Types: double

The time at which MATLAB® receives magnetometer data, specified as a datetime.

Data Types: datetime

Introduced in R2019b