In this post
Why a pen carries a compass at all
Gravity, read through the accelerometers, reveals two of the three angles of the pen's orientation, how it tilts. The third angle, which way it points on the horizontal plane, is invisible to gravity. That is the magnetometer's one job: anchor the heading. Without it, the heading estimate can only come from integrating rotation, and anything integrated drifts.
The two flavours of magnetic lying
Magnetic interference comes in two flavours with useful names. Hard-iron distortion is a constant bias, something magnetised near the sensor adds a fixed push. Soft-iron distortion is direction-dependent, nearby ferrous material bends the field differently as the pen rotates. There is also the plain ambush: the writer sets the pen down next to a laptop whose speaker magnet swamps Earth's field entirely.
Calibration you can picture
Rotate a perfect magnetometer through every orientation and its readings trace a sphere centred at zero. Hard-iron bias shifts that sphere off-centre; soft-iron distortion squashes it into an ellipsoid. Calibration is the act of measuring that shifted, squashed shape and computing the correction that restores the centred sphere. It is geometry, honest and checkable, and it is redone over time because the pen's own magnetic environment can change.
Trust, but verify continuously
Calibration cannot fix the laptop ambush, so the firmware never trusts the compass blindly. The magnetic reading is continuously checked for plausibility, is its strength near Earth's field, is it stable, does it agree with what the gyroscope says about rotation? When checks fail, the compass is quietly ignored and heading rides on the gyroscope until sanity returns. The rule of thumb: the magnetometer corrects slowly, or not at all.
Key takeaways
- The compass anchors the one orientation angle gravity cannot see.
- Hard-iron bias shifts readings; soft-iron distortion bends them by direction.
- Calibration restores the centred sphere and is refreshed over the pen's life.
- Plausibility checks demote the compass instantly when the desk lies.
A sensor you sometimes ignore, on purpose, with criteria, is worth far more than a sensor you always believe.