Code:
'###############################################
'# For PICAXE-28X1 and Devantech CMPS03 Compass #
'###############################################
#picaxe 28x1
SetFreq m8
'###############################################
Main:
'COMPASS CODE
' Set up i2c for device
hi2csetup i2cmaster,%11000000,i2cfast_8,i2cbyte '%11000000 is device i2c bus address
Compass:
pause 1000
' hi2csetup i2cmaster,%11000000,i2cfast_8,i2cbyte
' If using multiple devices of different speeds on the bus,
' then use this line and remove the [%11000000] in the next line.
hi2cin [%11000000],0,(b22) ' Read CMPS03 Software Revision
' [%11010000] ensures correct i2c is read - reqd if more than one
' i2c device on bus being read in sequence
hi2cin 2,(b27,b26) ' Read compass bearing as a word (0-3599 for full circle)
' CMPS03 Register 2=HighByte, 3=LowByte. w2(b27)=highbyte, (b26)=Low byte
w12 = w13/10 ' /10 to get whole degrees
pause 500
sertxd ("FW Rev:",#b22," Compass Bearing:",#w12,cr,lf)
Goto Compass 'Loop for continuous display
Last edited: