' Hitechnic NXT Compass Sensor (part MS1034)
symbol heading_2degree = b0
symbol heading_adder = b1
symbol heading = w1
' Wires on NXT jack plug.
' Wire colours may vary. Pin 1 is always end nearest latch.
' 1 White No connect
' 2 Black 0V
' 3 Red 0V
' 4 Green V+ (4.5V or 5V)
' 5 Yellow SCL
' 6 Blue SDA
' Do not use i2c pullup resistor - already provided within sensor.
init:
'Slave address is $02
hi2csetup i2cmaster $02, i2cslow, i2cbyte
'Optional configuration
hi2cout $41,($00) ; normal mode
'hi2cout $41,($43) ; hard iron calibrate mode
pause 100
main:
; read values
hi2cin $42,(heading_2degree) ', heading_adder
heading = heading_2degree * 2 '+ heading_adder
; debug display
debug
; wait 1 second then loop
pause 1000
goto main