Main Content

read

Read acceleration, angular velocity, magnetic field, time, and overrun data from BNO055 sensor

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

Description

[sensorReadings,overrun] = read(bno055) returns the acceleration, magnetic field, angular velocity, and overrun data from BNO055 in the timetable format. The number of samples depends on the SamplesPerRead value specified while creating the sensor object. These output arguments are returned only when the output format is set to timetable.

example

[accelReadings, gyroReadings, magReadings, timeStamps, overrun] = read(bno055) returns matrices of acceleration, gyroscope, magnetic field, orientation, time stamps, and overrun data in AMG mode. The number of samples depends on the SamplesPerRead value specified while creating the sensor object. These output arguments are returned only when the output format is set to matrix.

example

[accelReadings, gyroReadings, magReadings, orientationReadings,timeStamps, overrun] = read(bno055) returns matrices of acceleration, gyroscope, magnetic field, time stamps, and overrun data in NDOF mode. The number of samples depends on the SamplesPerRead value specified while creating the sensor object. These output arguments are returned only when the output format is set to matrix.Calibrate BNO055 Sensors before using the read to ensure accurate values are read from sensor in NDOF operating mode.

example

Examples

Read Data from Sensor in NDOF Mode as a Timetable

Create an arduino object.

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

Create a sensor object with additional properties.

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

Calibrate the sensor using steps mentioned in Calibrate BNO055 Sensors. Read five samples of sensor data in datetime format.

sensorReadings = read(imu)
sensorReadings =

 5×4 timetable

              Time                   Acceleration                     AngularVelocity                       MagneticField                    Orientation        
    ________________________    _______________________    ______________________________________    ____________________________    ___________________________

    21-Jul-2020 16:24:25.538        0     0.35     9.82     0.0032725    -0.0054542    -0.0021817     24.25    -19.375      -2.75    0    -0.035997    0.0021817
    21-Jul-2020 16:24:25.548    -0.05     0.32     9.84    -0.0021817     0.0010908     0.0010908     24.25    -19.375      -2.75    0    -0.035997    0.0021817
    21-Jul-2020 16:24:25.558    -0.03     0.32     9.75    -0.0010908     0.0010908    -0.0010908     24.25    -19.375      -2.75    0    -0.035997    0.0021817
    21-Jul-2020 16:24:25.568        0     0.34     9.82     0.0010908    -0.0021817             0     24.25    -19.375      -2.75    0    -0.035997    0.0021817
    21-Jul-2020 16:24:25.578        0     0.36     9.77      0.006545    -0.0010908    -0.0021817    23.063    -20.188    -3.5625    0    -0.035997    0.0021817
	

Read Data from Sensor in AMG Mode as a Timetable

Create an arduino object.

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

Create a sensor object with additional properties.

imu = bno055(a,'OperatingMode','amg','SampleRate',100,'SamplesPerRead',5)

Read five samples of sensor data in datetime format.

sensorReadings = read(imu)
sensorReadings =

 5×3 timetable

              Time                   Acceleration                     AngularVelocity                       MagneticField        
    ________________________    _______________________    ______________________________________    ____________________________

    21-Jul-2020 16:29:51.323    -0.02     0.32     9.87     0.0032725      -0.01309     0.0021817     24.25    -18.375         -4
    21-Jul-2020 16:29:51.333    -0.02     0.32     9.87     0.0032725    -0.0032725     0.0021817     24.25    -18.375         -4
    21-Jul-2020 16:29:51.343     0.02     0.35     9.82    -0.0032725     0.0076358     0.0032725     24.25    -18.375         -4
    21-Jul-2020 16:29:51.353     0.02     0.35     9.82    -0.0032725     0.0021817     0.0010908    23.125    -19.438         -4
    21-Jul-2020 16:29:51.363    -0.03     0.32     9.86             0    -0.0098175     0.0010908    23.125    -19.438         -4

Read Data from Sensor in NDOF Mode as a Matrix

Create an arduino object.

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

Create a sensor object with additional properties.

