I am trying to use the magnetometer on the sense hat to act as a compass however I also want to utilise the GPIO pins for other components. I've successfully wired up the sense hat to the GPIO pins on my Raspberry Pi 4 Model B and am having no issues with connectivity or outputs from the sense hat itself. The issue I am having is that because the sense hat is "loose" and I have it sitting next to the Raspberry Pi, whenever I run the following code to get the sense hat bearing:
from sense_hat import SenseHat sense = SenseHat() while True: print(sense.compass)
the position of the Raspberry Pi affects the results. If I rearrange the Raspberry Pi to be sitting effectively underneath the sense hat, the output is 0 or 360 when pointing to north (as expected). When I move the Raspberry Pi off to the side without changing the orientation or position of the sense hat, the output changes be nearly 10-20 degrees.
I know that I could account for this and have some extra calibration in my code but I want to avoid this for two reasons. One is I want to actually put the effort in to fix it instead of applying a fudge factor and two is my project incorporates some movement via servos and I want to make sure I can reduce the interference as much as possible.
I've played around with trying to shield the sense hat but have had little success.
Does anyone have any suggestions as to how to reduce or reject this interference? I am assuming that it is the current flowing through the wires connecting the sense hat to the GPIO pins that is affecting the magnetic field. Is there some way to shield the wires? I would have thought the current would only affect the magnetic field close to the magnetometer when actually moving through the field and wouldn't have an affect on the output when static (in different positions).
Any input would be greatly appreciated I haven't seen too much out there in terms of interference on the sense hat magnetometer.