Many Thanks flyingnunrt. I just tried your code, without then with the extra pause 10, and got the usual 255,255 response.
My guess is that most of these alternatives will work with a fresh HMC6352, if it has not been "upset" by, maybe, sending SERVO pulses to the I2C pins (even though all agree this seems unlikely). I'm hoping that Roy and/or Hippy will be able to repeat my tests above, and will find that my COMPASS.BAS program, and then APSTEER.BAS (they will need a servo for this) work as they did for me. Then running a modified APSTEER.BAS, doing SERVO/SERVOPOS to the "wrong servo" will "upset" the chip. Hopefully, this is reversible, such as re-writing factory defaults into the HMC6352 eprom. If Hippy is given a fresh HMC6352, I'm confident it will work first time. After it has been "upset", I'm sure he will get the same symptoms - of all alternative programs giving 255,255. If I am correct, all we then need to find out, is what extra setup calls to make at the start of the program, to put the HMC6352 into a "fresh" condition. Roy may have done this already, because his first good tests were with a non-picaxe platform (Arduino?) and this may have done the extra set ups. Lots of possible other explanations, including bugs/restrictions in the AXE024 I2C, but I'm sure Hippy will quickly find this out - if he has a HMC6352.
Below are the programs that should work OK, with a fresh HMC6352:
Code:
'COMPASS.BAS test for HMC6352 Compass Module with PICAXE AXE024 Servo Controller
HI2CSETUP I2CMASTER, $42, I2CSLOW, I2CBYTE
top:
hi2cout 0, ("A")
PAUSE 10
hi2cin 0, (b1, b0) 'w0 should now hold binary Heading 0-3590 tenths of degrees
w0 = w0 / 10 'degrees
SERTXD ( " H=",#w0 ) 'e.g. H=180 for south
PAUSE 100
goto top
The following needs a servo plugged into the RHS servo position.
Code:
'APSTEER.BAS based on AUTOP2TTS.BAS simple auto pilot for robot boat - with TTS
'v1a 1 August 2013 for testing with rudder servo and I2C Compass Module
'based on COMPASS.BAS test for HMC6352 Compass Module with PICAXE AXE024 Servo Controller
'
#picaxe 08M2
setfreq M16
symbol CENTRE = 150 'Servo middle position
symbol THROW = 50
symbol LEFT = CENTRE + THROW 'Servo left
symbol RIGHT = CENTRE - THROW 'Servo right
symbol FOR1SEC = 4000 'pause value at 16MHz for 1 sec
symbol FOR1P5SEC = 6000 'pause value at 16MHz for 1.5 sec
symbol FOR2SEC = 8000 'pause value at 16MHz for 2 sec
symbol FOR3SEC = 12000 'pause value at 16MHz for 3 sec
symbol FOR4SEC = 16000 'pause value at 16MHz for 4 sec
symbol FORP5SEC = 2000 'pause value at 16MHz for 0.5 sec
symbol FORP1SEC = 400 'pause value at 16MHz for 0.1 sec
symbol FORP2SEC = 800 'pause value at 16MHz for 0.2 sec
sertxd ( "APSTEER",10,13 ) 'test output back to PC at 19200
'waggle rudder servo 4 (RHS position) on startup to show that working.
SERVO 4,CENTRE 'start servo control process - middle
PAUSE FORP5SEC ' 0.5 sec
SERVOPOS 4,LEFT 'move servo to position 1
PAUSE FOR1SEC ' 1 sec
SERVOPOS 4,CENTRE 'move servo to middle position
PAUSE FOR1SEC
SERVOPOS 4,RIGHT 'move servo to position 2
PAUSE FOR1SEC
SERVOPOS 4,CENTRE 'move servo to middle position
PAUSE FOR1SEC
SEROUT 2, T9600_16, ( "N1",10,"V10",10,"W300", 10 ) 'N1=Deep Male, loud, fast
SEROUT 2, T9600_16, ( "S I am Snoopy's Steering Picaxe Computer.",10 ) 'test TTS output
PAUSE FOR4SEC
HI2CSETUP I2CMASTER, $42, I2CSLOW_16, I2CBYTE
top:
hi2cout 0, ("A")
PAUSE 10
hi2cin 0, (b1, b0) 'w0 should now hold binary Heading 0-3590 tenths of degrees
w0 = w0 / 10 'degrees
SERTXD ( " H=",#w0 ) 'e.g. H=180 for south
PAUSE 100
SEROUT 2, T9600_16, ( "S ",#w0," degrees.",10 ) 'test TTS output
if w0<175 then SERVOPOS 4,RIGHT endif
if w0>185 then SERVOPOS 4,LEFT endif
if w0>=175 and w0<=185 then SERVOPOS 4,CENTRE endif
goto top
The following may "screw up" the HMC6352, stopping the above two programs from working. i.e. they return 255,255. (SERVO to 1 instead of 4). For this test, the servo plugs into the centre position on the AXE024, instead of the RHS position.
Code:
'APSTEER.BAS based on AUTOP2TTS.BAS simple auto pilot for robot boat - with TTS
'The following may "screw up" the HMC6352, stopping the above two programs from working. i.e. they return 255,255. (SERVO to 1 instead of 4)
'based on COMPASS.BAS test for HMC6352 Compass Module with PICAXE AXE024 Servo Controller
'
#picaxe 08M2
setfreq M16
symbol CENTRE = 150 'Servo middle position
symbol THROW = 50
symbol LEFT = CENTRE + THROW 'Servo left
symbol RIGHT = CENTRE - THROW 'Servo right
symbol FOR1SEC = 4000 'pause value at 16MHz for 1 sec
symbol FOR1P5SEC = 6000 'pause value at 16MHz for 1.5 sec
symbol FOR2SEC = 8000 'pause value at 16MHz for 2 sec
symbol FOR3SEC = 12000 'pause value at 16MHz for 3 sec
symbol FOR4SEC = 16000 'pause value at 16MHz for 4 sec
symbol FORP5SEC = 2000 'pause value at 16MHz for 0.5 sec
symbol FORP1SEC = 400 'pause value at 16MHz for 0.1 sec
symbol FORP2SEC = 800 'pause value at 16MHz for 0.2 sec
sertxd ( "APSTEER",10,13 ) 'test output back to PC at 19200
'waggle rudder servo 4 (RHS position) on startup to show that working.
SERVO 1,CENTRE 'start servo control process - middle
PAUSE FORP5SEC ' 0.5 sec
SERVOPOS 1,LEFT 'move servo to position 1
PAUSE FOR1SEC ' 1 sec
SERVOPOS 1,CENTRE 'move servo to middle position
PAUSE FOR1SEC
SERVOPOS 1,RIGHT 'move servo to position 2
PAUSE FOR1SEC
SERVOPOS 1,CENTRE 'move servo to middle position
PAUSE FOR1SEC
SEROUT 2, T9600_16, ( "N1",10,"V10",10,"W300", 10 ) 'N1=Deep Male, loud, fast
SEROUT 2, T9600_16, ( "S I am Snoopy's Steering Picaxe Computer.",10 ) 'test TTS output
PAUSE FOR4SEC
HI2CSETUP I2CMASTER, $42, I2CSLOW_16, I2CBYTE
top:
hi2cout 0, ("A")
PAUSE 10
hi2cin 0, (b1, b0) 'w0 should now hold binary Heading 0-3590 tenths of degrees
w0 = w0 / 10 'degrees
SERTXD ( " H=",#w0 ) 'e.g. H=180 for south
PAUSE 100
SEROUT 2, T9600_16, ( "S ",#w0," degrees.",10 ) 'test TTS output
if w0<175 then SERVOPOS 1,RIGHT endif
if w0>185 then SERVOPOS 1,LEFT endif
if w0>=175 and w0<=185 then SERVOPOS 1,CENTRE endif
goto top
Robin
www.gpss.co.uk
www.gpss.co.uk/autop.htm - robot boat "front page" with latest news, etc. Amusing videos
www.gpss.co.uk/rbdesign.htm - what serves as a "design" page, including the picaxe based autopilot
www.sparkfun.com/datasheets/C...ts/HMC6352.pdf - data sheet for HMC6352 Compass Module
www.picaxe.com/docs/axe024.pdf - PICAXE AXE024 Servo Controller kit (v1)
www.picaxe.com/docs/axe024v2.pdf - PICAXE AXE024 Servo Controller kit (v2) - as used in tests above.
www.gpss.co.uk/phmc6352.gif - link to picture showing wiring of HMC6352 to AXE024 v2 (or v1).
p.s. for those that have difficulty understanding what the purpose of this work is:
a) to confirm that a PICAXE AXE024 can be used with a HMC6352 Compass (and how?). Probably yes (COMPASS.BAS)
b) to identify complete setup process needed for HMC6352. e.g. restoration of HMC6352 factory defaults if needed. ???
c) to determine what pins can be used for things like Rudder Servo (Prob. yes), serial I/O, analogue input.
d) to identify design limitations and side-effects (analogous to those existing with SERIN and SERVO solutions)
- to help identify design options for including compass in Autopilot. e.g. one AXE024 or more.
APSTEER.BAS indicates AXE024 can reliably combine compass reading and rudder servo output.
It seems that SERVO or SEROUT to the I2C pins can upset the HMC6352. More information needed.
Sorry that I will not respond to all postings in this thread, but anyone is welcome to contact me directly via my
robin@gpss.co.uk or contact page
www.gpss.co.uk/contact.htm