PICAXE handling GPS for robot boat

MartinM57

Moderator
If I'm following this correctly (I really can't be bothered to read 10 words when 1 will do, and visit a handful of external links to try to understand what's going on) then you are using the i2c pins when you want to talk to the compass and then using some or all of the same pins to send servo pulses?
...in my book, and if it's true, that's just a plain bad design decision and you should keep them well separate.

Is your friendly other supplier doing this also, and does he think it's a good idea?
 

srnet

Senior Member
The issue of sharing I2C pins has been discussed a few times in the context of using the SPI (which uses two of the same pins) as well as I2C.

The consensus has been, that whilst it initially might appear to work, unless you can disable the I2C device, you cannot be sure what effect the alternative use of the I2C pins will have on devices so attached.
 

hippy

Technical Support
Staff member
Below are the programs that should work OK, with a fresh HMC6352:
No; both have I2C interactions which do not match what the datasheets say should be used. If either worked to any degree that would be more down to good fortune rather than by design. If neither worked then that would not be unexpected.

Determining what the code should be to perform the interaction, and why the code which would be expected to work does not, is a matter analysis and testing as previously described.

Providing a means to factory reset a HMC6352 from any unknown state is a separate issue and would require further investigation and testing.

What could screw up a HMC6352 is easier to define; anything which does not provide the required interaction with the HMC6352 and any adverse activity on the I2C bus. Keep clear of those and everything should continue to work as expected. If not that would need to be investigated further.

PICAXE commands which had unintended and unexpected side-effects on I2C operations would also need investigating though there is currently no evidence of any commands having either.

I suppose the bottom line, as I see it, is that there is no need to worry about how or why 'doing it wrong' does not work because it would not be expected to work. 'Doing it right' is all that matters; doing it wrong is anything which is not doing it right.

We are back to the top in determining what 'doing it right' actually is, and then providing a means of rescue, factory reset, should it have been done wrong.
 

Robin Lovelock

Senior Member
Thanks Hippy. I agree with you. May I arrange for an HMC6352 to be sent to you ? You may keep it, for an AXE024-HMC6352 Reference System, and I think my earlier posting provides all the detail you may use, if you choose to. It seems to me that the few minutes of you soldering it onto an AXE024 and testing it, will be far less - and more productive - than reading the postings on this thread. I will need your postal address, if you work from home, and not in the Rev'Ed' office from where we get the picaxe's. You may email me direct on robin@gpss.co.uk if you'd prefer not to make the address public.

The above would take a few days, but I can still do software tests here. I think I've already tried the code from Technical, that you think should be used, but if not (in my earlier postings) could you tell me the simple changes needed to the program below ?

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
 
Last edited:

hippy

Technical Support
Staff member
I don't really have much time at all but it may be possible for Rev-Ed to investigate to some extent and commit some company time to doing that. I will make a note of it and pass it on for consideration by management.

I am not sure there are any simple changes to any programs which are guaranteed to make things work. I would have expected the code in post #300 to work with a compass fresh from the factory.

An unused, factory fresh compass, is probably a pre-requisite to investigating the issues. I don't think there's anything to gain without that or in simply trying code variations without looking at the I2C bus activity with a logic analyser.
 

PADJ

Member
I think I've already tried the code from Technical, that you think should be used, but if not (in my earlier postings) could you tell me the simple changes needed to the program below ?
One more time.
Drop the location parameter.
Use hi2cout ("A") and hi2cin (b1, b0)
 

Robin Lovelock

Senior Member
Thanks Hippy. Yes, the HMC6352 would be "factory fresh" direct from Proto-pic. The argument for a simple investigation being made by Rev-Ed is to provide authorative information that the AXE024 will work with this device, and with what software code statements. We all realize that the only software information out there at present, is the result of a few enthusiasts, none of whom have used exactly the same hardware. The value of Proto-Pic looking into this, is not so much the I2C that is going on inside the PICAXE, but what is going on inside the HMC6352. i.e. how to reset a device, that has been "upset", back to "factory fresh" state.
 
Last edited:

Robin Lovelock

Senior Member
Thanks PADJ. Yes, I'd tried this before, but I just tried it yet again - with the same 6553 result.

Code:
'PADJ COMPASS.BAS test for HMC6352 Compass Module with PICAXE AXE024 Servo Controller
 HI2CSETUP I2CMASTER, $42, I2CSLOW, I2CBYTE
