Society of Robots
     | Robot Forum | Robot Tutorials | Robot FAQ |
September 02, 2010, 09:47:31 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: SoR Robot Chat every friday night. Join us! (forum integration fix coming when I have time)
http://www.societyofrobots.com/robotforum/chat/

Robot Forum
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: HMC6343 compass code for Axon, I2C  (Read 1985 times)
0 Members and 1 Guest are viewing this topic.
AdminTopic starter
Administrator
Supreme Robot
*****

Helpful? 110
Offline Offline

Posts: 9,833



View Profile WWW
« on: June 30, 2009, 08:54:38 AM »

I got a HMC6343 Compass hooked up to my Axon, using I2C. Here is some code I'd like to share . . . don't forget to include the I2C AVRlib library. Grin

Code:
//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];  //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[0]);  //read 6 byte data from slave to master

//process heading data:
compass = in[0];  //first byte is MSB heading
compass = compass << 8;  //shift MSB byte to top of int
compass = compass + in[1];  //add LSB byte (2nd byte) to bottom of int
compass = compass; // / 10;

//process pitch data:
pitchCompass = in[2];  //3rd byte is MSB pitch
pitchCompass = pitchCompass << 8;
pitchCompass = pitchCompass + in[3];  //4th byte is LSB pitch
pitchCompass = pitchCompass / 10;
if(pitchCompass > 6400)
pitchCompass = (pitchCompass - 6400 - 155);  //convert to negative values

//process roll data:
rollCompass = in[4];  //5th byte is MSB roll
rollCompass = rollCompass << 8;
rollCompass = rollCompass + in[5];  //6th byte is LSB roll
rollCompass = rollCompass / 10;
if(rollCompass > 6400)
rollCompass = (rollCompass - 6400 - 155);  //convert to negative values

Output of course is pitchCompass and rollCompass.

Also a comment on this compass . . . I'm using it on my robot fish. The fish uses a waterproof magnet switch . . . the magnet is weak, and 2-3 inches away from the compass, but still affects results by about +/- 13% (absolute value 27%). Hopefully that info helps someone!


edit: changed the % error, due to my own error Tongue
« Last Edit: July 01, 2009, 12:01:40 PM by Admin » Logged

Razor Concepts
Supreme Robot
*****

Helpful? 49
Offline Offline

Posts: 1,743



View Profile WWW
« Reply #1 on: June 30, 2009, 05:21:17 PM »

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.
Logged

AdminTopic starter
Administrator
Supreme Robot
*****

Helpful? 110
Offline Offline

Posts: 9,833



View Profile WWW
« Reply #2 on: June 30, 2009, 10:08:33 PM »

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.

Hmmmm I haven't done any real testing of it yet to comment. But outside interference can definitely make it non-proportional!
Logged

Ro-Bot-X
Contest Winner
Supreme Robot
****

Helpful? 19
Offline Offline

Posts: 1,282


Current project: MiniEric robot.


View Profile
« Reply #3 on: July 01, 2009, 07:21:04 AM »

I have an old Lego compass and I have noticed that it needs a bit of time to settle if the robot was moving and the measurements are not reliable while in motion, even it it is a streight line. This sensor is similar with the Devantech CMPS03, I had the same problems with that one too. So, it may be a good idea to keep the robot still while checking the compass, then let it move. Why? because of magnetic interference from the motors.
Logged

Check out my new blog!
 SeriousRobotics
AdminTopic starter
Administrator
Supreme Robot
*****

Helpful? 110
Offline Offline

Posts: 9,833



View Profile WWW
« Reply #4 on: July 01, 2009, 12:03:52 PM »

Why? because of magnetic interference from the motors.
Not to mention the power fluctuations in your system, and the 'moving' environment. What if your floor had a steel I-beam under it and you didn't know? etc.


note: I changed the reported error above, had a typo . . .
Logged

Pages: [1]
  Print  
 
Jump to:  


Related Topics
Subject Started by Replies Views Last post
Need some help on interrupt code (axon)
Software
Tomas 2 714 Last post February 11, 2009, 11:10:10 PM
by Admin
new Axon source code v1.11
Software
Admin 0 387 Last post October 20, 2009, 08:46:43 PM
by Admin
Axon - I need an Example Source Code of PWM !
Software
Hasan999 1 450 Last post December 26, 2009, 12:30:03 AM
by Admin
compass module HMC6343
Software
joco000 1 282 Last post May 21, 2010, 11:20:41 AM
by Admin
Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!


Advertise on this Forum