This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Read one sample of acceleration from sensor


accelReadings = readAcceleration(imu)



accelReadings = readAcceleration(imu) returns one sample of the acceleration data on x, y, and z axes read from the sensor in units of m/s2.


Read Acceleration from Sensor

Create an Arduino object and include the I2C library.


Or, you can explicitly specify it in the Libraries Name-Value pair while creating the Arduino object.

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

Create the sensor object.

imu = mpu9250(a);

Return one sample of acceleration data.

accelReadings = readAcceleration(imu)

accelReadings =

   -0.7023    0.1317   10.3968

Input Arguments

collapse all

The IMU sensor object.

Output Arguments

collapse all

The acceleration value on x, y, and z axes read from the sensor.

Introduced in R2019a