Proper I2C configuration
Posted: Mon May 11, 2015 8:21 am
I'm developing a project using Arduino IDE + HMC5883L + ESP8266. I need to read data from HMC5883L using ESP, but it always give me wrong values. I've tested it directly on Arduino UNO and the sensor is OK. Here follows my code:
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?
Code: Select all
#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?