top:
 hi2cout ("A")
 PAUSE 10
 hi2cin (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
 

Armp

Senior Member
Just for kicks, and thanks to Hippy, try using
HI2CSETUP I2CMASTER, $42, 227, I2CBYTE
with no freq modifiers.
 

Robin Lovelock

Senior Member
Thanks Armp. Just tried it as below, with same 6553 result.
Code:
'Armp test for HMC6352 Compass Module with PICAXE AXE024 Servo Controller
 HI2CSETUP I2CMASTER, $42, 227, I2CBYTE
top:
 hi2cout ("A")
 PAUSE 10
 hi2cin (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
I'm guessing many of these software "variations" would work on a "factory fresh" HMC6352, rather than that I'm using here. I suspect the one I returned to Proto-pic for test, which worked for them, was in the same "upset" condition, but something used in their (Arduino) test rig, reset it. e.g. factory default settings. That's what I'm hoping to find out from them, or others - such as Spark-fun in USA, who make that board. As I understand it, they use the Honeywell chip (and reference the Honeywell data sheet, that reccomends 10k pull-up resistors) but their board may include the pull up resistors - protopic suggested I need not include them. I'm not, at present.

So we have two tasks outstanding:
a) confirm that the AXE024 can be used reliably with the Spark-fun HMC6352, and what the recommended software statements should be, probably similar to those above. This is best done by Rev-Ed, but they obviously need a factory fresh Spark-fun HMC6352. Off-forum communication makes me hopeful this might be done in due course. Rev-Ed are obviously in the unique position of knowing the internal I2C firmware within the picaxe chip, and so - if there are restrictions, such as timing delays needed - they will know best how to do it.
b) know how to reset the Spark-fun HMC6352 to it's "factory fresh" condition. It is thought that the factory defaults will be the same as those set by Honeywell, but of course, it is possible that they have been changed by Spark-fun, or their supplier who puts the chip onto that little board. If this "resetting" can be done from the picaxe, then it can enable experimenters to recover use of an "upset" chip. It can also be included in the setup process for programs that need to be particularly resilient. e.g. restart perfectly when solar based power supply is restored slowly, when the sun comes out.

I'm sorry that my pocket money does not extend to free-issuing HMC6352 and/or AXE024 to all of you out there, who may offer to look into these issues. Those of you who want to try "hands-on" will find it easy to order the Spark-fun direct if they are in the USA, or through Proto-pic if in the UK. The HMC6352-AXE024 does seem the neat solution to many applications that need a low power compass-operated servo. Maybe some of you will think of applications other than robot boats. e.g. my existing autopilot, without compass, has been briefly tested in the air, and could easily be tried on a land vehicle. But I'm only interested in sail-power on the water :) That earlier APSTEER.BAS program worked nicely, and the Picaxe and compass only consumed a total of 2mA. The servo took an average of 10mA, but for some applications, maybe that could be reduced further. e.g. switching the servo off. Much lower power means interesting possibilities, for things that require long periods of operation: like many months at sea :)

Robin
www.gpss.co.uk

p.s. for Srnet and now MartinM57 below. No Srnet - see code above. But that is a means of "upsetting" the HMC6352, before testing a full reset procedure. This has been said several times in earlier posts. I'm replying here, to avoid even more cluttering of this thread. Sorry if I've not explained it clearly enough to you in the past, but schematics, photos, etc are all there.
 
Last edited:

srnet

Senior Member
I may have missed the comment, so apologies if I did, are you actually trying to use the I2C pins for driving servos as well ?
 

MartinM57

Moderator
Who knows, srnet?

We tried to establish that in #321-323, and armp asked for a schematic in #293 but OP doesn't seem to want to tell us in really simple terms if the design intention is to run the the boat servos (how many?), and the compass, and possibly anything else, from the same 08M2 on a AXE024 servo controller board

I see statements from previous posts like:

- "My best guess is that I've overwritten the factory settings inside eprom of the HMC6352 as a side effect of using other things like SERVO or SEROUT, on pins that might be shared with the I2C system" and various others

- "I got out my soldering iron and connected two servo leads to the HMC6352 Compass Module, to plug into the LHS and Centre Servo positions on the AXE024 as seen from the top edge of the board. My test program is below, and avoids the complication of SERVO commands, etc - which could provoke restrictions and bugs in the picaxe firmware"

...which seem to suggest that there is an intention to (or an assumption that it is valid to) just use the 08M2 pins for whatever purposes the software wants at any particular point in time (or even at the same time).

There may be a cunning design that could achieve that, but I think it would be quite cunning, and I see no evidence of it....
 

PADJ

Member
We tried to establish that in #321-323, and armp asked for a schematic in #293 but OP doesn't seem to want to tell us in really simple terms if the design intention is to run the the boat servos (how many?), and the compass, and possibly anything else, from the same 08M2 on a AXE024 servo controller board
Many of the last 70+ posts and hundreds of lines from him would have been avoided if he'd given a clear statement of what he was trying to do, with a complete schematic, the code, and a clear photo of the setup.
 

Hemi345

Senior Member
Just a guess, a very wild guess:

:) joe
You're close, I think. Post #331 says he's NOT using pull up resistors because the Sparkfun board has 10K pullups already built in. If his connections look like his previous posted picture,

