GY-271 (HMC5883) doesnt respond

hi, i bought two gy-271 modules recently. but they dont respond correctly, they show always default values and always same. when i load these codes and this library on this website. it shows values like below. even if unplug wires of gy271, it shows same values. i mean they are default values.

this is i2c scanner's result:

whats wrong this module?

There are lots of code examples for that sensor. Try another one.

The best approach is to read the sensor data sheet, learn what the code is doing, and put print statements to see the results of each individual step in the program.

jremington:
There are lots of code examples for that sensor. Try another one.

The best approach is to read the sensor data sheet, learn what the code is doing, and put print statements to see the results of each individual step in the program.

actually i tried many examples, do you have any? all of them shows default values.

There are no "default values", just erroneous numbers if the I2C communications don't work.

You can try a different I2C library, which includes an HMC5883L example, in the zip file attached. You will need to edit the program to make an .ino file.

The simplest test is to see if you can read back the identification registers 0x0A, 0x0B and 0x0C.

Register 0x0A should contain the value 0x48, equivalent to the ASCII letter 'H'.

I2C_Rev5.zip (6.79 KB)

jremington:
There are no "default values", just erroneous numbers if the I2C communications don't work.

You can try a different I2C library, which includes an HMC5883L example, in the zip file attached. You will need to edit the program to make an .ino file.

The simplest test is to see if you can read back the identification registers 0x0A, 0x0B and 0x0C.

Register 0x0A should contain the value 0x48, equivalent to the ASCII letter 'H'.

i upload this sketch, but it shows nothing like that:

Please read "How to use this forum" and upload your code properly, using code tags.

i upload sketch you advised and uploaded without changement. this the code i mean:

#include <I2C.h>

#define HMC5883L  0x1E

int x = 0;
int y = 0;
int z = 0;


void setup()
{
  I2c.begin();
  I2c.write(HMC5883L,0x02,0x00); //configure device for continuous mode
}

void loop()
{
  I2c.read(HMC5883L,0x03,6); //read 6 bytes (x,y,z) from the device
  x = I2c.receive() << 8;
  x |= I2c.receive();
  y = I2c.receive() << 8;
  y |= I2c.receive();
  z = I2c.receive() << 8;
  z |= I2c.receive(); 
}

Yes, try THIS known-working info/software:

If you want to see something on the screen, you should put in a serial print statement.

Start with the basics!

#include <I2C.h>

#define HMC5883L  0x1E

int x = 0;
int y = 0;
int z = 0;


void setup()
{
  Serial.begin(9600);
  I2c.begin();
  I2c.write(HMC5883L,0x02,0x00); //configure device for continuous mode
}

void loop()
{
  I2c.read(HMC5883L,0x03,6); //read 6 bytes (x,y,z) from the device
  x = I2c.receive() << 8;
  x |= I2c.receive();
  y = I2c.receive() << 8;
  y |= I2c.receive();
  z = I2c.receive() << 8;
  z |= I2c.receive();
  Serial.println(x);
  Serial.println(y);
  Serial.println(z);
}

Do you have pullup resistors on the I2C lines SDA and SCK?

Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Not a fritzy diag, but a circuit drawn from your project please.
Also a picture of your project will help too.

Thanks.. Tom... :slight_smile:

jremington:
Do you have pullup resistors on the I2C lines SDA and SCK?

i am using Arduino Uno, is it necessary? can you send an example please?

TomGeorge:
Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Not a fritzy diag, but a circuit drawn from your project please.
Also a picture of your project will help too.

Thanks.. Tom... :slight_smile:

i am using this module, you can look this:

http://i.hizliresim.com/o0rpXX.jpg

It is required to have pullup resistors (typically 4.7K) on the I2C lines. The UNO does not have them.

Your module may, but it is impossible to tell from that completely useless photo.

ADD THEM. Google for examples.

jremington:
It is required to have pullup resistors (typically 4.7K) on the I2C lines. The UNO does not have them.

Your module may, but it is impossible to tell from that completely useless photo.

ADD THEM. Google for examples.

i think module already has pullup resistors. This is the datashet which includes schematic:
http://www.robotpark.com/image/data/PRO/91457/GY_271_ELECTRONIC_COMPASS.pdf

Is there any other answer?

For anyone searching for this issue in the future: I had this same problem and found that the root cause was that I was using a GY-271 with the QMC5883L sensor instead of the HMC5883L which requires a different library as detailed in this article: