?MC5883 compass problem

I'm trying to get a compass sensor to work. There is some uncertainty about whether it is a HMC or a QMC, I have tried libraries for both. The chip itself just has 5883 in microscopic letters. The most promising so far has been the Adafruit library for the HMC, which gave me the following output.

HMC5883 Magnetometer Test


Sensor: HMC5883
Driver Ver: 1
Unique ID: 12345
Max Value: 800.00 uT
Min Value: -800.00 uT
Resolution: 0.20 uT

in Loop
(The "in Loop" bit comes from a Serial.println added just after the start of the loop for diagnostic purposes.)

However, I don't really know if that information is coming from the actual sensor or from the library just saying what it thinks it should be. The Adafruit example code used for the above output seems to hang on a line that says:

mag.getEvent(&event); // This is where it is hanging.

The rest of the code is as per the Adafruit example code and compiles and uplads without any error messages.
The processor is a Freenove Uno clone.
I'm wondering if there is a problem with the I2C address of the sensor but don't know how to find out what it is, or for that matter what to change in any of the libraries I have tried if it is different to what they expect.
Thanks
John

Run the I2C scanner program. The HMC5883 and QMC5883 sensors have different I2C addresses.

Also, they are 3.3V devices, so you cannot directly connect them to a 5V Arduino. You need level shifters for the I2C connections.

Hi, Thanks for the quick reply. I had just found that there is such a thing as an I2C scanner and ran it, the result it gives is not the same as either the QMC or the HMC. It is 0x30. I guess that means it needs a different library.
According to the packaging, the module contains a level shifter. It also specifies a 5V supply and there are a couple of extra tiny chips on the board, presumably a regulator and a level shifter. It is from Duinotech, which is the Australian Jaycar outfit. They seem to be pretty crap on both documentation and support so I suspect the best way to get it going might be to order the equivalent device from Adafruit or one of the other suppliers.
regards
John

If it is a cheap module from Amazon, Alibaba, eBay or the like, it really could be anything: a complete fake, a crude counterfeit, or a factory reject. Genuine HMC5883 chips have not been manufactured for several years, and the newer magnetometers are better in any case.

Toss it in the wastebin and buy the genuine item from a reputable hobby supplier like Adafruit, Sparkfun, Pololu, or commercial suppliers like Mouser, Digikey, etc.

Jaycar are a supposedly reputable storefront retailer with lots of branches in Australia and NZ, however as I said they don't seem to be much good at documentation and software support for this sort of thing, but at least rather then throw it in the bin I should be able to get a refund.
regards
John

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.