QMC5883L magnetometer not updating, and sending wrong values

Hey everyone,
I've recently started trying to make a magnetometer work with my arduino pro micro, but I'm stuck on 2 issues : the first is that once I upload the basic test code to the board, it starts sending a set of value in a loop, and they never update unless I reset the board. The second issue is that the values seems pretty wrong, though they are somewhat consistent. I've tried turning the sensor in every direction, and the variance is basically the same as when I don't move it at all between resets.
Any help appreciated !

Here's my test code :

#include <Wire.h>
#include <MechaQMC5883.h>

MechaQMC5883 qmc;

void setup() {
  Wire.begin();
  Serial.begin(9600);
  qmc.init();
  qmc.setMode(Mode_Continuous,ODR_200Hz,RNG_2G,OSR_256);
}

void loop() {
  int x,y,z;
  qmc.read(&x,&y,&z);
  Serial.print("x: ");
  Serial.print(x);
  Serial.print(" y: ");
  Serial.print(y);
  Serial.print(" z: ");
  Serial.print(z);
  Serial.println();
  delay(100);
}

Sounds like a defective sensor. The QMC5883L is a cheap Chinese imitation of the long obsolete HMC5883L, and doesn't work as well as more modern magnetometers.

Just about any magnetometer you buy from reputed suppliers will work better.

I'll try soldering up the second sensor I got from them, then. Can you recommend any other sensor I could get quickly ?

Would this one be a good fit ?

The LIS3MDL is a good choice.

No point they are a different chip and require a different library.

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