Grove - 3-Axis Digital Compass

From Wiki 来自痴汉的爱
Jump to: navigation, search



This 3-axis digital compass features a low field magnetic sensing multi-chip module HMC5883L, which provides up to 1° to 2° heading accuracy. HMC5883L consists of high-resolution HMC118X series magneto-resistive sensors, as well as Honeywell developed ASIC containing amplification, automatic degaussing strap drivers, offset cancellation and 12 bit ADC. With peripheral power management circuit added, this is an easy to use and reliable compass module for low cost compassing and magnetometry.


3 axis compass.jpg


  • High resolution
  • Easy to control I2C interface
  • Compatible with either 3.3V or 5.0V development platform
  • Max 116Hz output rate
  • High heading accuracy

Applications Ideas

  • Low cost compassing
  • Magnetometry
  • Pedestrian Navigation
  • Hobby Auto Navigation
  • Compassing support for mobile devices and portable computers (i.e connected via Blue-tooth or UART)


Items Conditions Min Norm Max Unit
VCC - 3.3 5.0 6.0 Volts
Current Draw Sleep Mode - 2.5 - μA
Idle Mode - 240 - μA
Measurement Mode (8Hz averaged) - 640 - μA
Resolution - - 10 - milli-gauss
Linearity ±2.0 gauss input range - 0.1 - ±% FS
Output Rate - - 15 116 HZ
Measurement Period From receiving command to data ready - 8.3 - msec
Operating Temperature Ambient -30 85 °C milli-gauss
Storage Temperature Ambient, unbiased -40 - 125 °C


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. Plug the 3-axis compass into the I2C port of Grove - Base Shield.

2. Download the library file: Digital 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. Digital Compass1.jpg

4. Replace the value of variable "declinitionAngle" with the one you've figured out already.

5. Upload the Code. Please click here if you do not know how to upload.

6. Check the output result by opening the serial monitor.

Digital Compass2.jpg


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
Table: HMC5883L Register Map

There are five operation modes of this module. They are Continuous Measurement Mode, Single Measurement Mode, Idle Mode, Sleep Mode and Off Mode. The module is set by default in the Continuous Measurement Mode. But you can get higher level of control authority by changing the setting of these registers. Find more in its datasheet.



If you have questions or other better design ideas, you can go to our forum or wish to discuss.

Personal tools