Basically what @Ollie says - you need to take a zero reading :)
To use it as a compass you can maintain a min/max reading (http://www.espruino.com/modules/Vec3.js should make this easier) and then subtract the average of those 2 and then use the offset like a compass - so you'd have to upload the code, then rotate it every angle you can think of, and it should then be ok.
Math.atan2 will save you a bunch of work too - unlike atan it can work over a whole 360 degrees, not just 90/180.
But... Moving location, having magnets near, etc will all throw it off and it may need recalibrating.
One thing you could do is make your own little jig/stand that has a magnet on it. That way it'll be powerful enough that the surrounding magnetic field won't be a big issue.
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.
Basically what @Ollie says - you need to take a zero reading :)
To use it as a compass you can maintain a min/max reading (http://www.espruino.com/modules/Vec3.js should make this easier) and then subtract the average of those 2 and then use the offset like a compass - so you'd have to upload the code, then rotate it every angle you can think of, and it should then be ok.
Math.atan2
will save you a bunch of work too - unlikeatan
it can work over a whole 360 degrees, not just 90/180.But... Moving location, having magnets near, etc will all throw it off and it may need recalibrating.
One thing you could do is make your own little jig/stand that has a magnet on it. That way it'll be powerful enough that the surrounding magnetic field won't be a big issue.