HMC5883L GY-273 does not work as compass

Hi,some days ago I received this module but I have some trouble with it.
I connected SDA to 20 pin ( I have an Arduino Mega 2560), SCL to 21 and VCC to 3.3V.
I want to use this code:

#include <Wire.h> //I2C Arduino Library

#define addr 0x0D //I2C Address for The HMC5883

void setup()
{
  
  Serial.begin(9600);
  Wire.begin();
  
  
  Wire.beginTransmission(addr); //start talking
  Wire.write(0x02); // Set the Register
  delay(100);
  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
  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);
}

But it always show 0. I also tried to print Wire.endTransmission() , which give 0 (success) and the I2C scanner that show

I2C device found at address 0x0D !

Anyone has some idea for why the test finds it but the sketch does not work?
Thanks in advance!

(deleted)

(deleted)

spycatcher2k:
try 0x1E for the address!

It does not work obviously and the Wire.endTransmission() prints 2, that is for "received NACK on transmit of address" because the port is not correct, the right is 0x0D..!

Edit: I also tried to execute the code that you posted but does not work! Anyway, thanks for the answer.

(deleted)

I asked it to he yesterday but he has not answered yet :frowning:

Caution, if you are buying a HMC5883L module, there are some fake modules about on eBay that claim they are HMC5883L devices but are in fact a QMC5883, which while they are indeed magnetic sensors, have a very different internal structure, different capabilities, and will not work with the software here. The way to tell a real HMC5883L is that the chip is marked L883 where as the "fake" chip is marked DA5883.

@Grumpy_Mike thanks for the answer, I think you are right! As soon as I can read the number on the chip I'll do it!( I need a microscope, the characters are too small).
Just now I tested a QMC sketch I taked on this site, but it shows a different number everytime I close and reopen the serial monitor and while it is open it does not change..!

Edit: I found this post and using the exemple on this github library it works! I only have to convert the values in degrees! Thanks for the "hint" !!!!

Grumpy_Mike:
Caution, if you are buying a HMC5883L module, there are some fake modules about on eBay that claim they are HMC5883L devices but are in fact a QMC5883, which while they are indeed magnetic sensors, have a very different internal structure, different capabilities, and will not work with the software here. The way to tell a real HMC5883L is that the chip is marked L883 where as the "fake" chip is marked DA5883.

Thanks Grumpy Mike!!! :smiley:
I have already tried all the options and I never realized that they had sold me a QMC5883 >:(

Cricri:
Edit: I found this post and using the exemple on this github library it works! I only have to convert the values in degrees! Thanks for the "hint" !!!!

hi Did you get it working? I'm using the same library as well, and I'm getting values. How do you plan on converting the values to degrees? Have you already?
I don't know where to begin because I don't know what these values are coming up. What about calibration?
Please let me know

High Regards

If anyone is still experiencing problems trying to get the HMC5883L GY-273, which is actually actually the QMC5883L version then have a look at https://leobot.net/viewproduct.aspx?id=2940 for links to the libraries and tutorials on how to use it.