🧠 Operating principle:

The prototype uses a Raspberry Pi Pico to run two BMI160 sensors mounted head-to-tail on a support driven by a NEMA-17 motor. By accumulating tens of thousands of measurements, It eliminates measurement bias through rapid reversal of the measurement direction. The use of dithering improves the resolution beyond the least significant bit (LSB). A five-state Kalman filter is applied at each position to estimate in real time the rotation rate along five directions in the horizontal plane. Finally, a cosine function is fitted to determine the latitude based on the amplitude, and the angle between the machine's reference frame and true north based on the phase shift.

🛠️ Hardware Architecture

The prototype is composed by the following components:

This setup enables precise measurement of Earth's rotation to determine true north and latitude without relying on magnetic fields




🎥 Project Demo

To see the system in action, check out the demonstration video below!
It shows how the device rotates through five directions, collects thousands of samples, and processes the data in real time to estimate true north and latitude — entirely without relying on any magnetic sensors.
The final result is displayed live on the onboard 3.5″ SPI screen (like a real compass).

Over longer periods (tens of minutes), the heading precision reaches about one degree.
However, what is truly impressive is that even after just a few complete cycles (a few thousand samples), the system already provides a remarkably good estimation of true north — as clearly visible in this video!




🔄 Measurement Cycle and Bias Cancellation

The system performs measurements according to the following cycle:

🎯 Bias Suppression by Rapid Reversal

By measuring successively in two opposite directions, the system leverages the fact that gyroscope bias drifts slowly compared to the measurement time. Assuming Δt (≈ 0.5 s) is much shorter than the bias drift timescale (on the order of a minute), the horizontal component of Earth's rotation, ω_E,h, can be estimated as:

ω_E,h = 0.5 × (ω₁ − ω₂)

with

ω1 = +ω_E,h + b(t)
ω2 = -ω_E,h + b(t + Δt)

This technique, similar to the mode-reversal method used in certain MEMS gyroscopes, effectively cancels out the bias.

During the early tests, I applied exactly this method. However, in the approach developed here, a Kalman filter now fuses the measurements to estimate both the sensor bias and the rotation rate.

📈 Oversampling & Dithering: Beating the LSB

The BMI160 gyroscope has a resolution of 3.8 mdps per LSB at ±125 °/s full-scale range, whereas the Earth's rotation is 4,1667 mdps and  horizontal component of Earth's rotation at 45° latitude is about 2,945 mdps. To detect such a faint signal, the system:


🧮 Real-time Kalman Filtering (5-state EKF)

The raw data from the two BMI160 gyroscopes are noisy (≈ 3.8 mdps/LSB) and subject to slow bias and temperature drift.
After each 12-second acquisition cycle (1,280 samples), the firmware runs a lightweight Kalman filter (~2 seconds processing time on the Pi Pico).

1. State vector

For every azimuth θ, the filter tracks five variables:

This 5-degree-of-freedom model whitens 1/f noise and temperature effects without burdening the Cortex-M0+.

2. Prediction model

Between the two half-turns (θ and θ + 180°), the system assumes:

The process noise matrix (Q) is diagonal and tuned based on Allan variance measurements of the BMI160.

3. Measurement model

Each half-turn produces two signed measurements:

By combining z_A and z_B:

The key: the two readings are taken only 0.5 seconds apart, making bias drift negligible compared to the Earth signal.

4. Update step

A standard Extended Kalman Filter (EKF) update is applied:

All matrices are small (5×5) and fit easily into the Pi Pico's RAM, ensuring fast real-time performance.

5. Outputs

Thanks to the EKF, the device achieves less than 1° heading error and around 1° latitude precision after about 20 minutes — using only 3€ sensors.
This level of accuracy would be impossible with simple averaging alone!

You can see more details on my website : https://selvasystems.net/innovations

In a future where magnetic north may wander — or even flip completely — traditional compasses will become unreliable. By relying only on Earth's immutable rotation, this MEMS-based gyrocompass offers a simple, mechanical way to find true north and latitude anywhere, anytime, without needing satellites, magnetic sensors, or external infrastructure. If the world goes dark, you'll still know where true north is - assuming Aliexpress keeps delivering :)