This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Read data from the magnetometer sensor on BBC micro:bit board


[data] = readMagneticField(obj)



[data] = readMagneticField(obj) reads data from the Magnetometer sensor connected to the BBC micro:bit board, specified as a microbit object.


collapse all

Create a connection to the BBC micro:bit hardware connected to the COM4 port., and read the magnetic field along the three axes of the BBC micro:bit hardware.

>>m = microbit('COM4');
>>[data] = readMagneticField(m)

data = 

   -33.2 -9.8 -134.8

Input Arguments

collapse all

BBC micro:bit hardware connection, specified as a microbit object, created with the microbit function.

Output Arguments

collapse all

Three-dimensional data of the surrounding magnetic field intensity. The data is measured along the x-, y-, and z- axes, relative to the position of the board.

Data Types: double

Introduced in R2017b