2-axis compass module

Where can I find the document? Do you have example program for it?

Hi,

You can refer to SparkFun.
sparkfun.com/commerce/produc … ts_id=7915

Thanks

#include <Wire.h>
int HMC6352Address = 0x42;
// This is calculated in the setup() function
int slaveAddress;
int ledPin = 13;
boolean ledState = false;
byte headingData[2];
int i, headingValue;
void setup()
{
// Shift the device’s documented slave address (0x42) 1 bit right
// This compensates for how the TWI library only wants the
// 7 most significant bits (with the high bit padded with 0)
slaveAddress = HMC6352Address >> 1; // This results in 0x21 as the address to pass to TWI
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // Set the LED pin as output
Wire.begin();
}
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) {
digitalWrite(ledPin,HIGH);
}
else
{
digitalWrite(ledPin,LOW);
}
// Send a “A” command to the HMC6352
// This requests the current heading data
Wire.beginTransmission(slaveAddress);
Wire.send(“A”); // The “Get Data” command
Wire.endTransmission();
Serial.println(“End transmission”);
delay(50); // 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
Serial.println(“Send end,Receive begin”);
Wire.requestFrom(slaveAddress, 2); // Request the 2 byte heading (MSB comes first)
i = 0;
while(Wire.available() && i < 2)
{
headingData[i] = Wire.receive();
i++;
}
headingValue = headingData[0]*256 + headingData[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(”.”);
Serial.print(int (headingValue % 10)); // The fractional part of the heading
Serial.println(" degrees");
delay(500);
}

This is the Arduino playground example,I have tested,but can not work.
it hang on Wire.send(“A”); // The “Get Data” command
Wire.endTransmission();
program seems stop here.why?

Hi,

I have tested your code, it can read the date of the module. So in my opinion, your code is OK, you can check your connection.

Thanks.

Send end,Receive begin
Current heading: 0.0 degrees
End transmission
Send end,Receive begin
Current heading: 2.6 degrees
End transmission
Send end,Receive begin
Current heading: 10.7 degrees
End transmission
Send end,Receive begin
Current heading: 17.5 degrees
End transmission
Send end,Receive begin
Current heading: 21.7 degrees
End transmission
Send end,Receive begin
Current heading: 23.4 degrees
End transmission
Send end,Receive begin
Current heading: 29.3 degrees
End transmission
Send end,Receive begin
Current heading: 30.8 degrees
End transmission
Send end,Receive begin
Current heading: 38.3 degrees
End transmission
Send end,Receive begin
Current heading: 46.7 degrees
End transmission
Send end,Receive begin
Current heading: 53.7 degrees
End transmission
Send end,Receive begin
Current heading: 56.7 degrees
End transmission
Send end,Receive begin
Current heading: 60.1 degrees
End transmission
Send end,Receive begin
Current heading: 69.7 degrees
End transmission
Send end,Receive begin
Current heading: 73.8 degrees
End transmission
Send end,Receive begin
Current heading: 77.4 degrees
End transmission
Send end,Receive begin
Current heading: 80.3 degrees
End transmission
Send end,Receive begin
Current heading: 84.3 degrees
End transmission
Send end,Receive begin
Current heading: 87.5 degrees
End transmission
Send end,Receive begin
Current heading: 90.0 degrees
End transmission
Send end,Receive begin
Current heading: 94.1 degrees
End transmission
Send end,Receive begin
Current heading: 99.0 degrees
End transmission
Send end,Receive begin
Current heading: 101.3 degrees
End transmission
Send end,Receive begin
Current heading: 110.3 degrees
End transmission
Send end,Receive begin
Current heading: 118.6 degrees
End transmission
Send end,Receive begin
Current heading: 118.6 degrees
End transmission
Send end,Receive begin
Current heading: 126.4 degrees
End transmission
Send end,Receive begin
Current heading: 140.0 degrees
End transmission
Send end,Receive begin
Current heading: 146.7 degrees
End transmission
Send end,Receive begin
Current heading: 155.2 degrees
End transmission
Send end,Receive begin
Current heading: 165.9 degrees
End transmission
Send end,Receive begin
Current heading: 180.4 degrees
End transmission
Send end,Receive begin
Current heading: 188.8 degrees
End transmission
Send end,Receive begin
Current heading: 195.5 degrees
End transmission
Send end,Receive begin
Current heading: 202.6 degrees
End transmission
Send end,Receive begin
Current heading: 208.3 degrees
End transmission
Send end,Receive begin
Current heading: 214.8 degrees
End transmission
Send end,Receive begin
Current heading: 226.8 degrees
End transmission
Send end,Receive begin
Current heading: 234.6 degrees
End transmission
Send end,Receive begin
Current heading: 242.3 degrees
End transmission
Send end,Receive begin
Current heading: 246.6 degrees
End transmission
Send end,Receive begin
Current heading: 251.5 degrees
End transmission
Send end,Receive begin
Current heading: 255.6 degrees
End transmission
Send end,Receive begin
Current heading: 260.7 degrees
End transmission
Send end,Receive begin
Current heading: 264.4 degrees
End transmission
Send end,Receive begin
Current heading: 271.0 degrees
End transmission
Send end,Receive begin
Current heading: 274.1 degrees
End transmission
Send end,Receive begin
Current heading: 280.0 degrees
End transmission
Send end,Receive begin
Current heading: 284.2 degrees
End transmission
Send end,Receive begin
Current heading: 288.1 degrees
End transmission
Send end,Receive begin
Current heading: 293.1 degrees
End transmission
Send end,Receive begin
Current heading: 302.2 degrees
End transmission
Send end,Receive begin
Current heading: 309.5 degrees
End transmission
Send end,Receive begin
Current heading: 314.4 degrees
End transmission
Send end,Receive begin
Current heading: 323.2 degrees
End transmission
Send end,Receive begin
Current heading: 351.1 degrees
End transmission



First I connect compass to ebrick chassis IIC port with 4 wire cable,and vcc to vcc,it can not work,even my Seeeduino v2.12 can not work too,all light off,even the PWR LED. So,I connect to the opposite side,i.e. vcc to scl,the Seeeduino v2.12 can work,but serial output show nothing. I find ebrick chasis IIC port scl and sda is different with compass,so I use single pin wire to connect vcc to vcc,scl to scl,sda to sda,but the Seeeduino v2.12 can not work too.
and I put the compass directly to the Seeeduino v2.12 and it can work only without ebrick chasis.But maybe I have burn the compass out,so it can only display 0 degree.So,the compass module can not work with your ebrick chasis IIC port.

Hi,

The Chasis’s IIC port is GND, VCC, SDA, SCL. And the Seeeduino board’s IIC port is VCC, GND, SCL, SDA.
You can refer to this when you connect your wire.

Regards.