Hi. I have the Honeywell HMC5883L magnetometer sensor which I am using on the GY-273 with a Arduino UNO. Because I just got it today, I wanted to try it out with simply reading some Values. After I ran this Code:
#include <Wire.h> //I2C Arduino Library
#define addr 0x1E //I2C Address for The HMC5883
void setup(){
Serial.begin(9600);
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
Serial.print("X Value: ");
Serial.println(x);
Serial.print("Y Value: ");
Serial.println(y);
Serial.print("Z Value: ");
Serial.println(z);
Serial.println();
delay(500);
}
I got Values between -3 to 3 on all of the 3 Axis. These Values were completely random
I have the Sensor connected as following:
Vcc - 3.3V
Gnd - Gnd
SCL - A5
SDA - A4
DRDY not connected to anything
I've tried using other code examples but always just got a random Value.
I don't really know what im doing Wrong and have check everything a couple of times.
Do I perhaps have to connect the SCL/SDA output of the sensor to my SCL/SDA pin on my Arduino?
Edit:
I've tried Using the 5V pin and also the SCL/SDA Input on my Arduino with no difference in Values
Do I perhaps have to connect the SCL/SDA output of the sensor to my SCL/SDA pin on my Arduino?
If you have an Uno, you have connected it correctly.
Load and run the I2cScanner program to check communications and verify the device address.
It is possible that you will need pullup resistors on the I2C lines. Post a link to the exact HMC5883 module that you have.
So the I2cScanner foul the Device at address 0x1E
I have the GY-273 HMC5883L Magnetometer. The Code I am using is the Same Code as of the Website Link below. This Tutorial of the Website is for the GY-273 HMC5883L so I thought I might be my best Chance at making the sensor work.
As I said its the GY-273 module based on the Honeywell HMC5883L IC. A second Link to confirm this would be http://hobbycomponents.com/sensors/377-gy-273-hmc5883l-3-axis-digital-compass-module
If your meaning something else with module please describe where I can find it...
There are many different modules containing that sensor.
Which exact module did you buy, and where did you buy it? Post links.
I got it from Amazon
and if your referring to Module as the Chip on the GY-273 it says L8832109
Hope this Helps... Thanks for your Time
Thank you. There are incorrectly labeled, fake GY-273 modules, but you appear to have a genuine one, and it has appropriate pullup resistors.
Post examples of the output on the serial monitor.
X Value: 1
Y Value: 2
Z Value: 0
X Value: 2
Y Value: -2
Z Value: 1
X Value: 4
Y Value: 1
Z Value: 1
X Value: 1
Y Value: 0
Z Value: -1
X Value: 0
Y Value: -5
Z Value: 1
X Value: 2
Y Value: -2
Z Value: -1
X Value: 4
Y Value: -3
Z Value: 1
X Value: 3
Y Value: -3
Z Value: -2
X Value: 2
Y Value: 0
Z Value: 1
X Value: 2
Y Value: -2
Z Value: 0
X Value: 6
Y Value: -1
Z Value: -1
X Value: 3
Y Value: -3
Z Value: -2
X Value: 4
Y Value: -4
Z Value: -2
X Value: 0
Y Value: -2
Z Value: 0
X Value: 3
Y Value: -2
Z Value: -1
X Value: 3
Y Value: -5
Z Value: 0
X Value: 0
Y Value: -1
Z Value: 1
X Value: 4
Y Value: -2
Z Value: 0
X Value: 3
Y Value: -1
Z Value: -3
X Value: 0
Y Value: -2
Z Value: 1
X Value: 5
Y Value: -4
Z Value: 2
X Value: 2
Y Value: -1
Z Value: 1
X Value: 2
Y Value: -3
Z Value: 1
X Value: 1
Y Value: -2
Z Value: 1
I can't see or think of any other possible problems, and those numbers are certainly not correct, so you may have a defective sensor.