Read orientation data from BNO055 sensor
Read Orientation from Sensor
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
tic; 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 end end
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
bno055 — BNO055 sensor object
BNO055 sensor object created in the
ndof operating mode
with the default or specified properties.
readVal — Orientation data
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 Quantity||Description||Range in Radians|
|Azimuth||Angle between y- axis of the sensor and magnetic north||[|
|Pitch||Angle between z- axis and y- axis of the sensor||[|
|Roll||Angle between z- axis and x- axis of the sensor||[|
timestamp — Timestamp
The time at which MATLAB® receives the orientation from the sensor, specified as a datetime.
Code Generation Using MATLAB Function Block
readOrientationin a MATLAB Function block with the Simulink® Support Package for Arduino® Hardware to generate code that can be deployed on Arduino Hardware.
readOrientationreturns zeroes if the sensor is not calibrated. Ensure you calibrate the sensor before using it in the
ndofoperating mode. See Calibrate BNO055 Sensors for the steps.