Hello, everybody. I have been working with the HMC5883L compass for a while now, and through much frustration and struggles, I have figured out that the HMC5883L is not on the market anymore, but its semi-clone, the QMC5883L is. However, I am using a code for GPS Guided Robotic car from online and it is a bit difficult to change the code, so I have decided to directly hack the HMC library and change all the registers in the cpp/ and h/ files in the library. Well, I have been trying for two days now, my Serial baud is 9600, and I am using the code below to calibrate my compass but to no avail. I am using this code
/*
Calibrate HMC5883L. Output for HMC5883L_calibrate_processing.pde
Read more: http://www.jarzebski.pl/arduino/czujniki-i-sensory/3-osiowy-magnetometr-hmc5883l.html
GIT: https://github.com/jarzebski/Arduino-HMC5883L
Web: http://www.jarzebski.pl
(c) 2014 by Korneliusz Jarzebski
*/
#include <Wire.h>
#include <HMC5883L.h>
HMC5883L compass;
int minX = 0;
int maxX = 0;
int minY = 0;
int maxY = 0;
int offX = 0;
int offY = 0;
void setup()
{
Serial.begin(9600);
// Initialize Initialize HMC5883L
while (!compass.begin())
{
delay(500);
}
// Set measurement range
compass.setRange(HMC5883L_RANGE_1_3GA);
// Set measurement mode
compass.setMeasurementMode(HMC5883L_CONTINOUS);
// Set data rate
compass.setDataRate(HMC5883L_DATARATE_30HZ);
// Set number of samples averaged
compass.setSamples(HMC5883L_SAMPLES_8);
}
void loop()
{
Vector mag = compass.readRaw();
// Determine Min / Max values
if (mag.XAxis < minX) minX = mag.XAxis;
if (mag.XAxis > maxX) maxX = mag.XAxis;
if (mag.YAxis < minY) minY = mag.YAxis;
if (mag.YAxis > maxY) maxY = mag.YAxis;
// Calculate offsets
offX = (maxX + minX)/2;
offY = (maxY + minY)/2;
Serial.print(mag.XAxis);
Serial.print(":");
Serial.print(mag.YAxis);
Serial.print(":");
Serial.print(minX);
Serial.print(":");
Serial.print(maxX);
Serial.print(":");
Serial.print(minY);
Serial.print(":");
Serial.print(maxY);
Serial.print(":");
Serial.print(offX);
Serial.print(":");
Serial.print(offY);
Serial.print("\n");
}
Well, no data is coming from the Serial Monitor. I also will attach the registers I changed. The code I am about to attach is the registers in .h file of the HMC5883L library to make the QMC work on the same library.
#define HMC5883L_ADDRESS (0x0D)
#define HMC5883L_REG_CONFIG_A (0x0A)
#define HMC5883L_REG_CONFIG_B (0x0B)
#define HMC5883L_REG_MODE (0x09)
#define HMC5883L_REG_OUT_X_M (0x01)
#define HMC5883L_REG_OUT_X_L (0x00)
#define HMC5883L_REG_OUT_Z_M (0x05)
#define HMC5883L_REG_OUT_Z_L (0x04)
#define HMC5883L_REG_OUT_Y_M (0x03)
#define HMC5883L_REG_OUT_Y_L (0x02)
#define HMC5883L_REG_STATUS (0x0C)
#define HMC5883L_REG_IDENT_A (0x06)
#define HMC5883L_REG_IDENT_B (0x07)
#define HMC5883L_REG_IDENT_C (0x08)
NOTE: THIS CODE ABOVE IS FOR THE .H FILE FOR THE HMC5883L AFTER I CHANGED THE REGISTERS TO QMC REGISTERS
Does anybody know what my problem is?
Best regards, Daniel