The micro:bit has a built-in compass. This compass has to be calibrated the first time that it is used, so that the readings that it produces are accurate.


The micro:bit compass is configured to be used in a horizontal orientation, just like an analog compass. The calibration on the V2 device is a little more sensitive, so it is important to calibrate the device slowly, from a horizontal position and leave some time once the program is running to let the values settle, for example adding a pause after the calibration routine completes and/or between readings.


When you load a program into the micro:bit and your program tries to read from the compass, it will scroll the words TILT TO FILL SCREEN on the screen. Hold the micro:bit horizontally and tilt it on the spot trying to fill in the screen. After you have done this, your program will run.





The calibration routine runs in the background whilst the letters scroll across the screen, so it is possible to start tilting before the words finish scrolling. This speeds up the calibration routine.


Calibration tips

Make sure that you calibrate your compass in the same environment where you will be using it, to get the best accuracy. For example, if you are using it in a classroom, calibrate it in the classroom. If you are using an accessory, or a battery pack make sure they are also attached when you run the routine.


Also, because the magnetometer is sensitive to magnetic fields, you should avoid attaching the micro:bit to any metal objects or rest it on a metal table, as this will affect both the calibration and the accuracy of the reading in normal use. 


If you are using a very strong magnet with the micro:bit, you may need to recalibrate it between activities. The "maximum exposed field value" for the magnetometer is 10,000 gauss (1Tesla). To put this in perspective, a fridge magnet is about 0.001 Tesla and a Scrap yard magnet about 1 Tesla.


MakeCode Editor

When flashing a hex from the MakeCode editor, the compass calibration is stored in memory, so next time you press the reset button or remove and replace the power to the micro:bit it will remember the calibration. 

However, this memory is cleared when you flash a new program to your micro:bit, so you will have to re-calibrate it if you drag and drop a new program via USB. If you use direct flashing to update the micro:bit, you will only update the part of the program that changes, so you will not need to calibrate each time.


If you would like to initiate a calibration from your program, include the Calibrate Compass block


Python Editor

In the python.microbit.org editor the compass calibration is also stored in memory and will persist between resets, but direct flashing from the Python Editor will always clear the calibration data and the compass will have to be re-calibrated.


When the codewith.mu editor is used to flash the micro:bit it might do so using one of two different methods. The first time the micro:bit is flashed it will copy the hex file into the MICROBIT USB drive, and that will clear the calibration data. Subsequent flashes might only transfer the Python code via serial connection, and in that case the calibration data will persist.


If you would like to initiate a calibration from your Python program include the code
compass.calibrate()