HMC5883L Triple Axis Magnetometer Breakout

From Geeetech Wiki
Revision as of 06:55, 6 October 2012 by Admin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Product Overview

Hmc5883L.jpg

This is a breakout board for The Honeywell HMC5883L . The Honeywell HMC5883L is a multi-chip module designed for low-field magnetic sensing with a digital interface for applications such as low-cost compassing and magnetometry. The HMC5883L includes our state-of-the-art, high-resolution HMC118X series magneto-resistive sensors plus an ASIC containing amplification, automatic degaussing strap drivers, offset cancellation, and a 12-bit ADC that enables 1° to 2° compass heading accuracy. The I2C serial bus allows for easy interface. Applications for the HMC5883L include Mobile Phones, Netbooks, Consumer Electronics, Auto Navigation Systems, and Personal Navigation Devices.

The HMC5883L utilizes Honeywell’s Anisotropic Magnetoresistive (AMR) technology that provides advantages over other magnetic sensor technologies. These anisotropic, directional sensors feature precision in-axis sensitivity and linearity. These sensors’ solid-state construction with very low cross-axis sensitivity is designed to measure both the direction and the magnitude of Earth’s magnetic fields, from milli-gauss to 8 gauss. Honeywell’s Magnetic Sensors are among the most sensitive and reliable low-field sensors in the industry.

Applications

Mobile Phones, Netbooks
Consumer Electronics
Auto Navigation Systems
Personal Navigation Devices


Features

The Honeywell HMC5883L includes a wide range of features:
3-Axis Magnetoresistive Sensors and ASIC in a 3.0x3.0x0.9mm LCC Surface Mount Package
12-Bit ADC Coupled with Low Noise AMR Sensors Achieves 2 milli-gauss Field Resolution in ±8 Gauss Fields
Low Voltage Operations (2.16 to 3.6V) and Low Power Consumption (100 μ A)
I2C Digital Interface
Wide Magnetic Field Range (+/-8 Oe)

Document

HMC5883L Library for Arduino IDE 023

HMC5883L Library for Arduino IDE 1.0

HMC5883L Datasheet

Usage

Hm5883l连线图.png

Arduino GND -> HMC5883L GND
Arduino 3.3V -> HMC5883L VCC
Arduino A4 (SDA) -> HMC5883L SDA
Arduino A5 (SCL) -> HMC5883L SCL
  • You will also need to add two 'pull-up' resistors to enable I2C. For this, connect two 4.7k or 10k resistors between SDA and VCC, and SCL and VCC

Example code

#include <Wire.h>
// Reference the HMC5883L Compass Library
#include <HMC5883L.h>
// Store our compass as a variable.
HMC5883L compass;
// Record any errors that may occur in the compass.
int error = 0;
// Out setup routine, here we will configure the microcontroller and compass.
void setup()
{
 // Initialize the serial port.
 Serial.begin(9600);
 Serial.println("Starting the I2C interface.");
 Wire.begin(); // Start the I2C interface.
 Serial.println("Constructing new HMC5883L");
 compass = HMC5883L(); // Construct a new HMC5883 compass.
 Serial.println("Setting scale to +/- 1.3 Ga");
 error = compass.SetScale(1.3); // Set the scale of the compass.
 if(error != 0) // If there is an error, print it out.
   Serial.println(compass.GetErrorText(error));
   Serial.println("Setting measurement mode to continous.");
 error = compass.SetMeasurementMode(Measurement_Continuous); // Set the measurement  mode to Continuous
 if(error != 0) // If there is an error, print it out.
   Serial.println(compass.GetErrorText(error));
}
// Our main program loop.
void loop()
{
 // Retrive the raw values from the compass (not scaled).
 MagnetometerRaw raw = compass.ReadRawAxis();
 // Retrived the scaled values from the compass (scaled to the configured scale).
 MagnetometerScaled scaled = compass.ReadScaledAxis();
 // Values are accessed like so:
 int MilliGauss_OnThe_XAxis = scaled.XAxis;// (or YAxis, or ZAxis)
 // Calculate heading when the magnetometer is level, then correct for signs of axis.
 float heading = atan2(scaled.YAxis, scaled.XAxis);
 // Once you have your heading, you must then add your 'Declination Angle', which is  the 'Error' of the magnetic field in your location.
 // Find yours here: http://www.magnetic-declination.com/
 // Mine is: 2� 37' W, which is 2.617 Degrees, or (which we need) 0.0456752665  radians, I will use 0.0457
 // If you cannot find your Declination, comment out these two lines, your compass  will be slightly off.
 float declinationAngle = 0.0457;
 heading += declinationAngle;
 // Correct for when signs are reversed.
 if(heading < 0)
   heading += 2*PI;
   // Check for wrap due to addition of declination.
 if(heading > 2*PI)
   heading -= 2*PI;
  // Convert radians to degrees for readability.
 float headingDegrees = heading * 180/M_PI; 
 // Output the data via the serial port.
 Output(raw, scaled, heading, headingDegrees);
 // Normally we would delay the application by 66ms to allow the loop
 // to run at 15Hz (default bandwidth for the HMC5883L).
 // However since we have a long serial out (104ms at 9600) we will let
 // it run at its natural speed.
 // delay(66);
}
// Output the data down the serial port.
void Output(MagnetometerRaw raw, MagnetometerScaled scaled, float heading, float  headingDegrees)
{
  Serial.print("Raw:\t");
  Serial.print(raw.XAxis);
  Serial.print("   ");   
  Serial.print(raw.YAxis);
  Serial.print("   ");   
  Serial.print(raw.ZAxis);
  Serial.print("   \tScaled:\t");
  //
  Serial.print(scaled.XAxis);
  Serial.print("   ");   
  Serial.print(scaled.YAxis);
  Serial.print("   ");   
  Serial.print(scaled.ZAxis);
  //
  Serial.print("   \tHeading:\t");
  Serial.print(heading);
  Serial.print(" Radians   \t");
  Serial.print(headingDegrees);
  Serial.println(" Degrees   \t");
}


How to buy

Click here to buy HMC5883L Triple Axis Magnetometer Breakout