I've built an boat autopilot which uses a QMC5883L spec compass. Each of a set of 3 worked for a short time then would stop being reachable on I2C. I bought a second set of 3 from a different manufacturer and one worked for a good while but now gives random results and the others are not reachable. Can you recommend a reliable unit - ideally with a hole for securing on my plywood baseboard.
thanks
Attach a wiring diagram and specify wire lengths so we can better figure out where the problem is. Include information about the board and the power supply you are using.
And don’t forget to publish your code
Have you been using a 3v3 controller or a level shifter with a 5v controller?
2.2-3.6V Supply Voltage
The problem you describe is likely due to faulty wiring, poor soldering, or connecting 5V and 3.3V devices without using logic level shifters.
For better informed help, please read and follow the directions in the "How to get the best out of this forum" post, linked at the head of every forum category. Also post a pic of your setup.
I’m using Arduino Nano ESP32-S3 in a screw terminal adaptor with approx 12cm wires. VCC is on 3.3v.
The first unit of the second batch of 3 from Adafruit worked well for a couple of weeks so basic connection and code is OK, then started giving random results. I tried the other 2 and they both could not be found on I2c. So looking for a reliable option even if it costs a bit more!
Consider magnetometer modules with Qwiic or Stemma connector options. Example
The long discontinued HMC5883L and its cheap, less well functioning Chinese copy QMC5883L are known for locking up or otherwise malfunctioning, requiring a programmatic hard reset. See the datasheet for the details.
For a much better performing compass, buy a module with an accelerometer, either a mag+acc combo, or a 9DOF sensor (and ignore the gyro). The accelerometer enables tilt compensation, so you don't have to keep the sensor level for accurate readings.
Thanks @jremington both in analysis and solution!