GY-271 Compass Module

I'm trying to do a project that requires a compass and I found this module.
Firstly: Does this work how I'd expect it to (Telling me what direction it's facing)?
And second: Where should I look to learn how to actually use it? I have had little luck finding a library or a reference page/post for it.

Probably not, until the magnetometer is calibrated.

To start leaning about the compass, find tutorials using the search phrase "arduino gy-271 tutorial".

One of many calibration methods: How to Calibrate a Magnetometer?

After reading this, I question my existence. To think our planes do not fall from the sky and cosmonauts are not lost in space due to mathematics' arch enemy; averaging averages. Does the maths department know about this practice? Will we receive detention?

Sorry, no idea what you are talking about.

But yes, the math, physics and chemistry departments, as well as pilots, navigators, surveyors and explorers, very clearly understand the need to calibrate measuring equipment.

From How to Calibrate a Magnetometer

avg_delta = (avg_delta_x + avg_delta_y + avg_delta_z) / 3

Averaging averages was taught as a sure way to incur a detrimental trend in results. Each element in the equation above (from this link and other search links) is an average of another quotient of averages, the result being yet another layer of an average of averages. Some say math is just theory (never average averages) and physics is real (planes do not get lost and fall from the sky). Some say physics is theory (massless objects on massless tethers gliding over frictionless surfaces, for example) and math is real. I guess it depends on what you want to read. (smiley face)

No, not if the the averages are from independent sources of information. The three magnetometer axes are completely independent sensors. But I agree that the "avg_delta" is not a particularly useful or meaningful quantity.(*)

If you want a better treatment, a much more thorough and technically correct procedure to calibrate accelerometer and magnetometers can be found here: Tutorial: How to calibrate a compass (and accelerometer) with Arduino | Underwater Arduino Data Loggers

(*) In fact, this part of that code probably works OK, but is not well justified and one of the scale factors should be 1.0 in any case, since there is no external calibration reference.

avg_delta = (avg_delta_x + avg_delta_y + avg_delta_z) / 3
scale_x = avg_delta / avg_delta_x
scale_y = avg_delta / avg_delta_y
scale_z = avg_delta / avg_delta_z

The Cavepearl tutorial describes state of the art methods.

1 Like

If A, B and C's data is averaged, I agree.
If A, B and C's averages are averaged, I do not (heh, but this is how it's done)

Yes, I read that... last year(?)... saw your cite.

I think we agree that the method in that first approach is not strictly correct. The second tutorial is mathematically correct.

heh, but this is how it's done

No, not really. What you were referencing was awkward pseudo code.

In reality, a least squares optimization is done to find the 3x3 alignment/scale matrix and 3 element bias vector that allows all magnetic vector readings to trace a sphere. The radius of the sphere is usually the average magnitude of all uncalibrated magnetic vector readings.

You could, in theory, do the calibration in an open field away from power lines/buildings and have the calibration sphere radius be the magnitude of the Earth's core field at that point as estimated by either the WMM or IGRF models, but that's a bit overkill.

Hahahaa.ahah. Then, I read this...

"...simple regression and least-squares methods have problems..."

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.