What do the Magnetometer Values Mean?

Posted on
  • Hi, I've been trying to figure out a way to calculate the orientation (both azimuth and altitude) of my Bangle using both the accelerometer and the magnetometer. The altitude was easy; I just multiply 90º by the accelerometer's Z value. However, to calculate the azimuth is proving to be trickier. I've tried reading the magnetometer's values at several orientations (the values mag.x, mag.y, mag.z, mag.dx, mag.dy, and mag.dz) but don't understand what they mean. Could someone please explain them to me so I can transform them into a vector to calculate the azimuth? Thanks for the help!

  • Sun 2021.09.12

    Hi @user134221 does this help?

    https://stackoverflow.com/questions/642555/how-do-i-calculate-the-azimuth-angle-to-north-between-two-wgs84-coordinates

    Would need to convert to Javascript, as code reads pretty much the same.

  • . . . just found this post

    Google:     calculate magnometer  site:espruino.com

    Trying to find compass heading from magnetometer

  • Thanks, I'll have a look!

  • Thanks, that works! At least, when the Bangle's lying flat. Now I'd like to still get the right angle whatever way the watch is oriented. I'm supposing I could use the accelerometer to find out where down is, and use that to rotate the magnetometers' vector... I don't know if I'm even making sense.

  • Glad you got something working! Just some extra info if it helps:

    • mag.x/y/z are the raw magnetic field strength values from the magnetometer, which can have some offset
    • mag.dx/dy/dz are the 'calibrated' field values - after the magnetometer is on and you move around a bit, it works out the maximum and minimum values, then gives you dx/dy/dz relative to the center of that bounding box. That's what the heading value works from.

    So if you want to work out the actual rotation, with the Bangle still and after you've rotated it around a bit to calibrate the magnetometer, you should be able to:

    • Treat acc.x/y/z as a vector pointing downwards
    • Treat mag.dx/dy/dz as a vector pointing towards north (or south? can't remember)
    • Then the cross-product of those two vectors points east/west
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

What do the Magnetometer Values Mean?

Posted by Avatar for qucchia @qucchia

Actions