WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

Honeywell/HMC5843.h

The HMC5843 compass sensor.
HMC5843.jpg
The image shows a carrier board from Sparkfun.
Datasheet: http://www.sparkfun.com/datasheets/Sensors/Magneto/HMC5843.pdf
This compass is accessed over I2C at address 0x3C. Since the device is really a magnetometer then the floating point maths library is used to calculate the bearing, roll and pitch in degrees.
To create a device use:-
HMC5843 compass = MAKE_HMC5843();
Example for the Axon:-
#include "sys/Axon.h"
#include "rprintf.h"
#include "Sensors/Compass/Honeywell/HMC5843.h"

HMC5843 compass = MAKE_HMC5843();


void appInitHardware(void){
   //setup UART
   uartInit(UART1, 9600);
   rprintfInit(&uart1SendByte);
   // Initialise compass
   compassInit(compass);
}

TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
   return 0;
}

// This is the main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){
   // Take a reading
   compassRead(compass);
 
   // Print out the values in degrees
   rprintf("Compass Bearing = %d\n",compass.compass.bearingDegrees);
   rprintf("Compass Roll = %d\n",compass.compass.rollDegrees);
   rprintf("Compass Pitch = %d\n",compass.compass.pitchDegrees);
 
   // Or just use the dump command
   compassDump(compass);
 
   // Alternatively the raw x,y,z magnetometer values can be shown
   rprintf("Compass Raw: x=%d, y=%d, z=%d\n",
      compass.rawX,compass.rawY,compass.rawZ);
   return 0;
}

 

Function

 


void HMC5843_1Hz(HMC5843* compass)

Changes the default refresh rate to once per second.

void HMC5843_2Hz(HMC5843* compass)

Changes the default refresh rate to twice per second (every 500ms).

void HMC5843_5Hz(HMC5843* compass)

Changes the default refresh rate to five temes per second (ie every 200ms)

void HMC5843_10Hz(HMC5843* compass)

Changes the default refresh rate to ten timer per second ie every 100ms

void HMC5843_20Hz(HMC5843* compass)

Changes the default refresh rate to twenty times per second ie every 50ms

void HMC5843_50Hz(HMC5843* compass)

Changes the default refresh rate to fifty times per second ie every 20ms

Valid XHTML 1.0 Transitional