#picaxe 28x1
#no_table
' PICAXE-28X1 sample program for two Hitechnic NXT Sensors plus AXE033
' display in I2C mode.
' Note : As operating on 4.5V supply installed jumpers on J1 and J2
' Hitechnic NXT Compass Sensor (part MS1034)
symbol heading_2degree = b0
symbol heading_adder = b1
symbol heading = w1
' Hitechnic NXT IRSEeker V2
symbol ac_direction = b10
symbol sensor1_ac = b11
symbol sensor2_ac = b12
symbol sensor3_ac = b13
symbol sensor4_ac = b14
symbol sensor5_ac = b15
' Wires on NXT jack plug.
' Wire colours may vary. Pin 1 is always end nearest latch.
' 1 White 9V (for IRseeker)
' 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 of compasss is $02
'Slave address of IRSeeker2 is $10
'Slave address of AXE033 is $C6
hi2csetup i2cmaster, $02, i2cslow, i2cbyte
hi2csetup i2cmaster, $10, i2cslow, i2cbyte
hi2csetup i2cmaster, $C6,i2cslow,i2cbyte
'Optional configuration of compass
hi2cout [$02],$41,($00) ; normal mode
;hi2cout [$02],$41,($43) ; hard iron calibrate mode
pause 500
'Optional configuration of IRSEEKER2
hi2cout [$10],$41,($00) ; normal AC mode
;hi2cout [$10],$41,($02) ; uncalibrated DC mode
hi2cout [$c6], 0,(254,1,255) ' clearing screen
pause 100
hi2cout [$c6], 0,(254,128," SHC Soccerbot ",255) ' just some random message
pause 100
hi2cout [$c6], 0,(254,192," ..booting up.. ",255)' another random message
pause 5000
hi2cout [$c6], 0,(254,1,255)' clearing screen
main:
; read values from compass (address $02)
hi2cin [$02], $42,(heading_2degree, heading_adder)
heading = heading_2degree * 2 + heading_adder
bintoascii heading,b4,b5,b6,b7,b8'converting heading to ascii
; read values from IRSeeker (address $10)
hi2cin [$10], $49,(ac_direction, sensor1_ac, sensor2_ac, sensor3_ac, sensor4_ac, sensor5_ac)
bintoascii ac_direction,b16,b17,b18 'converting direction to ascii
hi2cout [$c6], 0,(254,128,"Compass ",b6,b7,b8,255) 'displaying heading (0-360)
pause 100
hi2cout [$c6], 0,(254,192,"Direction ",b18,255) 'displaying direction of ball (0-9)
; wait 1/10 second then loop
pause 100
goto main