without the pullups, then I don't see why it won't work. But then that photo doesn't show whether he's now connecting servos to C.1 or C.2 either.

Why use the AXE024 for so many tasks? Wouldn't an AXE117 or AXE118 be a much better starting point?
 

JoeFromOzarks

Senior Member
You're close, I think. Post #331 says he's NOT using pull up resistors because the Sparkfun board has 10K pullups already built in.
You're correct, thank you!!! (I thought I read earlier that the 10K's had been removed and 4K7's installed.) I'll change the artwork in the previous post.

Thank you!!

:) joe
 

JoeFromOzarks

Senior Member
One more thing, quote from the datasheet:

APPLICATION NOTES
The HMC6352 Integrated Compass Sensor circuit is composed of two magneto-resistive (MR) sensors with orthogonal orientation for sensing the horizontal components of the earth’s magnetic field (0 to 630 milli-gauss), plus two amplifiers, a set/reset drive circuit, and a microprocessor (mP). Best accuracy is obtained in clean magnetic environments (free air) and held level, or perpendicular to the gravitational direction. At worst case, each degree of tilt from a level orientation could add two degrees of compass heading error. Magnetic errors can be introduced if operated near strong magnetic sources such as microphone or speaker magnets, transformers in test equipment, and CRT deflection yokes in video displays/monitors. These magnetic errors can typically be reduced or eliminated by performing the calibration routine.


How would one continuously compensate for "tilt from level" in a small boat in a big 'pond?'

:) joe
 

srnet

Senior Member
If this "resetting" can be done from the picaxe, then it can enable experimenters to recover use of an "upset" chip. It can also be included in the setup process for programs that need to be particularly resilient. e.g. restart perfectly when solar based power supply is restored slowly, when the sun comes out.
On that point in particular, if you have a project that needs to be 'particularly resilient' with less than perfect power supplies, its probably better dealt with in hardware.

You cannot predict what will happen to a PIC (or PICAXE) when the supply volts is slowly hovering around a critical point, the processor might run, but could easily crash and corrupt something.

To protect against this almost inevitable situation, there are power supply supervisor ICs in 3 pin SMT SOT or T092 packages that will hold a processor in reset until the the supply voltage reaches a set level.

These supervisor ICs cost around 30p each, so not really a major expense.........
 

Jeremy Harris

Senior Member
One more thing, quote from the datasheet:

APPLICATION NOTES
The HMC6352 Integrated Compass Sensor circuit is composed of two magneto-resistive (MR) sensors with orthogonal orientation for sensing the horizontal components of the earth’s magnetic field (0 to 630 milli-gauss), plus two amplifiers, a set/reset drive circuit, and a microprocessor (mP). Best accuracy is obtained in clean magnetic environments (free air) and held level, or perpendicular to the gravitational direction. At worst case, each degree of tilt from a level orientation could add two degrees of compass heading error. Magnetic errors can be introduced if operated near strong magnetic sources such as microphone or speaker magnets, transformers in test equipment, and CRT deflection yokes in video displays/monitors. These magnetic errors can typically be reduced or eliminated by performing the calibration routine.


How would one continuously compensate for "tilt from level" in a small boat in a big 'pond?'

:) joe
You can't. There will be large errors from both tilt and declination, making this type of compass of very limited use for navigation. I have a few two axis fluxgate compasses and they have to be gimballed just like a normal compass to give a half way decent heading. They also tend to suffer from errors caused by variation in declination so need recalibrating for heading if the location changes significantly in magnetic latitude.

You need a three axis flux gate/hall/magneto resistive sensor to compensate for tilt and declination and give a reasonably accurate heading indication over a wide range of magnetic latitudes.
 

PADJ

Member
On that point in particular, if you have a project that needs to be 'particularly resilient' with less than perfect power supplies, its probably better dealt with in hardware.

You cannot predict what will happen to a PIC (or PICAXE) when the supply volts is slowly hovering around a critical point, the processor might run, but could easily crash and corrupt something.
In fact the compass chip spec says "Solid and rapid power supply rise times are recommended, as some bench supplies may create soft starts that can cause internal processor clock delays and timing issues. A mechanical on/off switch between the supply and the circuits will cure these kinds of starting concerns."

There are so many things wrong with this 'design'.
 

JoeFromOzarks

Senior Member
In fact the compass chip spec says "Solid and rapid power supply rise times are recommended, as some bench supplies may create soft starts that can cause internal processor clock delays and timing issues. A mechanical on/off switch between the supply and the circuits will cure these kinds of starting concerns."
Microchip (among others) make a sweet little supervisory in T0-92: MCP100-315DI/TO $0.41USD.

There are so many things wrong with this 'design'.
+1 (But like any other train wreck, I cannot seem to turn away!) :)

:) joe

No offense intended!
 
Last edited:

Robin Lovelock

