Difference between revisions of "Sparkfun: HMC5883L Magnetometer"
(→Communicating with the HMC5883L Using the Shell) |
|||
Line 22: | Line 22: | ||
==Communicating with the HMC5883L Using the Shell== | ==Communicating with the HMC5883L Using the Shell== | ||
− | the HMC5883L has | + | the HMC5883L has 14 8-bit registers: |
{| style="color:green; background-color:#ffffcc;" cellpadding="10" cellspacing="0" border="1" | {| style="color:green; background-color:#ffffcc;" cellpadding="10" cellspacing="0" border="1" | ||
!scope="col"| Address | !scope="col"| Address | ||
Line 29: | Line 29: | ||
|- | |- | ||
| 00 | | 00 | ||
− | | | + | | WHO_AM_I |
| Read/Write | | Read/Write | ||
|- | |- | ||
− | | | + | | 15 |
− | | | + | | SMPLRT_DIV |
| Read/Write | | Read/Write | ||
|- | |- | ||
− | | | + | | 16 |
− | | | + | | DLPF_FS |
| Read/Write | | Read/Write | ||
|- | |- | ||
− | | | + | | 17 |
− | | | + | | INT_CFG |
+ | | Read/Write | ||
+ | |- | ||
+ | | 1A | ||
+ | | INT_STATUS | ||
| Read | | Read | ||
|- | |- | ||
− | | | + | | 1B |
− | | | + | | TEMP_OUT_H |
| Read | | Read | ||
|- | |- | ||
− | | | + | | 1C |
− | | | + | | TEMP_OUT_L |
| Read | | Read | ||
|- | |- | ||
− | | | + | | 1D |
− | | | + | | GYRO_XOUT_H |
| Read | | Read | ||
|- | |- | ||
− | | | + | | 1E |
− | | | + | | GYRO_XOUT_L |
| Read | | Read | ||
|- | |- | ||
− | | | + | | 1F |
− | | | + | | GYRO_YOUT_H |
| Read | | Read | ||
|- | |- | ||
− | | | + | | 20 |
− | | | + | | GYRO_YOUT_L |
| Read | | Read | ||
|- | |- | ||
− | | | + | | 21 |
− | | | + | | GYRO_ZOUT_H |
| Read | | Read | ||
|- | |- | ||
− | | | + | | 22 |
− | | | + | | GYRO_ZOUT_L |
| Read | | Read | ||
|- | |- | ||
− | | | + | | 3E |
− | | | + | | PWR_MGM |
− | | Read | + | | Read/Write |
|} | |} | ||
− | The sensor values for each axis are 16-bit and are stored across 2 registers each. | + | The sensor values for each axis are 16-bit and are stored across 2 registers each. GYRO_#OUT_H and GYRO_#OUT_L where # is just letter for the axis. Will have to get the two halves of the 16-bit signed measurement to read the entire value.. |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==Using C== | ==Using C== |
Revision as of 12:20, 26 September 2012
Contents
Overview
The HMC5883L Magnetometer is a sensor that measures the magnetic field vector in three dimensions. the Magnetometer uses a 400KHz I2C bus to communicate. The breakout board comes with filtering capacitors and four pins for the I2C, Vcc and ground.
Connecting to the Bone
The Beagle Bone can be connected to the magnetometer via the I2C bus, but the bone only has 100kHz I2C and communication is limited. Ground and Vcc on the breakout board should be connected to pins 1 and 2 respectively on the bone's P9 header, and the SCL and SDA pins should be connected to one of the I2C pairs on the bone. 4.7k resistors should be connected between SCL and Vcc and between SDA and Vcc. I used I2C3 (P9, pins 19 and 20). The address of the magnetometer can be found by using the i2cdetect command from the shell. I get:
beagle$ i2cdetect -y -r 3 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- UU -- -- 1e -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- UU UU UU UU -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --
The address should be 0x1e
Communicating with the HMC5883L Using the Shell
the HMC5883L has 14 8-bit registers:
Address | Name | Access |
---|---|---|
00 | WHO_AM_I | Read/Write |
15 | SMPLRT_DIV | Read/Write |
16 | DLPF_FS | Read/Write |
17 | INT_CFG | Read/Write |
1A | INT_STATUS | Read |
1B | TEMP_OUT_H | Read |
1C | TEMP_OUT_L | Read |
1D | GYRO_XOUT_H | Read |
1E | GYRO_XOUT_L | Read |
1F | GYRO_YOUT_H | Read |
20 | GYRO_YOUT_L | Read |
21 | GYRO_ZOUT_H | Read |
22 | GYRO_ZOUT_L | Read |
3E | PWR_MGM | Read/Write |
The sensor values for each axis are 16-bit and are stored across 2 registers each. GYRO_#OUT_H and GYRO_#OUT_L where # is just letter for the axis. Will have to get the two halves of the 16-bit signed measurement to read the entire value..
Using C
the I2C code from exercise 12 should work for the magnetometer, but it produces an error trying to read from or write to the device. This is probably because the magnetometer I2C operates at 400Khz and the bone uses 100kHz, so anything other than the simple shell commands produces corrupted data due to timing errors.