Trying to find compass heading from magnetometer #1848
Replies: 8 comments
-
Posted at 2016-12-14 by ClearMemory041063 Don't have a Puck here but I am working with magnetometer elsewhere in the forum. xy plane has to be level to get a heading. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-12-14 by Bennr I follow you to a point, but I don't know what you mean in this bit
Do I have the puck flat on a level surface and align it to North and South do the X axis (like turning a knob), then do I tip it on it's side and turn it (like a spinning coin) to do the same for Y? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-12-14 by ClearMemory041063 Try this:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-12-14 by ClearMemory041063 Not having a puck I'm not sure how the axis are laid out. See puck.mag at |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-12-14 by ClearMemory041063 The code posted above does a calculation called level and that uses the accelerometer in the chip I'm using, not the magnetometer. Sorry about that. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-12-14 by @gfwilliams I think the main thing here is that you have to find 'zero' for the magnetometer. All kinds of things can effect the reading - for instance when I've been using a magnet, if I get too close it can presumably magnetise some part of the Puck, and that then changes the readings from then on. But once you have the zero, you can subtract it from the magnetometer value and you should get a much cleaner reading. Easiest way I'd say is to take 4 readings - one normally, one rotated 90 degrees, one 180, and one 270. Add the x, y and z's separately and divide by 4 - then always subtract that value from the magnetometer. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-04 by Bennr Digging up an old thread here, but I kind of got it working enough for what I want. I did what was suggested an took four readings at N,S,E,W, averaged them and deducted them from what My code is below:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-05 by @gfwilliams Thanks - this looks great. Just to add: If you're using strong magnets near your Puck the you can magnetise it slightly which will knock off your calibration value (and you'll have to take the 4 readings again). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2016-12-13 by Bennr
I've been (unsuccessfully) trying to convert the magnetometer readings to a compass headings. I've been googling, and due to my maths education stopping at GCSE level, I don't understand most of the conversions. I tried following the adafruit guide but it's for a different magnetometer sensor, and the readings don't seem the same, Adafruit guide says the readings are in micro-Teslas and will be between 20 and 60 micro Teslas, and in the Puck guide it's saying a similar number, but that the increments are in 0.1 micro Teslas. I am getting readings of
{ "x": -3431, "y": 4167, "z": 508 }
so even divided by 10 these are off.I thought that the following code might work:
But I don't get the readings I would expect.
Am I missing something or being a dope?
Beta Was this translation helpful? Give feedback.
All reactions