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
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
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 offsetmag.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 theheading
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:
acc.x/y/z
as a vector pointing downwardsmag.dx/dy/dz
as a vector pointing towards north (or south? can't remember)