5

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

Kasami
  • 91
  • 1
  • 5
  • 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) https://www.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 01:43
  • 1
    Neo8M says its heading is *0.3 degree accurate*. Is it Ok with you? (2) https://www.u-blox.com/sites/default/files/NEO-M8-FW3_DataSheet_%28UBX-15031086%29.pdf (3) https://raspberrypi.stackexchange.com/questions/113544/how-can-rpi-change-neo-6m-gps-update-rates/113601#113601. Cheers. – tlfong01 Jul 28 '20 at 01:53
  • 1
    The Neo8M I am playing with actually has HMC5983 on board, for you to do some real time local bearing adjustments: (4) AliExpress Micro GYGPSV5-NEO M8N NEO-M8N GPS Module HMC5983 Pixhawk - APM US$22 https://nl.aliexpress.com/item/4000206421398.html,

    (5) TaoBao GYGPSV5-M8N NEO-M8N GPS APM2.6 HMC5983 - ¥125 https://item.taobao.com/item.htm?spm=a1z1r.7974869.0.0.269c3ad4J2Y5yR&id=589024915071. Cheers.

    – tlfong01 Jul 28 '20 at 02:03
  • Are you doing any averaging/smoothing? I reckon the Sense hat is just giving you raw data, to do with as you please. – HiredMind Jul 29 '20 at 17:20

2 Answers2

4

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

Kasami
  • 91
  • 1
  • 5
2

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

Nick
  • 776
  • 4
  • 15