HMC5883L Electronic Compass

From Epalsite Wiki
Jump to: navigation, search

Introduction

3-Axis Compass module, I2C based Honeywell HMC5883 digital compass. This ASIC is equipped with high resolution HMC118X magneto-resistive sensors and a 12-bit ADC. It provides compass heading accuracy up to 1° to 2°. Signal conditioning like amplification, automatic degaussing strap drivers and offset cancellation are inbuilt. This module also includes a MIC5205-2.5 voltage regulator for power supply requirement. Hence user can connect any 3.3V to 6V DC power supply.
HMC5883L.jpg

Features

  • I2C interface
  • Compatible with 3.3V-5.0V voltage level
  • Max 116Hz output rate
  • High heading accuracy

Usage

Below is a register map that might help you understand what you can get from this module. There are totally 13 registers provided by HMC5883L. Out of three registers - Configuration register A, Configuration Register B and Mode Register decide the working mode of the device. The remaining registers are read only data output registers, status register and identification registers.
Compass picture4.png
This demo is going to show you how to read raw data, how to calibrate the data with your local magnetic declination angle and how to get heading angle.
First off, before any action you are going to take, you need to prepare a parameter you are going to use in your demo. That's your local magnetic declination.
You can find it out in degree via the magnetic declination webpage. For example, mine is -2°37’, which is -2.617 degree.
Then transfer it from degree to radians, and there you get the "declinationAngle". For example, in my case, declinationAngle = -2.617 / (2*π)= -0.0456752665 rad. Three significant figures are enough. So I would shorten it into -0.0456 rad. And this is the parameter you are going to replace the value of "declinationAngle" in the domo code with.
Now let's start to run your compass.

  1. Connect the HMC5883L Electronic Compass to Arduino via the I2C port.
  2. Download the library file: HMC5883L Compass library. Unzip it into the libraries file of Arduino IDE by the path: ..\arduino-1.0.1\libraries.
  3. Open the demo by the path:File -> Example ->Digital Compass ->HMC5883L_Example.
  4. Replace the value of variable "declinitionAngle" with the one you've figured out already.
  5. Upload the Code.
  6. Check the output result by opening the serial monitor.

Digital Compass2.PNG

Resources