Inaccurate Readings from 6-axis-accelerometer-and-compass


I recently purchased a 6-axis-accelerometer-and-compass for my GrovePi+ and have been facing major issues with the accuracy of the compass. I have noticed that it is extremely sensitive to interference and produces erroneous heading values when near electrical components. When moved away from these components the accuracy of the heading increases, but is still not +/- 2 degrees like the datasheet says, its more like +/- 50. Occasional it’ll read the correct heading, but when I rotate the robot (lets say from facing north to east) it will be dramatically wrong. Not sure what to do about these inaccuracies as they make using the compass for reliable location tracking impossible.

I’ve tried calibrating to no avail (not sure if that’s even the true issue). Can someone offer any advice on how to get more accurate headings?

The compass is prone to noise and it usually recommended to keep it far from electrical components, however it should not be giving +/- 50 degrees. Can you send me a link to the code that you are using with the sensor.


This is the link to the code:

Any update on how to alleviate the interference/get less noisy readings?