Using the I2C Bus for Connecting the CMPS03 to the Dios 

Introduction
The compass module uses either a PWM output or the I2C bus for communications. This example uses the I2C Bus. The SDA (data) and SCL (clock) lines are connected to Port0 and Port1 on the Dios. The 4k7 resistors are only needed once on the I2C bus, not for each module and are normally located near the controller.

Circuit Schematic for connecting the Dios Mini Ultra to the CMPS03 Compass Module using the I2C bus

The CMPS03 is powered from the Dios Mini Ultra, which has an on-board 1amp regulator.


Software for the Dios Mini Ultra - this should be OK with all Dios variants

The sample code below displays the compass bearing as Degrees (0-359) in a Debug window on the PC.
It can be downloaded here


' Example program to read CMPS03

func main()
  const sda 0
  const scl 1
  const CMPS03 $C0     ' I2C bus address
  const Ver_reg 0      ' CMPS03 register addresses
  const Bearing_reg 2  ' Bearing
  dim  Ver, Bearing 
  while(1=1)           ' loop forever
    Ver = I2cin(sda,scl,CMPS03,Ver_reg)
    Bearing.byte(1) = I2cin(sda,scl,CMPS03,Bearing_reg)    ' high byte
    Bearing.byte(0) = I2cin(sda,scl,CMPS03,Bearing_reg+1)  ' low byte
    print "Version ", Ver, ", Bearing ",Bearing/10, " degrees"
  wend
endfunc
include \lib\DiosI2c.lib

You can find Compass Documentation Here as well as a small FAQ