1. Compass syntax

This module lets you access the built-in electronic compass. Before using, the compass should be calibrated, otherwise the readings may be wrong.

Tip

Calibrating the compass will cause your program to pause until calibration is complete.
Calibration consists of tilting the microbit to fill the LED display.

1.1. Main Functions

compass.calibrate()

Starts the calibration process. A message ‘TILT TO FILL SCREEN’ will be scrolled to the user after which the user will need to tilt the microbit to fill the LED display.

compass.heading()

Gives the compass heading, calculated from the above readings, as an integer in the range from 0 to 360, representing the angle in degrees, clockwise, with north as 0.

../_images/compass_angles.jpg

1.2. Other Functions

compass.is_calibrated()

Returns True if the compass has been successfully calibrated, and returns False otherwise.

compass.clear_calibration()

Undoes the calibration, making the compass uncalibrated again.

compass.get_x()

Gives the reading of the magnetic field strength on the x axis in nano tesla, as a positive or negative integer, depending on the direction of the field.

compass.get_y()

Gives the reading of the magnetic field strength on the y axis in nano tesla, as a positive or negative integer, depending on the direction of the field.

compass.get_z()

Gives the reading of the magnetic field strength on the z axis in nano tesla, as a positive or negative integer, depending on the direction of the field.

compass.get_field_strength()

Returns an integer indication of the magnitude of the magnetic field around the device in nano tesla.