Main Content

readMagneticField

Read the magnetic field measured by the Magnetometer along the x, y and z axis

Add-On Required: This feature requires the MATLAB Support Package for Raspberry Pi Hardware add-on.

Description

magField = readMagneticField(mysh) returns the magnetic field measured by the Magnetometer along the x, y, and the z axes.

The unit of measurement for the Magnetometer raw data is microtesla (µT).

example

[magField,Ts] = readMagneticField(mysh) returns the magnetic field measured by the Magnetometer along the x, y, and the z axes with timestamp. The unit of measurement for the Magnetometer field is microtesla (µT).

example

magField = readMagneticField(mysh,raw) returns the magnetic field measured by the Magnetometer along the x, y, and the z axes. The ‘raw’ argument is to specify that the output should be uncalibrated raw data.

example

[magField,Ts]= readMagneticField(mysh,raw) returns the magnetic field measured by the Magnetometer along the x, y, and the z axes with timestamp. The ‘raw’ argument is to specify that the output should be uncalibrated raw data.

The full scale range for the Magnetometer is +/- 4 gauss.

Sense HAT IMU sensor axis information is shown below.

example

Examples

collapse all

To read the magnetic field along the x, y, and the z axis.

magField = readMagneticField(mysh) 
magField =  

      -0.3045    0.2769   10.0417 

Read the magnetic field measured by the Magnetometer along the x, y, and the z axis.

To read the magnetic field along the x, y, and the z axes measured by the Magnetometer along with the time stamp at which the data was read.

[magField,ts] = readMagneticField(mysh)  
magField= 

 -0.1847    0.5511    0.1847 

ts =  

   09-Aug-2016 15:37:19  

Read the magnetic field measured by the Magnetometer along the x, y, and the z axis with timestamp.

To read raw uncalibrated magnetic field along the x, y, and the z axis.

magFieldRaw = readMagneticField(mysensehat,'raw')
magFieldRaw = 

         865       -1189        2002 

Read the raw uncalibrated magnetic field value measured by the Magnetometer along the x, y, and the z axis.

To read raw uncalibrated magnetic field along the x, y, and the z axis.

[magFieldRaw,ts] = readMagneticField(mysensehat,'raw') 
magFieldRaw= 

         865       -1189        2002 

ts = 

  09-Aug-2016 15:37:19 
 

Read the raw uncalibrated magnetic field value measured by the Magnetometer along the x, y, and the z axis with the timestamp.

Input Arguments

collapse all

Connection to a SenseHAT board, specified as a sensehat object.

Argument to specify that the output should be uncalibrated raw data.

Output Arguments

collapse all

The magnetic field measured by the Magnetometer along the x,y, and z axes. This is a 1x3 double data. The unit of measurement for the Magnetometer data is microtesla (µT).

Time at which the data is read.

Extended Capabilities

Version History

Introduced in R2016b