upm  0.4.1
Sensor/Actuator repository for libmraa (v0.8.0)
Public Member Functions

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.

hmc5883l.jpeg
// Instantiate on I2C
upm::Hmc5883l* compass = new upm::Hmc5883l(0);
int16_t *pos;
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
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());
sleep(1);
}

Public Member Functions

 Hmc5883l (int bus)
 
float direction ()
 
float heading ()
 
int16_t * coordinates ()
 
mraa::Result update ()
 
void set_declination (float dec)
 
float get_declination ()
 

Constructor & Destructor Documentation

Hmc5883l ( int  bus)

Creates an Hmc5883l object

Parameters
busNumber of the used I2C bus

Here is the call graph for this function:

Member Function Documentation

int16_t * coordinates ( void  )

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

Returns
*int to an int[3]
mraa::Result update ( void  )

Updates the values by reading from I2C

Returns
0 if successful

Here is the caller graph for this function:

void set_declination ( float  dec)

Sets the magnetic declination for better calibration

float get_declination ( )

Gets the current magnetic declination value

Returns
Magnetic declination as a floating-point value

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