Hello everyone! I'm doing a Smartwatch with GY-87 module sesnor. This module includes, among others, the QMC5883L compass sensor.
I use 2 different libraries; QMC5883LCompass and MechaQMC5883L.
The first one doesn't work, prints 0 in all directions (azimuth, bearing, etc.). But the second one "works".
There are 2 examples, azimuth and raw.
Azimuth example:
#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;
int azimuth;
//float azimuth; //is supporting float too
qmc.read(&x, &y, &z,&azimuth);
//azimuth = qmc.azimuth(&y,&x);//you can get custom azimuth
Serial.print("x: ");
Serial.print(x);
Serial.print(" y: ");
Serial.print(y);
Serial.print(" z: ");
Serial.print(z);
Serial.print(" a: ");
Serial.print(azimuth);
Serial.println();
delay(100);
}
In azimuth the serial monitor prints:
x: 20735 y: 180 z: 20480 a: 0
While the serial monitor (from Arduino IDE) is open, neither a,y,z,a move. If I close the serial monitor and move the GY to another site and I open the serial monitor again, de y changes, but the others no.
I don't know why if I move the GY-87, the numbers are not changed instantly.
The raw example:
#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);
}
The serial monitor prints:
x: 18771 y: 21024 z: -18170
The x,y,z are different from azimuth example. I don't understand it.
If someone can help me, please!