HMC5883L Magnetometer Arduino Library
 All Classes Files Functions Variables Macros
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Magnetometer Class Reference

#include <HMC5883Llib.h>

Public Member Functions

int8_t begin ()
 
int8_t readRaw (int16_t *x, int16_t *y, int16_t *z)
 
int8_t readGauss (double *x, double *y, double *z)
 
int8_t setGain (uint8_t gain)
 
int8_t readHeadingDeg (double *heading)
 

Protected Member Functions

int8_t i2cReadBytes (uint8_t reg, uint8_t *data, uint8_t len)
 
int8_t i2cWriteByte (uint8_t reg, uint8_t data)
 

Protected Attributes

uint8_t i2cAddr_
 
uint8_t gain_
 

Detailed Description

Represents a HMC5883L bassed Magnetometer sensor. You must call begin before calling any other methods.

Member Function Documentation

int8_t Magnetometer::begin ( )

Attenpts to connect to the device. You must call begin before calling any other method.

Returns
Returns 0 if it successfully connects to the Gyroscope sensor. Returns any other non-zero number if it fails. Check HMC5883Llib.h for the various ERROR definitions.
int8_t Magnetometer::i2cReadBytes ( uint8_t  reg,
uint8_t *  data,
uint8_t  len 
)
protected

I2C interface function for reading bytes. Uses the Arduino Wire library.

Parameters
regThe first register to read from.
dataThe array where the data will be read into.
lenThe number of bytes to read.
Returns
Returns 0 on success. Returns any other non-zero number if it fails. Check HMC5883Llib.h for the various ERROR definitions.
int8_t Magnetometer::i2cWriteByte ( uint8_t  reg,
uint8_t  data 
)
protected

I2C interface function for writing a single byte. Uses the Arduino Wire library.

Parameters
regThe register address to write to.
dataThe byte to write.
Returns
Returns 0 on success. Returns any other non-zero number if it fails. Check HMC5883Llib.h for the various ERROR definitions.
int8_t Magnetometer::readGauss ( double *  x,
double *  y,
double *  z 
)

Reads the Gauss experienced by the Magnetometer.

Parameters
xA pointer to the variable that will get the x data recorded to (in Ga).
yA pointer to the variable that will get the y data recorded to (in Ga).
zA pointer to the variable that will get the z data recorded to (in Ga).
Returns
Returns 0 on success. Returns any other non-zero number if it fails. Check HMC5883Llib.h for the various ERROR definitions.
int8_t Magnetometer::readHeadingDeg ( double *  heading)

Compass function. Reads the heading in degrees (0-360). Uses the X and Y axes readings to calculate the heading. The sensor must be as level as possible for accurate results.

Parameters
headingA pointer to the variable that will get the heading recorded to (in degrees).
Returns
Returns 0 on success. Returns any other non-zero number if it fails. Check HMC5883Llib.h for the various ERROR definitions.
int8_t Magnetometer::readRaw ( int16_t *  x,
int16_t *  y,
int16_t *  z 
)

Reads the RAW data from the magnetometer as a signed 16 bit integer. This integer does not represent Gauss. You'll probably want to use readGauss instead.

Parameters
xA pointer to the variable that will get the x raw data recorded to.
yA pointer to the variable that will get the y raw data recorded to.
zA pointer to the variable that will get the z raw data recorded to.
Returns
Returns 0 on success. Returns any other non-zero number if it fails. Check HMC5883Llib.h for the various ERROR definitions.
int8_t Magnetometer::setGain ( uint8_t  gain)

The HMC5883L has an adjustable gain to help you fine tune the sensitivity.

Parameters
gainThe gain definition. Check HMC5883Llib.h for possible arugments. Defaults range is +-1.3Ga.
Returns
Returns 0 on success. Returns any other non-zero number if it fails. Check HMC5883Llib.h for the various ERROR definitions.

Member Data Documentation

uint8_t Magnetometer::gain_
protected

The gain definition enum of the device.

uint8_t Magnetometer::i2cAddr_
protected

The I2C address of the device.


The documentation for this class was generated from the following files: