upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions | Protected Attributes

API for the HMC5883L 3-Axis Digital Compass. More...

Detailed Description

Honeywell HMC5883L is a 3-axis digital compass. Communication with HMC5883L is simple and all done through an I2C interface. Different breakout boards are available. Typically, a 3V supply is all that is needed to power the sensor.

// Instantiate on I2C
upm::Hmc5883l compass(0);
compass.set_declination(0.2749); // Set your declination from
// true north in radians
// Print out the coordinates, heading, and direction every second
while (true) {
compass.update(); // Update the coordinates
const int16_t* pos = compass.coordinates();
fprintf(stdout, "coor: %5d %5d %5d ", pos[0], pos[1], pos[2]);
fprintf(stdout, "heading: %5.2f direction: %3.2f\n", compass.heading(), compass.direction());

Public Member Functions

 Hmc5883l (int bus)
float direction ()
float heading ()
const int16_t * coordinates ()
upm_result_t update ()
void set_declination (float dec)
float get_declination ()

Protected Attributes

hmc5883l_context m_hmc5883l

Constructor & Destructor Documentation

Hmc5883l ( int  bus)

Creates an Hmc5883l object. The I2C address cannot be changed, and is always 0x1e (7-bit).

busI2C bus number

Member Function Documentation

const int16_t * coordinates ( void  )

Returns a pointer to an int[3] that contains the coordinates as ints

*int to an int[3]

Here is the call graph for this function:

upm_result_t update ( void  )

Updates the values by reading from I2C

0 if successful

Here is the call graph for this function:

void set_declination ( float  dec)

Sets the magnetic declination for better calibration

Here is the call graph for this function:

float get_declination ( )

Gets the current magnetic declination value

Magnetic declination as a floating-point value

Here is the call graph for this function:

Collaboration diagram for Hmc5883l:
Collaboration graph

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