Hi all,
I got a HMC5883L breakboard from here
I connected it to the Nano with connection SDA to A4, SCL to A5. I ran a quick test but the result looks quite weird. Despite the raw values at x and y axis seems to be ok, I could not get any useful data at the z axis. They keep jumping between 0 and -1 no matter how I rotated the board.
Can anyone give me some clue about the cause of this abnormal result? I hope this is not due to a defect inside the board.
The library I used is:
The code I used to read raw data from HMC5883L is:
#include <Wire.h>
#include <HMC5883L.h>
HMC5883L compass;
void setup()
{
Serial.begin(9600);
Serial.println("Initialize HMC5883L");
while (!compass.begin())
{
Serial.println("Could not find a valid HMC5883L sensor, check wiring!");
delay(500);
}
/* Set up magetometer */
compass.setRange(HMC5883L_RANGE_1_3GA);
compass.setMeasurementMode(HMC5883L_CONTINOUS);
compass.setDataRate(HMC5883L_DATARATE_30HZ);
compass.setSamples(HMC5883L_SAMPLES_8);
compass.setOffset(0, 0);
}
void loop()
{
Vector raw = compass.readRaw();
Serial.print("X: ");
Serial.print(raw.XAxis);
Serial.print(", Y: ");
Serial.print(raw.YAxis);
Serial.print(", Z: ");
Serial.print(raw.ZAxis);
Serial.println();
delay(100);
}
And the result I got is like this:
X: -410, Y: 50, Z: 0
X: -395, Y: 48, Z: 0
X: -384, Y: 46, Z: 0
X: -374, Y: 73, Z: -1
X: -367, Y: 111, Z: 0
X: -371, Y: 120, Z: -1
X: -368, Y: 163, Z: -1
X: -365, Y: 156, Z: 0
X: -345, Y: 170, Z: 1
X: -333, Y: 173, Z: -1
X: -302, Y: 194, Z: 0
X: -271, Y: 217, Z: 0