Read one sample of magnetic field from sensor
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
timestamp] = readMagneticField(
Timestamp is optional.
readMagneticField function is available for the
Create an Arduino object and include the I2C library.
a = arduino();
Or, you can explicitly specify it in the
pair while creating the Arduino object.
clear a; a = arduino('COM4', 'Uno', 'Libraries', 'I2C');
Create the sensor object for the sensor in use.
The sample code and output in this example is for
object. If you are using another sensor that supports
readMagneticField function, use the corresponding
sensorobj = mpu9250(a);
Return one sample of magnetic field data.
magReadings = readMagneticField(sensorobj) magReadings = 16.2797 9.1711 -19.0969
sensorobj— Sensor object
The sensor object.
magReadings— Value read from the sensor
The magnetic field value on x, y, and z axes read from the sensor.
The time at which MATLAB® receives magnetic field data from the sensor, specified as a datetime.
readMagneticField 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.