All posts Technology

The magnetometer: direction, zeroing and a cleaner signal

In short

An accelerometer anchors tilt and a gyroscope tracks rotation, but together they slowly drift in heading, the compass direction the pen points. A magnetometer reads Earth's magnetic field to supply an absolute heading, which the system uses to zero out that drift and lock orientation.

It needs careful calibration to remove interference, but once clean it gives a stable, drift-free sense of direction, important for tracking the consistent left-to-right flow and stroke directions of the five Indic scripts.

The short version. The full post has the detail and the why.

In this post

  1. Why accelerometer + gyroscope isn't enough
  2. The compass that fixes heading
  3. Zeroing and calibration
  4. Direction for five scripts

Two of the pen's three orientation senses have a shared blind spot. The third, the magnetometer, exists to cover it, and to give the whole system a stable sense of which way is which.

Why accelerometer + gyroscope isn't enough

An accelerometer uses gravity to pin down two of the three orientation angles, pitch and roll, the pen's lean. But gravity says nothing about heading: rotate the pen flat on the desk like a clock hand and gravity doesn't change at all. The gyroscope can track that rotation, but only by integrating its rate over time, which slowly accumulates error. So heading drifts: after a while the system's idea of "forward" quietly rotates away from reality. Pitch and roll stay anchored by gravity; heading has nothing to anchor it.

The compass that fixes heading

The magnetometer is that missing anchor. It measures the direction of Earth's magnetic field, the same field a compass needle follows, which provides an absolute reference for heading. Fused with the accelerometer and gyroscope, it lets the system continually correct heading drift: the gyroscope supplies smooth short-term motion, the magnetometer supplies the steady long-term direction. Together the three give a full, stable orientation, often called a nine-axis or AHRS (attitude and heading reference) solution.

true N drifted magnetometer supplies absolute heading re-zeroed
Without a reference, heading slowly rotates away from true. The magnetometer's absolute compass reading snaps it back, keeping the pen's sense of direction honest.

Zeroing and calibration

A magnetometer is only as good as its calibration, because it's sensitive to more than Earth's field. Nearby metal and the pen's own electronics distort the reading in two classic ways:

  • Hard-iron effects, a fixed offset from magnetised materials near the sensor, which shift the whole field.
  • Soft-iron effects, which stretch and skew the field depending on orientation.

Calibration models and removes both, typically by observing the sensor through many orientations and fitting the data back to a sphere. On top of that, the system performs zeroing: establishing a known reference heading at a quiet moment so the rest of the session is measured against a clean baseline. Filtering then suppresses the remaining electromagnetic noise. Only after all of this does the magnetometer earn its place in the fusion, otherwise it would inject more error than it removes.

Direction for five scripts

Why does heading matter for handwriting? Because direction is meaning. Strokes have a correct orientation and order, and a page is written along a consistent line of progression. If the pen's sense of "forward" drifts, reconstructed strokes can rotate subtly relative to the page, blurring the geometry the analysis depends on.

For the five Indic scripts, Telugu, Kannada, Malayalam, Tamil and Devanagari (Hindi), this is especially delicate. They're written left to right, but each akshara is a tight construction of curves and strokes with their own directions, and Devanagari hangs from a continuous horizontal head-line whose straightness is part of correct form. A stable, well-zeroed heading keeps that baseline and those stroke directions consistent across a whole page, so the analyser measures real letterform quality rather than accumulated drift.

Key takeaways

  • Gravity anchors tilt, but heading has no anchor, so accelerometer + gyroscope drift in direction.
  • The magnetometer reads Earth's field to supply an absolute heading reference.
  • It must be calibrated (hard-iron, soft-iron) and zeroed before it can be trusted.
  • Stable heading keeps stroke directions and the Devanagari head-line consistent across a page of Indic script.

Read next