Why Your micro:bit Asks to Calibrate the Compass Every Single Lesson

The micro:bit forces its calibration mini-game because magnetometer offsets vanish on power-down, while steel-framed school desks immediately distort the local magnetic field. Here is how to fix it in MakeCode and MicroPython.
The micro:bit demands calibration at the start of a lesson for two combined reasons: the magnetometer calibration data is stored only in volatile memory (RAM), which wipes the moment the board is unplugged, and the runtime automatically halts execution to run the calibration routine the first time your code requests a heading from an uncalibrated sensor. In a school environment, this is compounded by classroom furniture: standard steel-frame school desks and adjacent computing equipment distort the local geomagnetic field, ensuring that any uncalibrated reading is wildly inaccurate.
Why School Desks Break Magnetometer Readings
The micro:bit uses a combined accelerometer and magnetometer chip (such as the LSM303 or FXOS8700 on v1 boards, or the LSM303AGR on v2). A magnetometer measures the strength and direction of magnetic fields along three orthogonal axes. On an open sports field, the primary field measured is Earth's geomagnetic field (roughly 30 to 60 microteslas).
In a standard South African classroom, however, learners sit at desks built from mild tubular steel, often directly above reinforced concrete floor slabs containing steel rebar. Nearby laptops, monitor power bricks, and charging trolleys create active electromagnetic fields. These produce two types of magnetic distortion:
- Hard iron distortion: Permanent magnets or magnetised steel objects nearby produce a constant offset that shifts the entire magnetic circle away from the origin (0, 0, 0).
- Soft iron distortion: Ferromagnetic materials (like the mild steel desk frame) warp and squeeze the Earth's magnetic field lines, turning what should be a spherical measurement plot into an asymmetrical ellipsoid.
When the micro:bit boots up fresh, its internal calibration matrix is blank. As soon as a line of code asks for compass heading or compass.heading(), the micro:bit runtime checks if a valid calibration matrix exists. Finding none, it freezes your script and launches the mandatory tilt routine (drawing a circle or filling the 5x5 LED matrix) to calculate the hard and soft iron compensation offsets.
The Power-Cycle Problem in the Classroom
Because the default runtime stores calibration data only in RAM, every time a learner unplugs their micro:bit from a USB port or toggles a battery pack, the offsets vanish. If your lesson involves 30 learners repeatedly editing code, flashing it via USB, and running it, the board power-cycles on every flash. That triggers up to thirty calibration sequences per learner in a single 45-minute period.
Worse, if a learner completes the calibration while waving the micro:bit in the air at chest height, and then places the board back down 5 centimetres away from a steel desk strut, the magnetic field changes drastically. The micro:bit does not automatically realise the baseline shifted unless the runtime detects an outright invalid field vector, resulting in inaccurate bearings or erratic compass needles.
Bypassing and Controlling Calibration in MakeCode
In Microsoft MakeCode, the block compass heading (°) contains a built-in check: if the magnetometer is uncalibrated, it invokes input.calibrateCompass() automatically. You have three ways to manage this behavior depending on your lesson goals.
1. If absolute bearing is NOT required: Use the Accelerometer instead
If you are teaching basic inputs, tilt controls, or simple direction (e.g. steering a buggy left or right), you almost certainly do not need the magnetometer. Teachers often use compass heading when they actually want tilt or yaw. Using rotation (pitch/roll) or acceleration avoids the compass subsystem entirely and never triggers a calibration screen.
2. Calibrate once explicitly in `on start`
If your project genuinely requires a compass (such as orienteering or navigation), call the calibration explicitly inside the on start block rather than letting it trigger unexpectedly mid-loop:
input.calibrateCompass()Instruct learners to stand up, hold the micro:bit away from their bodies, and complete the tilt routine in free air before sitting down. This prevents the calibration game from interrupting the main logic loop while testing.
Managing Calibration in MicroPython
In MicroPython, you have far more granular control over the sensor lifecycle. You can check calibration status, calibrate non-interactively, or even inject hard-coded offsets.
Preventing the blocking calibration screen
By default, calling compass.heading() in MicroPython will raise the calibration routine if compass.is_calibrated() returns False. You can guard against unexpected blocking by checking the status explicitly:
import compass
if not compass.is_calibrated():
compass.calibrate()
while True:
heading = compass.heading()
# Project logic hereManually supplying calibration data
If your learners are working in a fixed lab setup and you want to completely eliminate the tilt game during iterative coding, you can determine baseline offsets once, write them to non-volatile storage (the micro:bit internal flash file system), and load them on boot. MicroPython provides low-level access via compass.get_field_strength() and calibration configuration methods to set the offset values directly, skipping the tilt sequence entirely.
Practical Classroom Protocol
To keep a robotics or coding class running smoothly without losing ten minutes to tilting boards:
- Keep boards away from desk frames: Maintain at least 15 to 20 cm of clearance between the micro:bit and any steel structural legs, desk mounts, or monitor bases.
- Do not calibrate flat on the table: If a micro:bit is calibrated while resting on a steel desk, it calibrates to the desk's magnetic anomaly. The moment the learner picks it up to walk around, the heading will be wrong. Always calibrate at waist or chest height in open air.
- Evaluate if you need absolute North: For 80% of introductory classroom challenges—like line following, obstacle avoidance, or tilt-controlled games—the magnetometer is the wrong sensor. Use the inertial measurement unit (accelerometer) instead.
For structured robotics modules, hardware reference designs, and lesson kits configured for South African classroom conditions, explore the teaching guides on Sheen Canvas or review our professional development workshops on Sheen Academy.



