read
Read real-time sensor data at a specified rate
Add-On Required: This feature requires the MATLAB Support Package for Arduino Hardware add-on.
Syntax
Description
[
returns the sensor readings in sensorReadings
,overrun
] = read(sensorobj
)timetable
format. The
timetable
contains data read from the sensor associated with
time data. The number of rows in the timetable 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
. This syntax is applicable for all sensors.
[
returns matrices of acceleration, angular velocity, magnetic field, time stamps, and
overrun. The number of samples depends on the accelReadings
, gyroReadings
, magReadings
, timeStamps
, overrun
] = read(sensorobj
)SamplesPerRead
value specified while creating the sensor object. These output arguments are
returned only when the output format is set to matrix
. This
function signature is available only for the MPU9250
and
LSM9DS1
sensors.
[
returns matrices of acceleration, angular velocity, magnetic field, temperature,
time stamps, and overrun. The number of samples depends on the
accelReadings
, gyroReadings
, magReadings
, tempReadings
, timeStamps
, overrun
] = read(sensorobj
)SamplesPerRead
value specified while creating the sensor
object. These output arguments are returned only when the output format is set to
matrix
. This function signature is available only for the
ICM20948
sensor.
[
returns matrices of acceleration, angular velocity, time stamps, and overrun. The
number of samples depends on the accelReadings
, gyroReadings
, timeStamps
, overrun
] = read(sensorobj
)SamplesPerRead
value specified
while creating the sensor object. These output arguments are returned only when the
output format is set to matrix
. This function signature is
available only for the MPU6050
sensor.
[
returns matrices of acceleration, angular velocity, temperature, time stamps, and
overrun. The number of samples depends on the accelReadings
, gyroReadings
, tempReadings
, timeStamps
, overrun
] = read(sensorobj
)SamplesPerRead
value specified while creating the sensor object. These output arguments are
returned only when the output format is set to matrix
This
function signature is available only for the LSM6DS3
,
LSM6DS3H
, LSM6DSL
,
LSM6DSM
, LSM6DSR
,
LSM6DSO
, , and ADIS16505
sensors.
[
returns matrices of acceleration, magnetic field, temperature, time stamps, and
overrun. The number of samples depends on the accelReadings
, magReadings
, tempReadings
, timeStamps
, overrun
] = read(sensorobj
)SamplesPerRead
value specified while creating the sensor object. These output arguments are
returned only when the output format is set to matrix
. This
function signature is available only for the LSM303C
sensor.
[
returns matrices of acceleration, time stamps, and overrun. The number of samples
depends on the accelReadings
, timeStamps
, overrun
] = read(sensorobj
)SamplesPerRead
value specified while creating
the sensor object. These output arguments are returned only when the output format
is set to matrix
. This function signature is available only for
the ADXL34x
family of sensors connected using the
adxl345
object.
[
returns matrices of humidity, temperature, time stamps, and overrun. The number of
samples depends on the humidityReading
, tempReadings
, timeStamps
, overrun
] = read(sensorobj
)SamplesPerRead
value specified while
creating the sensor object. These output arguments are returned only when the output
format is set to matrix
. This function signature is available
only for the HTS221
sensor.
[
returns matrices of pressure, temperature, time stamps, and overrun. The number of
samples depends on the pressureReading
, tempReadings
, timeStamps
, overrun
] = read(sensorobj
)SamplesPerRead
value specified while
creating the sensor object. These output arguments are returned only when the output
format is set to matrix
. This function signature is available for
LPS22HB
and BMP280
sensors.
[
returns matrices of acceleration, temperature, time stamps, and overrun. The number
of samples depends on the accelReadings
, tempReadings
, timeStamps
, overrun
] = read(sensorobj
)SamplesPerRead
value specified while
creating the sensor object. These output arguments are returned only when the output
format is set to matrix
This function signature is available only
for the LIS3DH
,
Examples
Read Data from Sensor as a Timetable
Create an Arduino object and include the I2C library.
a = arduino('COM4', 'Uno', 'Libraries', 'I2C');
Create a sensor object with additional properties.
Note
The sample code and output in this example is for mpu9250
object. If you are using another sensor that supports
read
function, use the corresponding sensor
object.
sensorobj = mpu9250(a,'SampleRate',50,'SamplesPerRead',5,'ReadMode','Latest');
Read five samples of sensor data in datetime
format.
[sensorReadings,overrun] = read(sensorobj) sensorReadings = 5×3 timetable Time Acceleration AngularVelocity MagneticField ________________________ ________________________________ ______________________________________ ____________________________ 14-Dec-2018 15:01:34.832 -0.28261 0.30836 10.395 0.018968 -0.0050405 -0.0026529 8.4938 10.582 -17.051 14-Dec-2018 15:01:34.852 -0.28261 0.30836 10.395 0.018968 -0.0050405 -0.0026529 8.4938 10.582 -15.687 14-Dec-2018 15:01:34.872 -0.2874 0.31375 10.432 0.021356 0.001857 0.00026529 8.4938 9.8766 -17.051 14-Dec-2018 15:01:34.892 -0.29339 0.30896 10.327 0.020427 -0.0013265 -0.00013265 8.4938 10.582 -17.733 14-Dec-2018 15:01:34.912 -0.29339 0.30896 10.327 0.020427 -0.0013265 -0.00013265 7.0781 9.1711 -17.733 overrun = 0
Read Accel, Gyro, and Mag Data from Sensor as a Matrix
Create an Arduino object and include the I2C library.
a = arduino('COM4', 'Uno', 'Libraries', 'I2C');
Create a sensor object with additional properties.
Note
The sample code and output in this example is for mpu9250
object. If you are using another sensor that supports this syntax of
read
function, use the corresponding sensor
object.
sensorobj = mpu9250(a,'OutputFormat', 'matrix', 'SamplesPerRead', 2);
Read two samples of sensor data in matrix
format.
[accel, gyro, mag, timeStamps, overrun] = sensorobj.read accel = -0.6239 1.2747 9.5986 -0.6263 1.2730 9.5861 gyro = 0.0114 -0.0397 0.0155 0.0106 -0.0382 0.0147 mag = 41.0133 101.0625 -13.1813 40.2937 100.3406 -13.8750 timestamps = 2×1 datetime array 4-Feb-2021 15:53:18.790 4-Feb-2021 15:53:18.800 overrun = 5
Read Accel and Gyro Data from Sensor as a Matrix
Create an Arduino object and include the I2C library.
a = arduino('COM4', 'Uno', 'Libraries', 'I2C');
Create a sensor object with additional properties.
Note
The sample code and output in this example is for mpu6050
object. If you are using another sensor that supports this syntax of
read
function, use the corresponding sensor
object.
sensorobj = mpu6050(a,'OutputFormat', 'matrix', 'SamplesPerRead', 2);
Read two samples of sensor data in matrix
format.
[accel, gyro, timeStamps, overrun] = sensorobj.read accel = -0.6239 1.2747 9.5986 -0.6263 1.2730 9.5861 gyro = 0.0114 -0.0397 0.0155 0.0106 -0.0382 0.0147 timestamps = 2×1 datetime array 4-Feb-2021 15:53:18.790 4-Feb-2021 15:53:18.800 overrun = 5
Input Arguments
Output Arguments
More About
Version History
Introduced in R2019a