by JonHylands » Tue Aug 26, 2008 1:09 pm
by JonHylands
Tue Aug 26, 2008 1:09 pm
Well, I got my HMC6343 yesterday, and it took about an hour to write the code to interface to it, which worked the first time. Of course, the I2C code I ended up using had a couple nice examples, so it was easy to adapt them.
So it works really well - its very responsive, and will update its internal sensor values at either 1 Hz, 5 Hz (default), or 10 Hz.
I'm impressed - the hardest part of the whole thing was building the cable, with some built-in pullup resistors.
I used one of my General I/O boards, which has pin sockets for the two pins (C4 and C5) that are used for I2C, with a 3.3 volt regulator and a hacked in serial port. I grabbed some I2C interface code from here:
http://www.uoxray.uoregon.edu/orangutan/i2c.zip
which worked perfectly.
My code looked like this:
- Code: Select all
i2c_start_wait (COMPASS_ADDRESS_WRITE);
i2c_write (COMPASS_HEADING_COMMAND);
i2c_rep_start (COMPASS_ADDRESS_READ);
heading = (i2c_readAck () * 256) + i2c_readAck ();
pitch = (i2c_readAck () * 256) + i2c_readAck ();
roll = (i2c_readAck () * 256) + i2c_readNak ();
i2c_stop ();
printf ("Heading: %4d Pitch: %4d Roll: %4d\n", heading, pitch, roll);
- Jon
Well, I got my HMC6343 yesterday, and it took about an hour to write the code to interface to it, which worked the first time. Of course, the I2C code I ended up using had a couple nice examples, so it was easy to adapt them.
So it works really well - its very responsive, and will update its internal sensor values at either 1 Hz, 5 Hz (default), or 10 Hz.
I'm impressed - the hardest part of the whole thing was building the cable, with some built-in pullup resistors.
I used one of my General I/O boards, which has pin sockets for the two pins (C4 and C5) that are used for I2C, with a 3.3 volt regulator and a hacked in serial port. I grabbed some I2C interface code from here:
http://www.uoxray.uoregon.edu/orangutan/i2c.zip
which worked perfectly.
My code looked like this:
- Code: Select all
i2c_start_wait (COMPASS_ADDRESS_WRITE);
i2c_write (COMPASS_HEADING_COMMAND);
i2c_rep_start (COMPASS_ADDRESS_READ);
heading = (i2c_readAck () * 256) + i2c_readAck ();
pitch = (i2c_readAck () * 256) + i2c_readAck ();
roll = (i2c_readAck () * 256) + i2c_readNak ();
i2c_stop ();
printf ("Heading: %4d Pitch: %4d Roll: %4d\n", heading, pitch, roll);
- Jon