I have an HMC5883L Sensor.
I am trying to get the data from it to serial monitor and to an LCD display.
I get in three values x,y,z a 0 as result.
I use an arduino UNO R3 and the connections are:
VCC to 5V
GND to GND
SDA to A4
SCL to A5
The example code i use
#include <Wire.h> //I2C Arduino Library
#include <LiquidCrystal.h> //LCD Library
#define addr 0x0D //I2C Address for The HMC5883
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup(){
Serial.begin(9600);
lcd.begin(16, 2);
Serial.print("HMC5833L COMPASS SENSOR BEGIN");
Serial.println();
Wire.begin();
Wire.beginTransmission(addr); //start talking
Wire.write(0x02); // Set the Register
Wire.write(0x00); // Tell the HMC5883 to Continuously Measure
Wire.endTransmission();
}
void loop(){
int x,y,z; //triple axis data
//Tell the HMC what regist to begin writing data into
Wire.beginTransmission(addr);
Wire.write(0x03); //start with register 3.
Wire.endTransmission();
//Read the data.. 2 bytes for each axis.. 6 total bytes
Wire.requestFrom(addr, 6);
if(6<=Wire.available()){
x = Wire.read()<<8; //MSB x
x |= Wire.read(); //LSB x
z = Wire.read()<<8; //MSB z
z |= Wire.read(); //LSB z
y = Wire.read()<<8; //MSB y
y |= Wire.read(); //LSB y
}
// Show Values
lcd.clear();
lcd.print("X:");
lcd.setCursor(2, 0);
lcd.print(x);
lcd.setCursor(8, 0);
lcd.print("Y:");
lcd.setCursor(10, 0);
lcd.print(y);
lcd.setCursor(0, 1);
lcd.print("Z: ");
lcd.setCursor(2, 1);
lcd.print(z);
Serial.print("X Value: ");
Serial.println(x);
Serial.print("Y Value: ");
Serial.println(y);
Serial.print("Z Value: ");
Serial.println(z);
Serial.println();
delay(1000);
}
I got out a HMC5883L module, hooked to my Uno, and uploaded the code from your original post with the exception of changing the addr define to 0x1E. I get changing and believable data to serial monitor. I did not connect a LCD.
X Value: -361
Y Value: -258
Z Value: -461
X Value: -220
Y Value: 63
Z Value: -438
X Value: -83
Y Value: -19
Z Value: -484
X Value: 200
Y Value: -233
Z Value: -411
Is there another device on the I2C bus? Where did you get the module? As far as I know there is only one address for HMC5883 and it is not changeable.
My apologies for not referring to the correct part number. Mine is a HMC5883L. I have done a Google search for HMC5883 and all hits refer to HMC5883L. I do not think that HMC5883 (without the L exists).
I connected an LCD as well and the LCD shows the correct output. The numbers match the serial monitor output. So the program is OK so the issue must be wiring or hardware. Can you post a photo of hour wiring?
Are the solder joints between header and the module good? Pullup resistors are on the module so external pullups are not required.
I believe you have the QMC5883L compass instead. It is a Chinese imitation with a few differences, including the I2C address. Google for forum posts on the topic.
Thank you guys for your help!!!!
It is the chinese clone QMC5883L.
I use the Mecha_QMC5883L library as jremington says and now everything working.
But i should tell that in the module is written that it is HMC5883L.