Senior Member
Thanks srnet, and Joe. I'd be interested in any simple hardware solution on power. e.g. to detect that power has dropped from nominal 5v to the level (in 3.5v ballpark) where it is then cut completely. This would avoid the risks, I'm glad you understand, of what happens inside the picaxe at these low voltages. Whenever I switch off, then back on, my autopilot, it always re-starts as it should. Under 24/7 test, it normally does this, when coming back slowly from a low voltage condition - but not always. Cost is not a major issue, especially when measured in a few tens of dollars/pounds, but time is. This includes the time to find the right product (you guys often help in this, as Jim did in finding the compass chip). But it also includes the time to adequately evaluate and test the product - to ensure the overall reliability is not decreased, rather than increased. Any links to actual product that can be purchased would be appreciated.
Robin
www.gpss.co.uk
 
Last edited:

srnet

Senior Member
There are plenty to choose from;

http://uk.farnell.com/supervisors-monitors

A 3 pin open drain device is easiest in this type of application, the open drain output holds the PICAXE reset pin down if the voltage falls below the supervisor threshold. This of course requires a PICAXE with an external reset pin, and since cost is not an issue, a 28X2 would be a good choice.

I may have missed the comment, so apologies if I did, are you actually trying to use the I2C pins for driving servos as well ?
?
 

Robin Lovelock

Senior Member
Hi Folks. Thanks to Hippy and those of you who have made useful suggestions, including code to try. This includes the guys who contact me direct, and have never posted on this forum. This thread has been linked from my pages for years, and includes valuable advice - particularly from Hippy - on things like hardware and software aspects of getting a GPS-picaxe autopilot to work - often overcoming restrictions in the picaxe system. e.g. use of the faster 8M2 chip, and faster clock rate.

Sorry if I've not managed to explain clearly enough to some of you the basics of where we are on this compass thing. The large number of enthusiastic comments obviously makes it more difficult for some to go back and find what was said before. I'll therefore repeat some of a recent posting, before giving you some later information, posted by me when talking about the many variations of a simple COMPASS.BAS test program possible ....


I'm guessing many of these software "variations" would work on a "factory fresh" HMC6352, rather than that I'm using here. I suspect the one I returned to Proto-pic for test, which worked for them, was in the same "upset" condition, but something used in their (Arduino) test rig, reset it. e.g. factory default settings. That's what I'm hoping to find out from them, or others - such as Spark-fun in USA, who make that board. As I understand it, they use the Honeywell chip (and reference the Honeywell data sheet, that reccomends 10k pull-up resistors) but their board may include the pull up resistors - protopic suggested I need not include them. I'm not, at present.

So we have two tasks outstanding:

a) confirm that the AXE024 can be used reliably with the Spark-fun HMC6352, and what the recommended software statements should be, probably similar to those below. This is best done by Rev-Ed, but they obviously need a factory fresh Spark-fun HMC6352. Off-forum communication makes me hopeful this might be done in due course. Rev-Ed are obviously in the unique position of knowing the internal I2C firmware within the picaxe chip, and so - if there are restrictions, such as timing delays needed - they will know best how to do it.

b) know how to reset the Spark-fun HMC6352 to it's "factory fresh" condition. It is thought that the factory defaults will be the same as those set by Honeywell, but of course, it is possible that they have been changed by Spark-fun, or their supplier who puts the chip onto that little board. If this "resetting" can be done from the picaxe, then it can enable experimenters to recover use of an "upset" chip. It can also be included in the setup process for programs that need to be particularly resilient. e.g. restart perfectly when solar based power supply is restored slowly, when the sun comes out.

I'm sorry that my pocket money does not extend to free-issuing HMC6352 and/or AXE024 to all of you out there, who may offer to look into these issues. Those of you who want to try "hands-on" will find it easy to order the Spark-fun direct if they are in the USA, or through Proto-pic if in the UK. The HMC6352-AXE024 does seem the neat solution to many applications that need a low power compass-operated servo. Maybe some of you will think of applications other than robot boats. e.g. my existing autopilot, without compass, has been briefly tested in the air, and could easily be tried on a land vehicle. But I'm only interested in sail-power on the water :) That earlier APSTEER.BAS program worked nicely, and the Picaxe and compass only consumed a total of 2mA. The servo took an average of 10mA, but for some applications, maybe that could be reduced further. e.g. switching the servo off. Much lower power means interesting possibilities, for things that require long periods of operation: like many months at sea :)

.... OK, back to the present again. I've just ordered yet another HMC6352, so I will have another "factory fresh" compass module here. I'm confident that it will work with many of the variations tried with an "upset" chip, included the simplest one, suggested by Hippy and at least one of you. Please remember that I did get the HMC6352-AXE024-Servo to work with APSTEER.BAS after a working simple COMPASS.BAS, but with code suggested by an enthusiast that Hippy thought should not work. The code that I will try with the "factory fresh" module is as follows:

