HMC6352 Compass and I2c

Hi All,

I have been trying to get the HMC6352 compass module from sparkfun to work without any success.

I have used every variation of code examples that i could find. I tried the one from the playground, I tried the library from here, and read through every post that I can find.

It seems as though some people have gotten this working, but I just cant get it to go. I have been able to get them to compile, and run, but it just wont send the data back.

To check if perhaps mine had a different address, I tried to run the I2c scanner from here, this however didnt work for me. When I opened the serial port to view the output, there were just garbage characters.

This has got me wondering if there is something wrong with either my arduino, or my compass.

I am really stumped with this, and have gone past my ability to trouble shoot it.

If anyone can point me in the direction of working compass code that runs on v0018 or another way for me to test either the board or the sensor, I would really appreciate it.


Are you sure you connected your compass module to analog pins?

Maybe you mismatched it and connected to digital pins instead?

Hope it helps.

Hi calc,

Did you ever have any eventual success with the compass? I have the exact same problem as you. I also tried the I2C scanner and it didn't work for me either :-?.

The results I usually obtain are:

-the compass always puts out "heading = 0.0" or -its always puts out the same value e.g. 80 degrees (at any orientation)

Its usually gives one or the other of these results depending on the sketch or library used.

Any advice would be appreciated...

Try adding one 10K resistor to each SDA and SDL line to the ground, see if that improves the response from the sensor.

10K resistor to each SDA and SDL line to the ground,

No the resistor should be 4K7 and go from each line to +5V.


I hesitate to post this - I probably have something wonky with my IDE setup, but I spent a few hours this weekend getting my HMC6352 to work. I foud it wouldn’t work with REL 0017, but worked fine with REL 0021! ::slight_smile: (No pullups used.)

(I don’t remember if I ever changed wire to use fast I2C.)

On REL 0017, I’d get 2 bytes back but zeros. On REL 0021 it worked fine with this example.

I know I used REL 0017 with other I2C (GPIO, RTC, etc.) but the coincidence with your issue was too much not to post.

Okay, I guess I should have mentioned I'm using a HMC module like the one seen here so the pull up resistors are already in place.

My initial thoughts were that I was looking at the wrong eeprom address. I find the fact that the I2C scanner seen above didn't detect anything quite strange. You'd think it would detect the HMC straight away.

@BroHogan Like yourself I have succesfully used the DS1307 real time clock on I2C and that seemed to work perfectly. So the REL version you used made the difference huh? I'm currently using ver 0021 so maybe I'll check to see if any older versions work...

Thanks for the input guys. :)

If you're interested, the project is a two axis solar tracker. I'd like the compass to be used for azimuth positioning to allow for quick and accurate calibration and positioning. Also a much cheaper option than an equivalently accurate rotary encoder.