readAcceleration
Read one sample of acceleration from sensor
Add-On Required: This feature requires the MATLAB Support Package for Arduino Hardware add-on.
Description
[
returns one sample of the acceleration data on x, y, and z axes read from the sensor
in units of m/s2 along with the
accelReadings
,timestamp
] = readAcceleration(sensorobj
)timestamp
. Timestamp
is optional.
Note
The readAcceleration
function is available for the
LSM6DS3
, LSM6DS3H
,
LSM6DSL
, LSM6DSM
,
LSM6DSR
, LSM6DSO
,
MPU6050
, MPU9250
,
LSM9DS1
, LSM303C
,
ICM20948
, ADXL345
,
LIS3Dh
, and ADIS16505
sensors.
Examples
Read Acceleration from Sensor
Note
Required libraries must be flashed to arduino object before using the sensor. For example, to read data from MPU6050 sensor using mpu6050 object, I2C library is required. Similarly, for the ADIS16505 sensor, SPI library is required. To flash the arduino with required libraries use the Libraries Name-Value Pair arguments during arduino object creation.
Create an Arduino object and include the I2C library.
a = arduino();
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 for the sensor in use.
Note
The sample code and output in this example is for mpu9250
object. If you are using another sensor that supports
readAcceleration
function, use the corresponding
sensor object.
sensorobj = mpu9250(a);
Return one sample of acceleration data.
accelReadings = readAcceleration(sensorobj) accelReadings = -0.7023 0.1317 10.3968
Input Arguments
Output Arguments
More About
Version History
Introduced in R2019a