upm  0.4.1
Sensor/Actuator repository for libmraa (v0.8.0)
Public Member Functions | List of all members

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
short[] pos;
// Set your declination from true north in radians
compas.set_declination(0.2749f);
while (true) {
// Update the coordinates
compas.update();
pos = compas.coordinates();
System.out.println("Coor: " + pos[0] + " " + pos[1] + " " + pos[2]);
System.out.println("Heading: " + compas.heading() + " Direction:" + compas.direction());
Thread.sleep(2000);
}

Public Member Functions

synchronized void delete ()
 
 Hmc5883l (int bus)
 
float direction ()
 
float heading ()
 
short[] coordinates ()
 
int 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

Member Function Documentation

short [] coordinates ( )

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

Returns
*int to an int[3]
float get_declination ( )

Gets the current magnetic declination value

Returns
Magnetic declination as a floating-point value
void set_declination ( float  dec)

Sets the magnetic declination for better calibration

int update ( )

Updates the values by reading from I2C

Returns
0 if successful

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