Code:
'COMPASS.BAS test for HMC6352 Compass Module with PICAXE AXE024 Servo Controller
 HI2CSETUP I2CMASTER, $42, I2CSLOW, I2CBYTE
top:
 hi2cout ("A")
 PAUSE 10
 hi2cin (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
This will be without the extra 10k pull-up resistors. If it does NOT work, I will obviously try other variations, such as the one that worked before my module was "upset". If it does work, as I expect, then I will include similar code in a simpler APSTEER.BAS that should also work. Then it should not be difficult to find at least one spare input pin, to take serial data such as "Target 045 degrees" from the existing GPS Autopilot, used since early last year. Functional tests could then begin on Bray Lake, to analyse how well this solution worked, compared with one that only used the GPS. e.g. the GPS plots that you will see on my front page. This obviously includes testing of things like tilting of the boat.

This compass chip could also be a much better wind direction sensor, than that based on the Ametes chip. The Module could be put into the same enclosure as seen on www.gpss.co.uk/ametes.htm and will not suffer from the higher power consumption. i.e. only 1mA compared with 10mA. The data could probably easily be taken via the same I2C pins. Other articles describe using more than one HMC6352. I think the guy was measuring rotation between someone's head and shoulders :) The tacking logic could be put back in, within the "steering picaxe", so the 2KB memory limit would not be a squeeze either. This is just one new possibility that may open up, for next year's boat.

Note that in all of the above, we are talking about the comparatively simple process of using a "factory fresh" HMC6352. The other task is more difficult, since it relates to what is going on inside the HMC6352 rather than the picaxe. This is where useful advice is as likely to come from outside this forum, including from places such as Spark-fun or even Honeywell. However, so far, I've found mention of reset methods on other "enthusiast" forums, and there is no reason why myself, or anyone with an "upset" HMC6352 and AXE024 cannot try these reset methods.

I'll put the list of links below again. Sometimes it may be quicker to look on one of my pages, than hunt back through this thread. e.g. the latest photo of the AXE024-HMC6352 without the 10k pull up resistors. However, people are often directed back into this forum if they are seeking some of the nitty-gritty of picaxe stuff.

Thanks again to everyone.

Robin
www.gpss.co.uk
www.gpss.co.uk/autop.htm - Robot boat front page including overview, latest news, videos. e.g. GPS plots towards bottom of page.
www.gpss.co.uk/rbdesign.htm - "design" page, including talk about the Compass module with picture - way past the pussy cat :)
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 - later picture of AXE024-HMC6352 put up several days ago.

p.s. Thanks srnet. No, I'm not using the I2C pins for servo output. But it's a useful mechanism if someone wants to "upset" an HMC6352 before testing the full reset process, still unknown. I think my more detailed post above explains this. Thanks Jeremy (below) - ref tilt errors and testing on Bray Lake: see GPS Plots on first link above - done 18 months ago. Similar test with compass would be done.

p.p.s Friday: Proto-pic bits arrived and the "factory fresh" HMC6352 was soldered onto the AXE024. As expected, the code above worked perfectly. The earlier version with the preceding "0, " also worked - as expected. A lot more tests need to be done, including with APSTEER.BAS and I'll update this post if I have more news to report.... 2pm update: Good news is that the HMC6352 that Roy returned, also now works. Maybe his Aduino rig DID do something to it good ? Also, the AXE024 he returned, also worked. So now I have two good AXE024-HMC6352 systems, and one "upset" HMC6352.

3pm update: As expected, the servo control works :
Code:
'APSTEER1.BAS based on AUTOP2TTS.BAS simple auto pilot for robot boat
'v1a 9 August 2013 for testing with rudder servo and I2C Compass Module

 #picaxe 08M2  
 setfreq M16 'faster clock rate for better SERIN
 
 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
 
 'waggle rudder servo 4 (RHS position) on startup to show that working.
 SERVO 4,CENTRE 'start servo control process - middle
 PAUSE FOR1SEC ' 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
 

 HI2CSETUP I2CMASTER, $42, I2CSLOW_16, I2CBYTE
