HMC5883 not working as expected

Hello there. I have a problem with my HMC5883 sensor. At first I try using the adafruit example script. And it works fine, with only slight deviation from the compass in my phone. Then I try writing my own code using the example script as a reference. Only differences is my code doesn't print the serial value and sensor data, different serial baudrate, etc. then disaster strike. The bearing suddenly become unusable. Firstly the value always start with 2, so for example I can't get something like 170 degrees, or 90 degrees even after spinning the sensor in full 360 degrees. At the time I assume my code is faulty. So I reflashed the example script. And the same problem continue. I monitored the raw value. And the x and y somehow can't never get over 90. No matter how I move the sensor.

Please help. Thank you in advance.

For informed help, please read and follow the directions in the "How to get the best out of this forum" post.

Note that magnetometers must be calibrated to be useful as an electronic compass.

1 Like

Hi there, I really appreciate your response. I know I haven't calibrated the sensor, but (though I'm not entirely sure) the main problem isn't the lack of calibration. Since the sensor can't even output a raw value (not considering the accuracy). Even spinning a neodymium magnet around it doesn't work. The sensor keep outputting a 200 ish degree bearing. It's as if it was stuck, and cannot detect a change in the magnetic field.

And I don't know how. As I said before, it worked the first time with only an error under 5 degrees. After 2 power cycle, it become haywire.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.