Go Down

Topic: HMC6352 (Read 12933 times) previous topic - next topic


Hey guys,
I'm trying to get the HMC6352 working with the mini.

When using the mini do i need pull up resisters, and if so what value were you guys using?

Also, when trying to hook this up the first time, the chip got really hot.
Is there a way to check just the Compass module to know if it is working? (Such as, connect power and ground, then ground the SCL line and release and watch the output on an oscilloscope?)

Thanks for all of your posts so far, we have made quite a bit of progress on our project, the only sensor we have not interfaced with is this compass, and im thinking we might have busted it.


I'd really like to see the AVRlib code for HMC6352.  Would anyone mind posting it?


Try this code:


Does anyone know how to configure and read heading values using SPI?  The digital compass I'm using is the Compass Module - Vector 2Xe (http://www.sparkfun.com/commerce/product_info.php?products_id=236).  I know the basics of SPI but don't know how to implement it.  On the product's data sheet it mentions certain functions like SetConfiguration and GetData but I don't know if I have to write these functions myself or if there is an existing library that I can use.  Some help or suggestions would be great!  


The code listed here:


begins with #include <TwoWire.h>, this did not compile, I changed it to Wire.h and it compiled fine, has anyone else found this?


The digital compass I'm using is the Compass Module - Vector 2Xe

you should start a new topic - this is a completely different animal than the one being discussed in this thread.  There are lots more differences than SPI vs I2C.
On the product's data sheet it mentions certain functions like SetConfiguration and GetData but I don't know if I have to write these functions myself

Yep, unless you see source code in the datasheet (or maybe on the vendor's web site, in an app note, etc).

I've got a passing interest in the Vector compass modules myself since a) I would like to have an accurate computer interfaced compass in my truck, and b) have access to a module.  Don't have a lot of time right now, though...



Hey guys,

I know this topic is dead for long, but I've spent the entire last week trying to resolve all my HMC6352 problem, so that's my solution:

I worked with an arduino mini Pro 5V and Arduino0018 (the latest version) on XP.

Initially, the HMC6352 didn't work at all : I always saw on serial interface "current heading=0.0" (I used the same code as everybody, based on Wire.h". I don't remenber all the changes I made on the code, and all problem I've had : no EndTransmission(), etc.

This solution works fine :
- SDA and SCL on pin A4 and A5
- no pull-up resistors
- HMC6352 supplied with the VCC pin of Arduino (yes, I know it's a bit too high, but HMC accepts)
- GND to GND of course

First, I downloaded the I2CScanner by todbot, here : (http://todbot.com/blog/2009/11/29/i2cscanner-pde-arduino-as-i2c-bus-scanner/)
This .pde is very precious : uploaded on the arduino, it tests all the I2C address between 1 and 100 and returns if a component is present or not. And, surprise!, i discovered that my HMC6352'adress is neither 0x42, nor 0x21, but 0x33! (as the HMC6343... Why? I will surely never know...).

Secondly, due to this .pde also, I have tryed not to used Wire.h, which is likely not efficient for Arduino pro mini. This is my code :
Code: [Select]
#include <Wire.h>  // only to allow to include twi.h
extern "C" {
#include "utility/twi.h"
byte addr =33;  // address of your I2C slace : just copy the address found by I2CScanner (I don't pay attention to 7- or 8-bit)
int ledPin = 13;
boolean ledState = false;
byte data[2];
int i, headingValue;
void setup()
pinMode(ledPin, OUTPUT);      // Set the LED pin as output
delay(10); // to enable twi to be initiated correctly
void loop()
 // Flash the LED on pin 13 just to show that something is happening
 // Also serves as an indication that we're not "stuck" waiting for TWI data
 ledState = !ledState;
 if (ledState) {
 // Send a "A" command to the HMC6352
 // This requests the current heading data
 byte cmd[1];
 cmd[0] = 0x41;
 // method twi_writeTo from twi.h : send an array of bytes(cmd), length 1 byte (it's the first "1" input), to the slave addressed by addr.
 // The last input "1" is a boolean to make the method wait for the completion of the sending
 // return a indication of successful : 0:success, 1 to 4:error (search in twi.h to precision)
 int res=twi_writeTo(addr, cmd, 1, 1);
 Serial.print("A envoye=");
 delay(10);                   // The HMC6352 needs at least a 70us (microsecond) delay
 // after this command.  Using 10ms just makes it safe
 // Read the 2 heading bytes, MSB first
 // The resulting 16bit word is the compass heading in 10th's of a degree
 // For example: a heading of 1345 would be 134.5 degrees
 // method twi_readFrom from twi.h : receive 2 bytes (the "2" input), from the slave addressed by addr, and register in the byte array data
 // return the number of bytes read
 int N=twi_readFrom(addr, data, 2);
 Serial.print("Nb byte recus=");
 headingValue = data[0]*256 + data[1];  // Put the MSB and LSB together
 Serial.print("Current heading: ");
 Serial.print(int (headingValue / 10));     // The whole number part of the heading
 Serial.print(int (headingValue % 10));     // The fractional part of the heading
 Serial.println(" degrees");

I will do something to remove the include "Wire.h" on the top, but it works.

Thank you everybody for help, I've read at least 5 times every topics about HMC6352 ! ;)


Ps: don't pay attention to my english, you've made out that it's not my native tongue...


Hello all,

I have connected my HMC6352 to an Arduino Duemilanove the same way Louix did. I also used the code he posted (it's a lot like all the other samples I found). He said he found out that he had to use address 33 instead of 42, so I tried address 42, 21 and 33. None of those returned valid output.
When I run that code the only thing I get is:
"A envoye=2
Nb byte recus=0
Current heading: 0.0 degrees"

So it doesn't really work, when I use I2CScanner it doesn't find anything. Does anyone have an idea how to solve it or what to try to get any further?



I have the exact same problem as you. I have tried every variation of code found for the compass and I always get the same "heading = 0.0 degrees."

Did you ever manage to solve your problem? Any advice would be great, my head is melting because of this damn thing... :-/

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131