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


The CMPS09 compass sensor with roll and pitch.
The compass is connected via the I2C bus and also requires a 3.3V or 5V regulated supply.
Example :-
#include "sys/Axon.h" // Change this to fit your board
#include "rprintf.h"
#include "Sensors/Compass/Devantech/CMPS09.h"

CMPS09_I2C cmps09 = MAKE_CMPS09(); // use default 0xC0 I2C address

void appInitHardware(void){
   //setup UART
   uartInit(UART1, 9600);
   // Initialise the compass

TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
   return 0;

// This is the main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){
   // Print each value one at a time
   rprintf("CMPS09 = %d\n",cmps09.compass.bearingDegrees);
   rprintf("CMPS09 roll = %d\n",cmps09.compass.rollDegrees);
   rprintf("CMPS09 pitch = %d\n",cmps09.compass.pitchDegrees);
   // Or print all in one go
   return 0;
You may also need to calibrate the compass depending upon where you are on the earth and this is also explained in the data sheet.

Valid XHTML 1.0 Transitional