top:
 hi2cout ("A")
 PAUSE 10 
 hi2cin (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

 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
 
Last edited:

Jeremy Harris

Senior Member
Bear in mind the large tilt error from using a two axis compass and also the large (and variable) declination error. If you are relying on this for heading data then there will be very large (of the order of 2 deg per degree) pitch and roll induced errors and a variable declination heading error as the boat sails across the Atlantic and encounters fairly big changes in magnetic declination. The total heading error from using a fixed two axis sensor like this could be of the order of +/-20 to 30 deg or so over the range of magnetic declination changes and boat roll and pitch changes likely. Just changing tack, so the boat heel changes, will give a big apparent heading change on an East-West voyage.
 
Last edited:

hippy

Technical Support
Staff member
It will be interesting to see how errors affect things in real life. It may be that they average themselves over time, much like walking towards the sun won't have you travelling in the ideal straight line but you would generally be tacking towards the required destination.

Model it, and/or try it, is the only way we would probably find out.
 

Jeremy Harris

Senior Member
It will be interesting to see how errors affect things in real life. It may be that they average themselves over time, much like walking towards the sun won't have you travelling in the ideal straight line but you would generally be tacking towards the required destination.

Model it, and/or try it, is the only way we would probably find out.
My experience with using two axis flux gate compasses has been that the real world errors from tilt alone are fairly large. I have a selection of these sensors scrounged from surplus military kit, that come mounted to dangling ball joint type gimbals inside a silicone fluid filled housing. Because the housing was too tall for the application I had in mind (which was adding a dashboard mounted compass display to an old 4 x 4 I used to own) I removed the two axis flux gate coil unit and fitted it horizontally. This unit had a clocked serial data interface and would clock out 10 bits of heading data every time it received a data request pulse. I found that without the gimbal the thing was fairly unusable in a vehicle, as even the small tilt in a car was enough to make the heading change a fair bit. There's a stretch of old Roman road near me and, although it is dead straight, it goes up and down a lot. The apparent heading would change by several degrees at the top and bottom of every switchback in this road.

A small sailing boat probably has around +/- 20 or more degrees of heel, plus maybe +/- 10 degrees or so of wave-induced pitch. Even making a conservative error assumption of 1 deg heading change per deg pitch or roll change is going to mean heading errors (just from tilt alone) of around +/- 30 deg or so. Add in the variable magnetic declination error (which will produce variable pitch and roll errors dependent on magnetic heading and magnetic latitude) and I think the real world errors from a fixed two axis sensor in an application like this will be pretty large.

Still, it would be interesting to see what they are. Perhaps a bit of telemetry or data logging of compass heading when the boat sails around the course in Bray Lake using just it's existing GPS heading system might be a useful experiment. If nothing else it would give a good indication of the pitch and roll induced errors (although not the changing magnetic declination error) and so show how well suited to this task a simple compass may be.
 

Armp

Senior Member
You're correct, thank you!!! (I thought I read earlier that the 10K's had been removed and 4K7's installed.) I'll change the artwork in the previous post.

Thank you!!

:) joe
Looking at the schematic and the photo it looks like the Vcc for the compass and pullups comes from the servo connector - ie it doesn't go thru the diode but directly to the 4xAAs. Hope he hasn't used freshly charged cells.

Maybe its just the dodgy photo
 

Robin Lovelock

Senior Member
Please see my post #345 above. As expected, the code worked with a "factory fresh" HMC6352. See p.p.s at bottom. Thanks for postings above: see my p.s. Thanks srnet (post below) That's exactly the sort of thing I'm hoping we will uncover, then work-around, analogous to the SERIN/SERVO problems encountered a year or two back. Meanwhile, I've just updated my post #345 above - it seems Proto-pic's Aduino may have done the required reset, even if Roy did not think it did anything special.

Also, I've had a very useful conversation with Spark-fun, who manufacture the compass board in Colorado, USA. There obviously could be differences between the HMC6352, as it comes out of the Honeywell factory, such as the default eprom content. Note the differences already, such as the 10k pull-up resistors, already on the Spark-fun board. The good news is that the design was done within Spark-fun, but the bad news is that the engineer has since left. They are wisely sticking to the existing design, but detailed documentation might not be available.

Hippy: here is an interesting point noticed by Roy at Protopic, that I had missed: the AXE024 boards that I am using are labelled "v3", but I cannot see v3 documentation on the picaxe site. My links in post #345 now include both v1 and v2, and I hope - for my use - that they are all the same. I'm hoping that all the 8M2 chips are the same too.

p.s. I've updated post #345 above with the code that is now working for servo control. So we are back to where we were, but without the need for pull-up resistors, and with the simpler software lines suggested by Hippy. Now I can look for a spare pin, so I can complete this simple "steering subsystem". i.e. to use SERIN to read the "Target 45 degrees" from the existing Autopilot. We could then be close to testing on water. Before that, I will need to see if the compass needs calibration. Maybe I can use the input pin normally used for program load ? Maybe the output pin for SEROUT to my Text-To-Speech (TTS) module, so I can hear how accurate the compass heading is ?

p.p.s. code below works, using the TTS unit where the servo would go. So I can hear it speaking the bearing as I walk about outside. About to look into using this to calibrate the compass module.
Code:
'COMPASS2.BAS TTS test for HMC6352 Compass Module with PICAXE AXE024 Servo Controller
 #picaxe 08M2  
 setfreq M16
 symbol FOR4SEC = 16000 'pause value at 16MHz for 4 sec
 SEROUT 4, T9600_16, ( "N1",10,"V10",10,"W300", 10 ) 'N1=Deep Male, loud, fast
 PAUSE FOR4SEC  
 SEROUT 4, T9600_16, ( "S I am Snoopy.",10 ) 'test TTS output
 PAUSE FOR4SEC
 
 HI2CSETUP I2CMASTER, $42, I2CSLOW_16, I2CBYTE
