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.
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'.
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:
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();
}
#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);
}
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.
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.
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: