3

I'm building a project based on raspberry pi that relies on fairly accurate compass to be viable. Essentially, if I could know where's North with about 10° of error, I'd be quite happy.

I've bought Sense HAT and even after calibrating it, quite disappointed with the results. If I spin it 3-4 times, results were going absolutely wild. I've set a marker at 360° , but after spinning it couple of times, it became 60°, than 170°, than 280°. It seems like even my phone has higher accuracy in this regard.

I've bought two other magnetometers since, but the result was pretty similar.

Is there a way to get more accurate way of getting compass readings? I'm afraid i might have to pull them from the phone via adb, which sounds like a poor solution.

Appreciate any advice

7
  • 1
    I’ve found digital compasses are not great. I used dual RTK GPS to get an accurate bearing. – CoderMike Jul 27 '20 at 19:13
  • 1
    @CoderMike Thanks for the suggestion! I actually do have RTK for GPS, but it doesn't come with compass. Do you calculate it based on direction of movement? I can't seem to come up with a way of doing that if the board is stationary. – Kasami Jul 27 '20 at 19:36
  • 1
    The GPS should give you a bearing. – CoderMike Jul 27 '20 at 19:53
  • I heard SparkFun saying that their new gps module is 20 cm position accurate: (1) sparkfun.com/products/16344 . I guess their compass should be as accurate. Let me see if I can google something. I will be back. – tlfong01 Jul 28 '20 at 1:43
  • Neo8M says its heading is 0.3 degree accurate. Is it Ok with you? (2) u-blox.com/sites/default/files/… (3) raspberrypi.stackexchange.com/questions/113544/…. Cheers. – tlfong01 Jul 28 '20 at 1:53
1

A magnetometer, otherwise known as a digital compass, is first and foremost a sensor that measures the Earth’s magnetic field in three dimensions. They are also known to be noisy, esp. if they’re anywhere near another magnet typically a monitor, power supply, or similar electronics. Try moving your sensor around and you may see it move because of such. If so move the sensor away from the magnet.

To achieve a stable accurate reading you need to fuse, or combine, the magnetometer reading with another estimate of direction such as an accelerometer or gyroscope which will tell you if you’re changing direction. The fusion is not straightforward. If you’re not worried by maths have a look for details on Kalman filters and Inertial Management Units. There is a lot of Python code you can use, but you still need to have a rough understanding of the math. A Jupyter notebook is available here

1

It turns out that a lot of the cheaper magnetometers just aren't accurate enough and there isn't that much you can do about that.

I've tried Sense HAT, MPU9250, 6050, QMC, all sharing the same issues, but to a different extent.

When I turned my eye to more specified robotics devices, I've discovered UK-based company "Robot Electronics", which sells compasses among other things.

I've bought CMPS14 from them and it is a very clear winner in accuracy even straight out of the box. It can be connected to Raspberry Pi over I2C and provides extremely accurate results for my purposes.

For anyone wondering technical details of that chip can be found here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.