Tuesday, January 29, 2013

AVR Atmega HMC5883L magnetometer lib 01

The Honeywell HMC5883L is a surface-mount, multi-chip module designed for low-field magnetic sensing with a digital interface for applications such as lowcost compassing and magnetometry.

This library implements a way to get values from hmc5883l.

If your magnetometer stands with z-axis parallel to ground, you can get y and x raw values from magnetometer, and trasform it degrees using this formula:
heading = atan2(y_raw, x_raw) * 57.29578;
Then you should add magnetic declination (in degrees) for your location, to get yours visit http://magnetic-declination.com, if you have an EAST declination use +, if you have a WEST declination use -.
Then add this value to your heading.

Calibration is suggested to get more accurate parameters.

Setup parameters are stored in file hmc5883l.h

This library was developed on Eclipse, built with avr-gcc on Atmega8 @ 1MHz.
If you include math.h add libm library to linker.


Code


Notes
  • read risk disclaimer
  • excuse my bad english