imu = bno055(a,’SamplesPerRead’,5,’OutputFormat’,’matrix’,’OperatingMode’,’ndof’)

Calibrate the sensor using steps mentioned in Calibrate BNO055 Sensors. Read five samples of sensor data as a matrix.

[accelReadings, gyroReadings, magReadings, orientationReadings,timeStamps, overrun] = read(imu)
accelReadings =

   -0.0400    0.3000    9.7500
   -0.0500    0.3100    9.8400
   -0.0200    0.3300    9.8100
         0    0.3400    9.8800
   -0.0400    0.3200    9.7700


gyroReadings =

         0    0.0098   -0.0011
   -0.0022    0.0055    0.0011
    0.0022   -0.0022         0
   -0.0011   -0.0022    0.0011
   -0.0022   -0.0022   -0.0011


magReadings =

   23.8750  -20.5625   -4.0000
   23.8750  -20.5625   -4.0000
   23.8750  -20.5625   -4.0000
   23.0625  -20.8750   -4.7500
   23.0625  -20.8750   -4.7500


orientationReadings =

         0   -0.0338    0.0022
         0   -0.0338    0.0022
         0   -0.0338    0.0022
         0   -0.0338    0.0022
         0   -0.0338    0.0022


timeStamps = 

  5×1 datetime array

   31-Jul-2020 19:10:07.196
   31-Jul-2020 19:10:07.206
   31-Jul-2020 19:10:07.216
   31-Jul-2020 19:10:07.226
   31-Jul-2020 19:10:07.236


overrun =

     10    
	

Read Data from Sensor in AMG Mode as a Matrix

Create an arduino object.

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

Create a sensor object with additional properties.

imu = bno055(a,’SamplesPerRead’,5,’OutputFormat’,’matrix’,’OperatingMode’,’amg’)

Read five samples of sensor data as a matrix.

[accelReadings, gyroReadings, magReadings, orientationReadings,timeStamps, overrun] = read(imu)
accelReadings =

   -0.0400    0.3000    9.7500
   -0.0500    0.3100    9.8400
   -0.0200    0.3300    9.8100
         0    0.3400    9.8800
   -0.0400    0.3200    9.7700


gyroReadings =

         0    0.0098   -0.0011
   -0.0022    0.0055    0.0011
    0.0022   -0.0022         0
   -0.0011   -0.0022    0.0011
   -0.0022   -0.0022   -0.0011


magReadings =

   23.8750  -20.5625   -4.0000
   23.8750  -20.5625   -4.0000
   23.8750  -20.5625   -4.0000
   23.0625  -20.8750   -4.7500
   23.0625  -20.8750   -4.7500


timeStamps = 

  5×1 datetime array

   31-Jul-2020 19:10:07.196
   31-Jul-2020 19:10:07.206
   31-Jul-2020 19:10:07.216
   31-Jul-2020 19:10:07.226
   31-Jul-2020 19:10:07.236


overrun =

     10    
	

Input Arguments

collapse all

BNO055 sensor object with the default or specified properties.

Output Arguments

collapse all

Acceleration, angular velocity, and magnetic field data read from the sensor when the output format is set to timetable. In the ndof operating mode, the orientation values of the sensor is also returned. The timetable 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

Data Types: timetable

The discarded number of data samples between the previous read and the current read is the overrun. The overrun is zero when ReadMode is set to oldest.

Data Types: single | double

Acceleration in m/s2 read from the sensor on x, y and z axis. N is the number of samples in the current frame.

Data Types: double

Angular velocity in rad/s read from the sensor on x, y and z axis. N is the number of samples in the current frame.

Data Types: double

Magnetic field in µT (microtesla) read from the sensor on x, y and z axis. N is the number of samples in the current frame.

Data Types: double

Orientation in radians read from the sensor along x, y and z axis. N is the number of samples in the current frame.

Data Types: double

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 first call of the read function or the last execution of the release function.

More About

collapse all

Code Generation Using MATLAB Function Block

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

  • read does not return overrun.

  • read always returns matrices.

Version History

Introduced in R2019a