Hi @user134221 does this help?
. . . just found this post
Google: calculate magnometer site:espruino.com
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/zare the raw magnetic field strength values from the magnetometer, which can have some offset
mag.dx/dy/dzare 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
headingvalue 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/zas a vector pointing downwards
mag.dx/dy/dzas a vector pointing towards north (or south? can't remember)
- Then the cross-product of those two vectors points east/west
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!