readMagneticField
Read one sample of magnetic field from sensor
Add-On Required: This feature requires the MATLAB Support Package for Arduino Hardware add-on.
Description
[
returns one sample of the magnetic field data on x, y, and z axes read from the
sensor in units of µT (microtesla) along with the magReadings
,timestamp
] = readMagneticField(sensorobj
)timestamp
.
Timestamp
is optional.
Note
The readMagneticField
function is available for the
MPU9250
, LSM9DS1
,
LSM303C
, and ICM20948
sensors.
Examples
Read Magnetic Field
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
readMagneticField
function, use the corresponding
sensor object.
sensorobj = mpu9250(a);
Return one sample of magnetic field data.
magReadings = readMagneticField(sensorobj) magReadings = 16.2797 9.1711 -19.0969
Input Arguments
Output Arguments
More About
Version History
Introduced in R2019a