I have Tried both an Arduino Uno (Two different boards) using pins A5=>SCL & Pins A4=>SDA, I also tried the dedicated SCL & SDA Pins, I also tried supplying both 3.3 & 5V
I have also tried an Arduino Mega 1280 using pins 21=>SCL & 20=>SDA, again after trying multiple scripts found on the internet none of the 3 sensors work.
I have also tried a script that is supposed to scan for devices on the I2C, and that script finds the devices, but it says they are at address 0x0D (All three of them), however from what I have read, these chips should be on address 0x1E, not sure what is going on here. The results of the scan are same for both the Uno and the Mega.
Assuming that I have the wiring correct, then I can't what else to try.
Can anyone point me to a script that they know works with the HMC5883L
@el_supremo just taking my car for a service I will try the 4.7k pullup resistors later when I get back and let you know, but why does no one else need them in the all the YouTube videos that cover this chip?
The datasheet for the HMC5883L says it needs pullups. But the photo of your module has two 4.7k resistors on it which might be the pullups. However, the two reference designs in the datasheet use 2.2k. If you add external 4.7k resistors that will make the total equal to about 2.3k which is close enough. Try it and use the I2C scanner to see if it finds the correct address 0x1E.
It's I2C, and I2C needs pull-ups. The I2C specifications say 1-10k iirc - so 2k2 and 4k7 should work just fine. The I2C breakout boards that I've had so far all included these pull-ups.
Another possible issue: the chip works at 2.16 to 3.6V, and the absolute maximum rating is 4.8V for both VCC and VCCIO. You may need level shifters.
The breakout board in your amazon link appears to have an on-board regulator, and another chip which could be a level shifter. that would explain the four 472 resistors as well. If so, that's great, and it can be connected directly to your 5V Arduino and 5V I2C bus.
The breakout board from the ebay link on the other hand appears to have no regulator (the 3-pin component may be a regulator, no idea what else it could be) and definitely no level shifter, so that one you may destroy by connecting it to 5V (don't trust the seller's descriptions too much!) - this one will have to be powered by the 3.3V output, and connected to the I2C pins using level shifters. I do see two 472 resistors, that may be the pull-ups, some capacitors and that unknown 3-pin component.
@wvmarle@el_supremo I have tried the 4K7 pull up resistors on both 5 volts and 3.3. Still no joy. The I2C scanner still says it can see a device on 0x0D on both Mega and Uno. If I remove one of the I2C wires the scanner says no device found, so I am assuming the scanner is finding something and this is not just noise.
I just don't understand how I could be doing something so wrong.
Could you have a quick look at the code, I am using. This is just one of the scripts which does not work. The detectHMC5883L () returns false. I have even tried changing the HMC5883L_ADDR to 0x0D which is what the scanner says it has detected.
/*
* HMC5883L Demo.
* dipmicro electronics, 2014
*
* Hardware Used:
*
* Arduino UNO or compatible
* GY271 module (dipmicro part DE4196
* Arduino GND -> GY271/HMC5883L GND
* Arduino 3.3V -> GY271/HMC5883L VCC
* Arduino A4 (SDA) -> GY271/HMC5883L SDA
* Arduino A5 (SCL) -> GY271/HMC5883L SCL
*/
#include <Wire.h> //I2C Arduino Library
#define HMC5883L_ADDR 0x1E //0011110b, I2C 7bit address of HMC5883
bool haveHMC5883L = false;
bool detectHMC5883L ()
{
// read identification registers
Wire.beginTransmission(HMC5883L_ADDR); //open communication with HMC5883
Wire.write(10); //select Identification register A
Wire.endTransmission();
Wire.requestFrom(HMC5883L_ADDR, 3);
if(3 == Wire.available()) {
char a = Wire.read();
char b = Wire.read();
char c = Wire.read();
if(a == 'H' && b == '4' && c == '3')
return true;
}
return false;
}
void setup()
{
//Initialize Serial and I2C communications
Serial.begin(9600);
Serial.println("GY271 TEST");
Wire.begin();
// lower I2C clock http://www.gammon.com.au/forum/?id=10896
TWBR = 78; // 25 kHz
TWSR |= _BV (TWPS0); // change prescaler
}
void loop()
{
bool detect = detectHMC5883L();
if(!haveHMC5883L)
{
if(detect)
{
haveHMC5883L = true;
Serial.println("We have HMC5883L, moving on");
// Put the HMC5883 IC into the correct operating mode
Wire.beginTransmission(HMC5883L_ADDR); //open communication with HMC5883
Wire.write(0x02); //select mode register
Wire.write(0x00); //continuous measurement mode
Wire.endTransmission();
}
else
{
Serial.println("No HMC5883L detected!");
delay(2000);
return;
}
}
else
{
if(!detect) {
haveHMC5883L = false;
Serial.println("Lost connection to HMC5883L!");
delay(2000);
return;
}
}
int x,y,z; //triple axis data
//Tell the HMC5883 where to begin reading data
Wire.beginTransmission(HMC5883L_ADDR);
Wire.write(0x03); //select register 3, X MSB register
Wire.endTransmission();
//Read data from each axis, 2 registers per axis
Wire.requestFrom(HMC5883L_ADDR, 6);
if(6<=Wire.available()){
x = Wire.read()<<8; //X msb
x |= Wire.read(); //X lsb
z = Wire.read()<<8; //Z msb
z |= Wire.read(); //Z lsb
y = Wire.read()<<8; //Y msb
y |= Wire.read(); //Y lsb
}
//Print out values of each axis
Serial.print("x: ");
Serial.print(x);
Serial.print(" y: ");
Serial.print(y);
Serial.print(" z: ");
Serial.println(z);
delay(250);
}
Good photos. Unfortunately, they show that you've done everything right and I can't see any reason why the I2C scanner shouldn't find the correct address. However, I'm making a couple of assumptions which may not be correct.
The first is that your jumper wires aren't broken. Change all of them (or test their continuity with a multimeter).
The second is that the breadboard connections themselves are OK. Try moving the entire circuitry to the other end of the breadboard or to a different breadboard.
I've run into both of those problems.
The real oddity here is indeed that the I2C scanner detects SOMETHING. That normally means the wiring is correct, which is confirmed by the scanner detecting nothing the moment the cable is removed.
Now with two of the same sensors bought on different breakout from different vendors, it's very unlikely it's both the wrong (yet the same) sensor they shipped.
That would point to a faulty Arduino. However OP testing it on three different boards, that again is extremely unlikely: it would mean they all break in the same weird way that I2C is still working somewhat but reporting a different address.
It does make me think it detects something else - another device on the same bus. So I just did a Google search for "HMC5883L i2c address 0x0D" and guess what: you're not the only one with the exact same problem! Apparently there are "fake" boards out there using another chip - fake as in, not the correct chip, yet still the same functionality.
Fake from eBay perchance? Have you tried all of them since two were from Amazon and might be genuine.
There are a lot of fake chips about, the only way to avoid them is to shop from trustworthy electronics
suppliers. You do get bargains from eBay, but you also get junk - you take that risk.
MarkT:
Fake from eBay perchance? Have you tried all of them since two were from Amazon and might be genuine.
Didn't know Amazon had that much better a track record for their third-part sellers than e-bay... and OP stated in their first post that they're all the same, so I'll take their word for it:
prestondocks:
[...] they are at address 0x0D (All three of them), [...]
The fakes can look very similar to the genuine part. A friend tells me that where they work with
high end digital projection equipment they have an X-ray machine they use on all chip deliveries
to see if the chip packages actually contain silicon!! If it doesn't pass X-ray inspection the delivery is
rejected unopened.
I have contacted the seller on ebay and he could not give me a refund quickly enough, which prevents me from leaving the negative feedback, however the item is still for sale.
Here is the picture of the chip if anyone is interested. From what I can see, the "DA" does not appear on the authentic chips. Perhaps it stands for Dead on Arrival.
Thanks for everyone's help. In the end and being a gluten for punishment I have decided to go for another cheap alternative and see if works any better. The LSM303 chip.
prestondocks:
I have contacted the seller on ebay and he could not give me a refund quickly enough, which prevents me from leaving the negative feedback, however the item is still for sale.
Contact Amazon about this.
Just curious: do they actually work with the alternative libraries?
From the respective data sheets I don't see much difference between the two chips. Specifications are very similar.
I, too, found the device registered to 0x0d through the i2C Scanner. And yes, these chips (the QMC5883L knockoff) is completely different from the HMC8553L chip and yes, they use a different library.
I've tested it and I am able to get consistent readouts, versus the irregular/sporadic/non-consistent readouts I got using the HMC8553L Library from Adafruit. I currently have it connected to a KeyStudio Arduino Uno and it works using both 5V and 3.3V i2C logic. Hope this helps someone in the future.