Don't have a Puck here but I am working with magnetometer elsewhere in the forum.
Try atan2(x,y)*180/pi
First the divide by 10 in your atan2 function isn't needed. The ratio of the numbers is what's important for the trig to work.
Second set up a non magnetic level surface with a method of aligning the x or y axis due North and due South. Point the X axis North and take a reading, then point it South and take a reading. Do the same for the Y axis. If North reading equals - South reading the axis is zeroed. If not you will need to correct the readings with an offset value for each axis. (average 10 North reading with 10 South readings to get the offset value.
Do the math with the offsets applied to the raw readings. x1= x_raw-x_offset, y1= y_raw - y_offset.
Third the atan2 *180/PI gives -180 to +180 and you likely want 0 to 360 with 90 being East.
If atan2*180/pi <0 add 360.
If West is 90 degrees try atan2(-x,y).
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.
Don't have a Puck here but I am working with magnetometer elsewhere in the forum.
Try atan2(x,y)*180/pi
First the divide by 10 in your atan2 function isn't needed. The ratio of the numbers is what's important for the trig to work.
Second set up a non magnetic level surface with a method of aligning the x or y axis due North and due South. Point the X axis North and take a reading, then point it South and take a reading. Do the same for the Y axis. If North reading equals - South reading the axis is zeroed. If not you will need to correct the readings with an offset value for each axis. (average 10 North reading with 10 South readings to get the offset value.
Do the math with the offsets applied to the raw readings. x1= x_raw-x_offset, y1= y_raw - y_offset.
Third the atan2 *180/PI gives -180 to +180 and you likely want 0 to 360 with 90 being East.
If atan2*180/pi <0 add 360.
If West is 90 degrees try atan2(-x,y).
xy plane has to be level to get a heading.