code for compass output in degrees from MPU-9250

Place code snippets and demo code here
Zim
Posts: 289
Joined: Mon Feb 08, 2021 9:15 pm
Has thanked: 263 times
Been thanked: 129 times

code for compass output in degrees from MPU-9250

Post by Zim »

Hello. I am finding that a digital compass is very complicated. Is there a example (using Annex) to achieve this, using a affordable module like the MPU9250 or QMC5883L?

Thanks
Zim
AndyGadget
Posts: 222
Joined: Mon Feb 15, 2021 1:44 pm
Has thanked: 125 times
Been thanked: 132 times

Re: code for compass output in degrees from MPU-9250

Post by AndyGadget »

If you stretch the 'affordable' a bit, the BNO055 gives a direct readout of heading from Annex. The module is nearly 30 quid.

I'm using one in a device to attach to an astronomical telescope to assist aligning the 'scope to a selected object in the sky (planet, star, galaxy, nebula etc) in a PC program (Stellarium) via its API. I'm reading bearing (azimuth) and pitch (altitude) from the BNO055
It has a target type sight showing on an ESP32 TTGO-Display module so align the dot in the middle of the screen by moving the 'scope and you're pointing at the object in the sky you want to see.
Brilliant in theory, but in practice having a large metal tube at varying angles in close proximity to the compass module plays merry hell with the calibration. Even with an extender to about 1 foot above the 'scope tube accuracy still suffers. Work continues.
User avatar
cicciocb
Site Admin
Posts: 2056
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 439 times
Been thanked: 1354 times
Contact:

Re: code for compass output in degrees from MPU-9250

Post by cicciocb »

I agree with Andy, the bno055 is certainly a good choice because it contains inside all the processing power to compute the different angles, including the heading.

It is incredible how the prices increased as I payed around 10€ and now it is priced at more than 30€ ! :shock:

You can also use the MPU9250 (much cheaper) with the Mahony or Madgwick algorithms (see the examples in the help).
In this case, the Yaw angle is the compass information (heading).

Consider that these devices are very sensitive against the external magnetic fields and metallic objects around.
In particular they must be calibrated using the "8-mouvement" and the local magnetic variation must also be taken into account
peridot
Posts: 46
Joined: Mon Mar 08, 2021 4:54 am
Has thanked: 7 times
Been thanked: 93 times

Re: code for compass output in degrees from MPU-9250

Post by peridot »

I have used the QMC6310 magnetic sensor recently as a wind direction sensor, It has I2c but I have just used the Analog output but it was very easy to used , very responsive and inexpensive
Zim
Posts: 289
Joined: Mon Feb 08, 2021 9:15 pm
Has thanked: 263 times
Been thanked: 129 times

Re: code for compass output in degrees from MPU-9250

Post by Zim »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Wed Feb 22, 2023 10:26 am You can also use the MPU9250 (much cheaper) with the Mahony or Madgwick algorithms (see the examples in the help).
In this case, the Yaw angle is the compass information (heading).
Thanks cicciocb! I had seen that but didn't know "Yaw" was the heading!
Thanks
Zim
Zim
Posts: 289
Joined: Mon Feb 08, 2021 9:15 pm
Has thanked: 263 times
Been thanked: 129 times

Re: code for compass output in degrees from MPU-9250

Post by Zim »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Wed Feb 22, 2023 11:49 am I have used the QMC6310 magnetic sensor recently as a wind direction sensor, It has I2c but I have just used the Analog output but it was very easy to used , very responsive and inexpensive
Hi peridot;
Did the QMC6310 require programming to achieve analog output, or does it work "out of the box"?
Is there a analog output pin on the module?

Thanks
Zim
User avatar
Electroguard
Posts: 860
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 274 times
Been thanked: 322 times

Re: code for compass output in degrees from MPU-9250

Post by Electroguard »

This similar item suggests it has a simple analog out... https://www.aliexpress.com/item/4000861 ... Fy4L6KFRL5
Zim
Posts: 289
Joined: Mon Feb 08, 2021 9:15 pm
Has thanked: 263 times
Been thanked: 129 times

Re: code for compass output in degrees from MPU-9250

Post by Zim »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Wed Feb 22, 2023 4:18 pm This similar item suggests it has a simple analog out... https://www.aliexpress.com/item/4000861 ... Fy4L6KFRL5
Thanks Electroguard. I will order one of those too!

Thanks
Zim
User avatar
Electroguard
Posts: 860
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 274 times
Been thanked: 322 times

Re: code for compass output in degrees from MPU-9250

Post by Electroguard »

Yep, I just ordered a couple myself... thanks for bringing the matter to our attention, Peridot.
It looks like the sensor comes with a small magnet, how far from the rotation axis did you mount yours, and any other tips ?
User avatar
Electroguard
Posts: 860
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 274 times
Been thanked: 322 times

Re: code for compass output in degrees from MPU-9250

Post by Electroguard »

Gonna be using one ADC input for wind direction, so might as well try using another for wind speed ... won't break the bank even if it doesn't work.
https://www.aliexpress.com/item/1005003 ... ec%21FR%21
Post Reply