Code for autonomous ground vehicle, Data Bus, 3rd place winner in 2012 Sparkfun AVC.

Dependencies:   Watchdog mbed Schedule SimpleFilter LSM303DLM PinDetect DebounceIn Servo

Embed: (wiki syntax)

« Back to documentation index

HMC5843 Class Reference

HMC5843 Class Reference

Interface library for the Honeywell HMC5843 digital compass. More...

#include <HMC5843.h>

Public Member Functions

 HMC5843 (PinName sda, PinName scl)
 Create a new interface for an HMC5843.
void setOffset (float x, float y, float z)
 sets the x, y, and z offset corrections for hard iron calibration
void setScale (float x, float y, float z)
 sets the scale factor for the x, y, and z axes
void setSleepMode ()
 Enter into sleep mode.
void setDefault ()
 Set Device in Default Mode.
void setOpMode (int mode, int ConfigA, int ConfigB)
 Set the operation mode.
void write (int address, int data)
 Write to a register on the device.
void read (int m[3])
 read the calibrated accelerometer and magnetometer values
void readMag (int m[3])
 read the calibrated magnetometer values
void readData (int *readings)
 Get the output of all three axes.
int getMx ()
 Get the output of X axis.
int getMy ()
 Get the output of Y axis.
int getMz ()
 Get the output of Z axis.
int getStatus (void)
 Get the current operation mode.
void getAddress (char *address)
 Read the memory location on the device which contains the address.
void frequency (int hz)
 sets the I2C bus frequency

Detailed Description

Interface library for the Honeywell HMC5843 digital compass.

Author:
Michael Shimniok http://www.bot-thoughts.com/
Based on library by Uwe Gartmann
In turn based on HMC5843 library developed by Jose R. Padron and Aaron Berk as template

This version is modified to follow the same member functions of my LSM303DLH library. The intent is to make it drop in compatible with my other magnetometer libraries. For now, setScale() and setOffset() have no effect at this time.

 #include "mbed.h"
 #include "HMC5843.h"

 HMC5843 compass(p28, p27);
 ...
 int m[3];
 ...
 compass.readMag(m);

Definition at line 130 of file HMC5843.h.


Constructor & Destructor Documentation

HMC5843 ( PinName  sda,
PinName  scl 
)

Create a new interface for an HMC5843.

Includes.

Parameters:
sdambed pin to use for SDA line of I2C interface.
sclmbed pin to use for SCL line of I2C interface.
Author:
Jose R. Padron
Used HMC6352 library developed by Aaron Berk as template

LICENSE

Copyright (c) 2010 ARM Limited

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

DESCRIPTION

Honeywell HMC5843digital compass.

Datasheet:

http://www.ssec.honeywell.com/magnetic/datasheets/HMC5843.pdf

Definition at line 40 of file HMC5843.cpp.


Member Function Documentation

void frequency ( int  hz )

sets the I2C bus frequency

Parameters:
frequencyis the I2C bus/clock frequency, either standard (100000) or fast (400000)

Definition at line 214 of file HMC5843.cpp.

void getAddress ( char *  address )

Read the memory location on the device which contains the address.

Parameters:
Pointerto a buffer to hold the address value Expected H, 4 and 3.

Definition at line 193 of file HMC5843.cpp.

int getMx (  )

Get the output of X axis.

Returns:
x-axis magnetic value

Definition at line 146 of file HMC5843.cpp.

int getMy (  )

Get the output of Y axis.

Returns:
y-axis magnetic value

Definition at line 159 of file HMC5843.cpp.

int getMz (  )

Get the output of Z axis.

Returns:
z-axis magnetic value

Definition at line 173 of file HMC5843.cpp.

int getStatus ( void   )

Get the current operation mode.

Returns:
Status register values

Definition at line 187 of file HMC5843.cpp.

void read ( int  m[3] )

read the calibrated accelerometer and magnetometer values

Parameters:
mis the magnetometer 3d vector, written by the function

Definition at line 107 of file HMC5843.cpp.

void readData ( int *  readings )

Get the output of all three axes.

Parameters:
Pointerto a buffer to hold the magnetics value for the x-axis, y-axis and z-axis [in that order].
void readMag ( int  m[3] )

read the calibrated magnetometer values

Parameters:
mis the magnetometer 3d vector, written by the function

Definition at line 114 of file HMC5843.cpp.

void setDefault ( void   )

Set Device in Default Mode.

HMC5843_CONTINUOUS, HMC5843_10HZ_NORMAL HMC5843_1_0GA

Definition at line 71 of file HMC5843.cpp.

void setOffset ( float  x,
float  y,
float  z 
)

sets the x, y, and z offset corrections for hard iron calibration

Calibration details here: http://mbed.org/users/shimniok/notebook/quick-and-dirty-3d-compass-calibration/

If you gather raw magnetometer data and find, for example, x is offset by hard iron by -20 then pass +20 to this member function to correct for hard iron.

Parameters:
xis the offset correction for the x axis
yis the offset correction for the y axis
zis the offset correction for the z axis

Definition at line 51 of file HMC5843.cpp.

void setOpMode ( int  mode,
int  ConfigA,
int  ConfigB 
)

Set the operation mode.

Parameters:
mode0x00 -> Continuous 0x01 -> Single 0x02 -> Idle
ConfigAvalues
ConfigBvalues

Definition at line 82 of file HMC5843.cpp.

void setScale ( float  x,
float  y,
float  z 
)

sets the scale factor for the x, y, and z axes

Calibratio details here: http://mbed.org/users/shimniok/notebook/quick-and-dirty-3d-compass-calibration/

Sensitivity of the three axes is never perfectly identical and this function can help to correct differences in sensitivity. You're supplying a multipler such that x, y and z will be normalized to the same max/min values

Definition at line 57 of file HMC5843.cpp.

void setSleepMode (  )

Enter into sleep mode.

Definition at line 63 of file HMC5843.cpp.

void write ( int  address,
int  data 
)

Write to a register on the device.

Parameters:
addressis the register address to be written.
datais the data to write.

Definition at line 92 of file HMC5843.cpp.