You probably have a phone with a magnetometer to tell compass direction.
If you're like me, you have probably run into times where the compass is pointing in the wrong direction (90 to 180° out).
You're probably saying, "Just calibrate it, where's the problem?"
The problem is that it
always need calibrating and it hardly ever tells you that it needs it.
Android will tell you "low, medium, high quality" but the accuracy is rarely accurate.
My first attempt to fix the situation is to always monitor the absolute value of the field, i.e. sqrt(Hx*Hx + Hy*Hy + Hz*Hz).
This will tell you if you have a rogue external field or shielding or the offsets on the sensors has drifted out.
That's the root of the problem. Although the magnetoresistive sensors in your phone are sensitive they also drift like heck.
The obvious solution is to just drop $1000 on a flux gate compass. They're pretty good.
For a decade PNI Sensors has made the RM3100 sensor.
It's not a flux gate, but it is a related cousin. There is basically no drift.
You can get breakout boards from China or an evaluation board
direct from PNI for $25.
My test solution is pairing the RM3100 with a Seeed Studios Xiao SAMD21 in a 30 x 100 x 14 mm 3D printed enclosure.
Yes, 100 mm is long, not because I need the internal space but because I want to center the sensor in the middle of my phone.
That way it's as far away from the top and bottom speakers.
I stuck the enclosure to the back of my phone using the Tesa black double-stick tape.
The USB Type C jack is at the bottom and can be connected to the phone with a special USB "U" plug.
I'll try to get a photo of the whole setup, but I can't do it with my phone!
I calibrated the fixed offsets from the magnet fields in the phone.
Both the X & Y had count offsets of 250 (3.3 µT).
The Z had a count offset of 1000 (13.3 µT).
The absolute value I measure of total compensated field is ~44 µT around here.
If I had another phone that I wanted to root I would try to wire the RM3100 directly into the phone's I²C.
That would definitely save some power and free up the USB jack.
Right now the RM3100 is used directly in my hiking app so it's not used by Google Maps.
There is no "mock location" possible for the magnetometer.
Anyone with any experience/notes on the RM3100?