Shop OBEX P1 Docs P2 Docs Learn Events
hmc588l programming help needed — Parallax Forums

hmc588l programming help needed

psyopticapsyoptica Posts: 1
edited 2013-08-24 12:35 in Accessories
I have a small problem I hope someone having experience with sensors can resolve. I'm using a digital compass sensor hmc5883l. The code to read the compass heading is for a different compass model hmc6352. For some reason I need to use this code for my sensor. So I changed the slave read/write address in the code but it still doesn't work. What else do I need to change. I have very little knowledge about i2c devices.

slave read address for hmc5883l= 0x3D
slave write address for hmc5883l= 0x3C

Code for hmc6352 is posted below
#include <Wire.h>

int HMC6352Address = 0x42;
int slaveAddress;
byte headingData[2];
int i, headingValue;
int headingcompass;

void setup(){
slaveAddress = HMC6352Address >> 1;  
Wire.begin();
Serial.begin(115200);

}

void loop(){

Wire.beginTransmission(slaveAddress);        //the wire stuff is for the compass module

  Wire.send("A");              

  Wire.endTransmission();

  delay(10);                  

  Wire.requestFrom(slaveAddress, 2);       

  i = 0;

  while(Wire.available() && i < 2)

  { 

    headingData[i] = Wire.receive();

    i++;

  }

  headingValue = headingData[0]*256 + headingData[1];

 int pracheading = headingValue / 10;      // this is the heading of the compass

 if(pracheading>0){

   headingcompass=pracheading;

 }

Serial.println("current heading:");

Serial.println(headingcompass);
}

Comments

  • FranklinFranklin Posts: 4,747
    edited 2013-08-23 22:19
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-08-24 12:35
    psyoptica wrote: »
    I'm using a digital compass sensor hmc5883l. The code to read the compass heading is for a different compass model hmc6352. For some reason I need to use this code for my sensor.

    The HMC6352 will output a heading, the HMC5883L does not. You can not use the same code for both devices.

    The HMC5883L outputs the three axis vector of the magnetic field. You need to use some trig (arctangent) function to convert the vector to a heading.
Sign In or Register to comment.