My wiring is as follows -
HMC --- UNO
GND --- GND
VCC --- 5V
SCL --- A5
SDA --- A4
My code is fairly simple as start setup pretty normally, import the needed things then initialize the HMC with this-
Code: Select all
void Init_HMC5803L()
{
/* Set the module to 8x averaging and 15Hz measurement rate */
Wire.beginTransmission(HMC5803L_Address);
Wire.write(0x00);
Wire.write(0x70);
/* Set a gain of 5 */
Wire.write(0x01);
Wire.write(0xA0);
Wire.endTransmission();
}
Code: Select all
int HMC5803L_Read(byte Axis)
{
int Result;
/* Initiate a single measurement */
Wire.beginTransmission(HMC5803L_Address);
Wire.write(0x02);
Wire.write(0x01);
Wire.endTransmission();
delay(6);
/* Move modules the resiger pointer to one of the axis data registers */
Wire.beginTransmission(HMC5803L_Address);
Wire.write(Axis);
Wire.endTransmission();
/* Read the data from registers (there are two 8 bit registers for each axis) */
Wire.requestFrom(HMC5803L_Address, 2);
Result = Wire.read() << 8;
Result |= Wire.read();
return Result;
}
Here are the datasheets - https://cdn-shop.adafruit.com/datasheet ... ass_IC.pdf