top:
 hi2cout ("A") 'Ask for data
 PAUSE 10
 hi2cin (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 4, T9600_16, ( "S Heading ",#w0," degrees.",10 ) 'test TTS output
 PAUSE FOR4SEC
 goto top
 
Last edited:

srnet

Senior Member
Please see my post #345 above. As expected, the code worked with a "factory fresh" HMC6352. See p.p.s at bottom. Thanks for postings above: see my p.s.
Be aware that some devices may be using connected pins (such as I2C) to sense 'unusual' activity and trigger some factory or configuration mode.

Just two I came across recently when working on my long range lost model locator;

http://www.rcgroups.com/forums/showthread.php?t=1949624

1. The MTK3329 GPS, a common and very compact GPS, does not work properly if you connect a red LED to the 3D fix pin, you need to use a blue one. Use a red LED and the MTK3329 firmware detects it (no idea how) and assumes a different internal clock is in use. Result is a baud rate of 6060 baud and no connections to satellites.

2. The Openlog logger requires that the serial input pin is set high immediately after its power up, otherwise it goes into a factory reset mode. I was switching the power to the logger on off from a PICAXE circuit, so of course had the serial input pin low when first applying power, quite often this would cause the open logger to lock up.
 

John West

Senior Member
1. The MTK3329 GPS, a common and very compact GPS, does not work properly if you connect a red LED to the 3D fix pin, you need to use a blue one. Use a red LED and the MTK3329 firmware detects it (no idea how)
I suspect there is a different voltage dropped by red and blue LEDS. Red ones all seem to drop less voltage than other colors when driven by a fixed 20 mA.
 

Robin Lovelock

Senior Member
Hi Folks. Time for me to do other things tonight, but now the "work" is a bit more fun :)

Here is my new little, talking "compass calibration" program, COMPASSC.BAS:
Code:
'COMPASSC.BAS TTS test for HMC6352 Compass Module with PICAXE AXE024 Servo Controller
 #picaxe 08M2  
 setfreq M16
 
 symbol FOR1SEC = 4000 'pause value at 16MHz for 2 sec
 symbol FOR4SEC = 16000 'pause value at 16MHz for 4 sec

 SEROUT 4, T9600_16, ( "N1",10,"V10",10,"W300", 10 ) 'N1=Deep Male, loud, fast
 PAUSE FOR4SEC  
 SEROUT 4, T9600_16, ( "S We are about to enter compass calibration mode.",10 ) 'test TTS output
 PAUSE FOR4SEC
 SEROUT 4, T9600_16, ( "S When I say start, please rotate slowly, two revolutions in 20 seconds.",10 ) 'test TTS output
 PAUSE FOR4SEC
 SEROUT 4, T9600_16, ( "S Get ready !",10 ) 'test TTS output
 PAUSE FOR4SEC
 
 SEROUT 4, T9600_16, ( "S Go !",10 ) 'test TTS output
  
 HI2CSETUP I2CMASTER, $42, I2CSLOW_16, I2CBYTE
 hi2cout ("C")
 
 PAUSE FOR4SEC
 PAUSE FOR4SEC
 PAUSE FOR4SEC 
 PAUSE FOR4SEC
 PAUSE FOR4SEC 
  
 hi2cout ("E")
 PAUSE 40 'enough ?
 SEROUT 4, T9600_16, ( "S Thankyou. Calibration is finished. Now see how accurate I am !",10 ) 'test TTS output
 PAUSE FOR4SEC  
 
top:
 hi2cout ("A") 'Ask for data
 PAUSE 40 'was 10
 hi2cin (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 400 'was 100
 SEROUT 4, T9600_16, ( "S Heading ",#w0," degrees.",10 ) 'test TTS output
 PAUSE FOR4SEC
 goto top
and here is the latest talking COMPASS2.BAS which seems to work.
Code:
'COMPASS2.BAS TTS test for HMC6352 Compass Module with PICAXE AXE024 Servo Controller
 #picaxe 08M2  
 setfreq M16
 
 symbol FOR1SEC = 4000 'pause value at 16MHz for 2 sec
 symbol FOR4SEC = 16000 'pause value at 16MHz for 4 sec

 SEROUT 4, T9600_16, ( "N1",10,"V10",10,"W300", 10 ) 'N1=Deep Male, loud, fast
 PAUSE FOR1SEC
 SEROUT 4, T9600_16, ( "S See how accurate my compass is.",10 ) 'test TTS output
 PAUSE FOR4SEC 
 
 HI2CSETUP I2CMASTER, $42, I2CSLOW_16, I2CBYTE 
top:
 hi2cout ("A") 'Ask for data
 PAUSE 40 'was 10
 hi2cin (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 400 'was 100
 SEROUT 4, T9600_16, ( "S Heading ",#w0," degrees.",10 ) 'test TTS output
 PAUSE FOR4SEC
 goto top
Soon I'll be seeing how accurate this compass is, walking around my front drive - well away from those steel cars - and listening to what it speaks.

Earlier, it seemed to be a bit eratic - then I saw my battery had dropped to nearer 3.5v than < 5.2v. Maybe I'll invest in a resistor and zenar diode*, so I will not need to be so careful charging those cells :)

For what this is all about, please see my post #345 above, on http://www.picaxeforum.co.uk/showthread.php?18952-PICAXE-handling-GPS-for-robot-boat/page35

Robin
www.gpss.co.uk

p.s. *My three HMC6352 now have a simple series diode, to protect from over-charged 5v battery. e.g. 5.44v reduces to 4.86v.
 
Last edited:

Robin Lovelock

Senior Member
Jeremy "hit the nail on the head" when he warned that there would be large "tilt errors" in a boat that leans over. My conventional little boat will obviously be tilting over 45 degrees or more in typical conditions - even on Bray Lake, without the effect of large waves.

Late yesterday, now that I have my "speaking" HMC6352-AXE024-TTS test systems working, I was able to look at (listen to) the accuracy: probably good enough when the Compass module is horizontal, but those tilt errors are massive - in the same ballpark as the tilt angle. Tilt the Compass 45 degrees in one direction, and you might typically get an error of 20 or 30 degrees; tilt it the other way, and the error might be much larger: maybe nearer 90 degrees.

So this "tilt error" is a "show-stopper" for me - much more significant than my concerns such as achieving high reliability. Sadly, the tilt-compensated HMC6343 product from Spark-Fun is no longer available, possibly related to the engineer having left them. This product might have been compatible, and share the same benefits of low power drain - my reason for taking an interest in the compass. Putting the compass in a "gimbal" would probably be an even bigger mechanical and electrical challenge - imagine something that has to operate reliably for months at sea, and communicate those signals to other places, like the computer or rudder servo.

I'm glad I only started to look into this use of a compass at this late stage, after I had a working autopilot developed, based just on GPS-AXE024-rudder servo. It's amusing to read my words written on my oldest robot boat page, over five years ago, when I assumed we would need to use a flux gate compass. I'm glad my local friend John kept suggesting that I try just using the GPS heading :) It's a pity I just spent all those pennies on three HMC6352 - I could have spent it on another year of SPOT air time :) I guess these compass modules will be going into a plastic bag, with a paper note, to join more of my electronic junk - or maybe they will get tested in a toy of some kind.

Most of the other suggestions relate to "re-inventing" what should go on inside a tilt compensated compass. The main deterrent to me is the time it would take to develop such a solution, and there is always the question of what power it consumed. Maybe someone knows of a suitable alternative tilt compensated compass product, that only draws about 1mA from a 5v supply, and that can easily be interfaced to an AXE024 picaxe servo controller ?

This experience makes me ask myself, "what steering solution has been used in the French and Welsh boats that have made attempts on Microtransat already?". Or what solutions have progressed beyond early prototypes, to those that are being 24/7 tested for robustness at sea ? Some may have used that Spark-Fun HMC6343 product on https://www.sparkfun.com/products/8656 - what a pity it's no longer available.

Robin
www.gpss.co.uk

Bear in mind the large tilt error from using a two axis compass and also the large (and variable) declination error. If you are relying on this for heading data then there will be very large (of the order of 2 deg per degree) pitch and roll induced errors and a variable declination heading error as the boat sails across the Atlantic and encounters fairly big changes in magnetic declination. The total heading error from using a fixed two axis sensor like this could be of the order of +/-20 to 30 deg or so over the range of magnetic declination changes and boat roll and pitch changes likely. Just changing tack, so the boat heel changes, will give a big apparent heading change on an East-West voyage.
p.s. See Jeremy's #358 below : has got me thinking. Hope to add something soon, after some "DOing" rather than Thinking or Talking :)
 
Last edited:

Jeremy Harris

Senior Member
Sorry to hear that you've found this out too late to avoid buying these things. I've just dug around in my bits and pieces from old projects and found the gimballed flux gate I stripped apart to use as a car compass that I referred to earlier in this thread, plus the final version I used with the complete gimballed compass assembly. The blue pot contains a two axis flux gate compass mounted on a gimbal like the stripped one at the bottom. The pot is filled with silicone fluid to damp out the swing. Gimballing a two axis sensor like this allows it to read fairly accurately. IIRC, the accuracy specification on this unit was around +/- 1 deg, although it had a resolution of 10 bits, so around +/- 0.35 deg. As long as the tilt angle doesn't exceed the range of the gimbal it stays fairly accurate.

Sonobuoy compass.JPG
 
Top