Beginners: please read this post and this post before posting to the forum.
0 Members and 1 Guest are viewing this topic.
//Read HMC6343 compass I2C data: u08 TARGET_ADDR = 0x32; //0x32 = HMC6343 compass slave write address u08 command = 0x50; //0x50 = post heading data, pitch data, and roll data u08 in; //6 bytes = MSB heading, LSB heading, MSB pitch, LSB pitch, MSB roll, LSB roll i2cMasterSend(TARGET_ADDR, 1, &command); //send 1 byte command to slave from master delay_ms(10); i2cMasterReceive(TARGET_ADDR, 6, &in); //read 6 byte data from slave to master //process heading data: compass = in; //first byte is MSB heading compass = compass << 8; //shift MSB byte to top of int compass = compass + in; //add LSB byte (2nd byte) to bottom of int compass = compass; // / 10; //process pitch data: pitchCompass = in; //3rd byte is MSB pitch pitchCompass = pitchCompass << 8; pitchCompass = pitchCompass + in; //4th byte is LSB pitch pitchCompass = pitchCompass / 10; if(pitchCompass > 6400) pitchCompass = (pitchCompass - 6400 - 155); //convert to negative values //process roll data: rollCompass = in; //5th byte is MSB roll rollCompass = rollCompass << 8; rollCompass = rollCompass + in; //6th byte is LSB roll rollCompass = rollCompass / 10; if(rollCompass > 6400) rollCompass = (rollCompass - 6400 - 155); //convert to negative values
Are the heading readings you are getting good? I've tried using a HMC6352 (no tilt compensation) and the readings are not proportional, but in between 360 and 0 degrees.
Why? because of magnetic interference from the motors.
Started by mbateman
Started by Its_Friday
Started by Tomas
Started by joco000