#include <HMC5883L.h>
#include <Wire.h>
HMC5883L magnetometer;
MagnetometerScaled scaledVals;
void setup() {
Serial.begin(115200);
delay(20);
Wire.begin(0, 2);
Wire.setClock(400000);
Serial.println("Initializing HMC5883L");
magnetometer = HMC5883L();
magnetometer.SetScale(1.3);
magnetometer.SetMeasurementMode(Measurement_Continuous);
}
void loop() {
scaledVals = magnetometer.ReadScaledAxis();
printScaled(scaledVals);
delay(200);
}
void printScaled(MagnetometerScaled scaled)
{
Serial.print(scaled.XAxis);
Serial.print(" | ");
Serial.print(scaled.YAxis);
Serial.print(" | ");
Serial.print(scaled.ZAxis);
Serial.print("\n");
Serial.flush();
}
It was supposed to print the output like '235.00 | -129.32 | -321.54' but instead, I have '25.00 | 65129.32 | 65321.54'.
Note that this values are only examples that I made from my mind right now.
Can someone see anything wrong with my code?