Beau Schwabe (Parallax) said...
What happens if you take a rare earth magnet and rotate it about 5 inches away from the compass? Does it still show problems near what it's reporting as North? The problem I don't think is in X transitioning on Zero near North, because it is the Y that actually transitions at North and South. The X axis will transition at East and West.
That said, so what's this mean? I think that the atan2 c++ function that you are using is just fine. The big thing that happens near North is the Deg transition from 0 to 360 deg this "wrap around" can cause big headaches in software if not handled properly. Another thing is that the RAW X and Y values that are returned are relatively small. Even though the HM55B Compass is 11 bit, there is plenty of overhead for detecting stronger magnetic fields. With the Earth's magnetic force I get +/- XY numbers with a magnitude of about 50. With a rare earth magnet about 5 inches away those numbers increase to about 100.