Main Content

readAcceleration

Read one sample of acceleration from BNO055 sensor

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

Description

example

[accelReadings,timestamp] = readAcceleration(bno055) returns acceleration along x, y, and z axes of the BNO055 sensor as a 3-by-1 vector in units of m/s2 along with the timestamp. In ndof mode, the elements of the vector represent calibrated values, whereas in amg mode, the elements represent raw values.

Examples

Read Acceleration Data from Sensor in NDOF Mode

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

tic; 
while (toc < 120)
    [status,timestamp] = readCalibrationStatus(imu); 
    if strcmpi(status.Accelerometer,'full')
        break; %Accelerometer is calibrated proceed further
    end
    pause(1);
end

Read acceleration data.

[accelReadings,timestamp]  = readAcceleration(imu)
accelReadings = 1×3

   -1.4600    0.4300   -9.6000

timestamp = datetime
   21-Jul-2020 15:47:59.835

Read Acceleration Data from Sensor in AMG Mode

Create an arduino object

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

Create the BNO055 sensor object.

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

Read acceleration data.

accelReadings  = readAcceleration(imu)
accelReadings =

   -0.7023    0.1317   10.3968

Input Arguments

collapse all

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

Output Arguments

collapse all

The acceleration values along x, y, and z axes of the sensor as a 3-by-1 vector. In ndof mode, the elements of the vector represent calibrated values, whereas in amg mode, the elements represent raw values.

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

More About

collapse all

Code Generation Using MATLAB Function Block

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

  • Timestamp returned is always in seconds.

  • readAcceleration returns raw values of the acceleration 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 R2019a