PICAXE handling GPS for robot boat

Armp

Senior Member
Accuracy: better than 5 degrees; target accuracy 1 degree.
From the GY-26 Manual:
When using the module, please keep it level so that it can get the accurate results.
I think you'll going to need an accelerometer chip and some pretty complex math to compensate for the 'tilt' of the sensor.

We never quite got there in a previous automotive non-picaxe application.
 

ThierryP

New Member
Robin

I don't think GY-26 is tilt compensated.
As stated in post #196 of this thread, the following unit CMPS10 would fit the bill except for power consumption (25mA @ 5V), so you would have to power this unit down 90% of the time, eg by a MOSFET.

Thierry
 

Jeremy Harris

Senior Member

Robin Lovelock

Senior Member
Thanks Hippy and Jim. Either or both of you MAY have come up trumps, but I don't like the look of the words at the very end of Hippy's spec - looks suspiciously like this is another I2C device. I very much like the price of Jim's but I see no spec saying whether I2C or rs232 - I suspect I2C. I seem to remember this thread having details of my being too quick to buy a chip that looked like rs232 but was I2C. Luckily the UK supplier was kind to me and gave me a full refund, canceling the order. I'm really pleased that Jim ordered one - he will soon know if he can get it working, and how. Good Luck Jim ! :)

p.s. I've added a new "windmill" page and video on www.gpss.co.uk/rbwmill.htm - mostly for fun, but it's good to see the same autopilot, without changes, worked first time in this little 1 foot long motor boat. A good way of testing your autopilots on a small lake ? Meanwhile, we must only be a week or two away from Snoopy's attempt on the Atlantic - we are waiting for the weather. Details on www.gpss.co.uk/autop.htm
 
Last edited:

jaybeetoo

New Member
Robin

Looking at the devices that Proto-Pic is selling, there seems 1 unit that could do what you require even without an extra Picaxe device, because it also provides Tilt compensated Heading as serial data output or as I2C interface, ie. CMPS10 . Example application with Picaxe here.
Main downside seems the 25mA current it draws, but perhaps it can be put to sleep most of the time? Can't find that in the specs, but you can always have the 'master'-Picaxe completely switch the Power of this module on/off through a transistor.

Alternatively the LSM303 provides all the ingredients (3D magnetometer plus 3D accelerometer, I2C interface, <1mA), but this will need some interfacing MCU like a Picaxe plus some advanced trigonometry maths to convert these 6 dimensions into a tilt compensated heading over a serial interface, see also here. Seems mote fun than a CMPS10, but I'm not sure if this math fits the KISS bill.

Thierry
Or this version http://www.hobbytronics.co.uk/lsm303dlh-tilt-compass.

"The magnetometer and accelerometer can be individually turned on and off to save power, and a special sleep-to-wakeup function allows the accelerometer to sleep until an inertial interrupt is triggered. ...

The carrier board includes two voltage regulators that provide the 1.8 V and 3 V required by the LSM303 sensor, which allows sensor to be powered from a single 2.6 &#8211; 5.5 V supply. The regulator outputs are available on the 1V8 and 3V pins and can supply almost 150 mA and 300 mA, respectively, to external devices. The breakout board also includes a circuit that shifts the I²C clock and data lines to the same logic voltage level as the supplied VIN, making it simple to interface the board with 3.3 V or 5 V systems, ...."

As you say it would probably need something like a uM-FPU V2 or V3 (which can interface with the GPS as well).
 
Last edited:

Robin Lovelock

Senior Member
Thaanks Folks. I think Jim ordered stuff like this, and - if he gets something working - he may post onto this thread. Don't forget that the only reason
to use the compass, is so less power can be drawn. Also that it could not be switched off if that prevents the typical 7 or 8 seconds around the control loop for the rudder. Details aare on the design page www.gpss.co.uk/rbdesign.htm - but first see www.gpss.co.uk/autop.htm for the latest news - we are close to making a third attempt this year with the same design, that needs all those solar panels and a 4 ft boat. I'm fully occupied on getting Snoopy ready for yet another attempt, but I have an important job in the queue: setting up a Globalsat BR355 GPS into power saving mode: if that works, there is no need to change the software, that has now been frozen for months.
Enjoy the pictures and video of last Saturday's attempt ! :)
Robin
www.gpss.co.uk/autop.htm
 

jaybeetoo

New Member
Robin

I've been trying to work out how you can navigate with just a GPS in a boat which relies only on wind. If Snoopy is in a tidal stream (such as around Portland Bill) which is taking Snoopy backwards faster than the wind is taking 'her' forwards, the GPS will be showing Snoopy heading approximately 180 degrees in the opposite direction to where she is actually pointing. The servo will keep trying to turn Snoopy around to point the 'wrong' way. Without knowing in which direction the boat is heading (using a gyro or a compass) I can't think of how you can detect if this situation is happening.

Good luck with the next attempt!

Jeremy
 

JimPerry

Senior Member
Thaanks Folks. I think Jim ordered stuff like this, and - if he gets something working - he may post onto this thread.
I have a couple of different boards which I will be testing over the next few weeks - also have a mechanical and electronic compass to check calibration with! :rolleyes:
 

Robin Lovelock

Senior Member
I can understand your problem Jeremy, and I too was worried that the autopilot might be "confused" by the tide. If you start with www.gpss.co.uk/autop.htm you can go from there to an earlier copy of that page (i.e. for 2012) and there you will find my worries - dispelled after that November launch. Despite ending up on the Needles, the first two hours were an arrow straight course, despite a tide of 1.8 knots trying to push the boat to the west. His movement to the east was due to "human intervention" :) The design of the autopilot, including the software, that runs on the picaxe, is on the linked page www.gpss.co.uk/rbdesign.htm You will read that "confused by the tide" would result in the boat drifting with the tide, due to it applying so much rudder to counteract it, that it ends up going in circles, and hence drifts with the tide. But, despite my worries, that did not happen. Oh yes, not all the evidence on who snatched Snoopy is public - but there is enough there to give a clue :)

p.s. see "launch before Christmas to attempt the Atlantic crossing from UK to USA ? ... " on www.gpss.co.uk/rb11to12.htm
 
Last edited:

Robin Lovelock

Senior Member
I have a couple of different boards which I will be testing over the next few weeks - also have a mechanical and electronic compass to check calibration with! :rolleyes:
Crikey! It's a while since I visited this thread. My reason is that I've just ordered another three PICAXE servo controller kits, to make up another spare SPOT tracker, for "boat 10" (for launch in 2014???). Boat 9 is still ready for another attempt this year. For latest news, see www.gpss.co.uk/autop.htm

Stopped laughing yet ? :) Reason for this post is to contact Jim again - any progress on that compass ? When I ordered the picaxe kits, bundled in with the faster 08M2 chip, I just saw that it supports the I2C protocol - so - if power consumption is not a problem - the compass might be easy to interface from a software point of view.

Robin
www.gpss.co.uk
 

JimPerry

Senior Member
Yes I've got them - and will be doing work soon - with a break in and house sale I've been a bit preoccupied :(
 

Robin Lovelock

Senior Member
Sounds Good Jim. Sorry to hear about your other "diversions". I wonder if one of your chips is the Proto-pic HMC6352 at £24 ?
I found nice words from me on Page 20 of this thread, when I cancelled an order - they were very nice about it.
I googled and found their page http://proto-pic.co.uk/compass-module-hmc6352/ - looks great: 2.7v - 5.2v and only 1mA.
Maybe the I2C is not a problem now, on my 08M2 based based Picaxe AXE024 servo controller. Maybe has not been a problem for the past year :)
 

Robin Lovelock

Senior Member
I've just ordered two of those Proto-Pic compass modules, and hope to start trying one out in a few days, on a PICAXE servo controller with Servo, to see if I can get a low power "steering subsystem" working. No harm in starting to work on whatever goes into the next boat after that waiting here to launch :) www.gpss.co.uk/autop.htm
 

erco

Senior Member
Robin: What an amazing long-term project. It's amazing to see your efforts and enthusiasm over so many years. Hoping your weather window comes soon, followed by an amazing trans-Atlantic journey. My brother has a sailboat in Oriental, NC. Whenever your bot makes it that far, I'm sure he'd love to plot an intercept course and escort Snoopy into the colonies. :)

erco
 

g6ejd

Senior Member
I've just ordered two of those Proto-Pic compass modules, and hope to start trying one out in a few days, on a PICAXE servo controller with Servo, to see if I can get a low power "steering subsystem" working. No harm in starting to work on whatever goes into the next boat after that waiting here to launch :) www.gpss.co.uk/autop.htm
Quite easy to do, but will require some floating point maths to extract the X, Y and Z parameters.
 

Robin Lovelock

Senior Member
Hi Folks. First I'll paste some relevant links in below, such as the datasheet for the HMC6352 Compass Module.
I'm hoping some of you, maybe even Hippy, will save me some time getting this Compass working with my Autopilot.
Two compass chips arrived this morning - one to test and a spare, in case I blow it up !

I'll start with a few words to put this into context: this thread started just over two years ago, when I started the process
of moving from a Pocket PC autopilot, to one based on a single PICAXE. I had been using PICAXE as servo controllers,
long before, and had - with help from Hippy and others - solved problems like reading the GPS serial data.
This was a great success, and we were soon into tests on water. This simple GPS-Picaxe-rudder servo
has been thoroughly tested, including months of 24/7 tests, and GPS simulation across the Atlantic.
If you read my "front page" below you can amuse yourself with the details.
The "design" page goes into more detail on how it was put together. See bottom of page for mention of the compass.

Now, while waiting for a suitable launch window, I'm working on what might find it's way into a future design,
such as that used in next year's boat. If the work goes well, it may be tested on the water within days or weeks,
and - after the required few months of water tests, including 24/7 tests - it may get adopted for the next boat.

Possible benefits of using the compass, instead - or in addition to - GPS based heading, are potential reduced power consumption
and not being "confused by the tide" - although our November launch indicates this is not a problem.
There may be other spin-offs for 24/7 testing, like the boat steering in much lower wind speeds.
If the wind drops to 1 or 2 mph, the boat drifts into the bank, due to GPS based heading being too inaccurate.
This costs me petrol, going over to Bray Lake next morning, to push it out again :)

I'll be starting simply, with a the compass chip, PICAXE servo controller, and a servo.
If I'm lucky, it may be possible (if we have enough pins?) to interface the compass into the existing PICAXE Autopilot.
If not, we might split the system into the "GPS Navigation PICAXE" and the "Steering PICAXE".
So "how many pins" and "which pins to use" could be important decisions when I start.

I do hope G6ejd is very wrong above. Take a look at the datasheet for the Compass chip below. I intend to use this in the simple mode of outputing (maybe at 2 Hz) compass heading - not that X,Y,Z option. Also, if I'm lucky, I'm hoping to set this startup mode into the EPROM, which means I will only need one pin on the picaxe. Before you rush to talk about "tilt compensation" - I expect to test this as quickly as possible in realistic water conditions, with the boat leaning over and bobbing about.

I'll obviously be starting "on the table", with the compass connected to the PICAXE, but should then quickly progress to "walking around outside the house" between two waypoint, checking that the servo is moved correctly. Soon after that, it will be tested on Bray Lake, doing the "Bray Lake Test".

But lots of things may jump out to bite me before then :)

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/Components/HMC6352.pdf - data sheet for HMC6352 Compass Module
http://www.picaxe.com/docs/axe024.pdf - PICAXE AXE024 Servo Controller kit
 

Robin Lovelock

Senior Member
Hi Folks. Looks like I need help sooner than expected - where to find SCL pin for I2C on the AXE024 ? :)

I nearly got the HMC6352 a few months ago, but then saw it was I2C - not simple "RS232" serial (supported by SERIN/SEROUT)
Then, more recently, I saw that the faster chip in my AXE024 Servo Controller kit DID support I2c. (e.g. READI2C)

I've added some info on my "design" page above, on existing uses of pins, for things like GPS input, servo output, etc.
It seems I might start by adding one or two male servo leads onto the Compass Module to take it's 4 wires
(Power +5v and 0v, and SDA (data) and SCL (clock) to the right place on the PICAXE board.
BUT Where ? Particularly for the SCL pin ?

Before someone says "use a different PICAXE kit" I'd like to have it confirmed it is not possible with the AXE024 Servo Controller.
But I'm hoping it is.

Robin
www.gpss.co.uk
 

Robin Lovelock

Senior Member
Many Thanks Jim. I've printed out your JPG and can see that it says the PICAXE-08M chip has:
Pin 5 as C.2 (In/Out/ADC/Touch/pwm/tune/SRQ/hi2c sda) and
Pin 6 as C.1 (In/Out/ADC/Touch/hserin/SRI/hi2c scl) - so let me see where these go on the AXE024 board ....
... looks, by tracing 0v, as if your picture is as seen looking at the top of the chip - in which case ...
Pin 5 i2c SDA connects to ... nothing on the board - so I could put a wire onto it there.
Pin 6 i2c SCL connects to ... also nothing on the board it seems.
i.e. on the AXE024 Servo Controller, these two pins are not used.
It looks as if I might be able to risk careful soldering of the Compass Module onto a PICAXE.
If so, I can first see if it upsets normal operation. e.g. Program loading and AutoPilot use.
Do you agree ? Where did you find the diagram ?
Robin
www.gpss.co.uk
 

Robin Lovelock

Senior Member
Thanks Hippy. Good to hear from you again. I printed your picky and see I'm getting closer ...

I had missed those two 330 ohm Resistors, connecting pins 5 and 6 through to those two servo positions.
As it happens the picture seems to be for four servos, but I used a meter to trace, and on my AXE024
I can see that pin 5 (SDA) goes via 330 to the 1st (LHS from edge of board)
and pin 6 (SCL) goes via 330 to the 2nd (middle) servo position.

So, now we get into the questions of what hardware/software restrictions I need to impose on myself.
Seems to me that I cannot use these first two servo positions for other things, such as driving the rudder servo
- BUT, maybe I could write a "steering program" to handle the I2C, and drive the servo, using that 3rd (RHS) position ?

It looks as if I will have to forget adding the I2C compass module to a PICAXE autopilot, because of hardware pin use.
BUT, if I can handle the rudder servo, the compass module via I2C, and some other serial interface, maybe it can be done.
i.e. the existing PICAXE Autopilot would pass serial data to a separate PICAXE "Steering computer".

The existing PICAXE Autopilot practically has what is needed already: it outputs text, including target heading,
on a spare pin, for optional connection to a text to speech module. e.g. "45 degrees" (if target is North East)
A simple change can be made to simplify the SERIN reading the data. e.g. "Target 45 degrees".
So the Steering Computer might do a simple Serin looking for the number after "Target ".

So big question now is can we handle the serial input from the Navigation PICAXE (e.g. "Target 45 degrees")
the I2C reading of compass boat heading, and control the rudder servo ?

If this is possible, from a hardware and software point of view, I could give it a try.
e.g. see if there are any software restrictions/interference effects between compass I2C and Servo control.

Of course, it may mean we could not easily put a wind direction sensor back on, but we should not need to.

I only got my AXE024 servo controller kits recently - strange about the "three to four" servo positions ???

But no probs. Looking forward to hearing more.
Robin
www.gpss.co.uk
 

Armp

Senior Member
IMO, as a small boat sailor, a compass is of little value.
Your Autopilot needs to know where you want to go, and the course you're actually sailing and make the appropriate steering correction. A GPS unit does give you this information, but a compass only tells you where the boat is pointing. If sailing with light north winds for example you could be pointing north but sailing south....:eek:

If your GPS does not indicate heading at low speed it's a simple job to take positional data over a period of time and do the calculation yourself.
 

premelec

Senior Member
Hi Robin - great to see your project still going forward or sideways or at least in the right direction - eventually - have you taken continental drift into account :) - Best of luck with it all!
 

Robin Lovelock

Senior Member
Have not risked getting a soldering iron out yet - can wait to hear feedback about above.
e.g. maybe could go through those 330 ohm resistors, rather than direct onto the chip ?

Thought I'd start putting a test program together, to at least see if it syntax checks. seems to.
Sorry about quite a few lines that may not be needed, not deleted from the much bigger Auto Pilot program.

But it shows you what the first test might be.

Robin
www.gpss.co.uk/autop.htm

p.s. Thanks Armp - but I guess you haven't read any of my pages ? e.g. the GPS autopilot I've been using ?

Here's that first beginings of a test program....

Code:
'APSTEER.BAS based on AUTOP2TTS.BAS simple auto pilot for robot boat - with TTS
'v1a 30 July 2013 for testing with rudder servo and I2C Compass Module
' 
 #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 servo 1 on startup to show that working - will control rudder
 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
 


top: 
 sertxd ( "Output I2C then read two bytes",10,13 ) 

 writei2c 0, ("A")
 readi2c 0, (b1,b2)
 w3 = b1 * 256 + b2 'w3 now holds binary direction 0-359

 SERVOPOS 1,LEFT 'move servo to position 1
 PAUSE FOR2SEC ' 1 sec


 SERVOPOS 1,RIGHT  'move servo to position 2
 PAUSE FOR2SEC
 goto top
 

Robin Lovelock

Senior Member
Yup I've read them, what did I miss?
Maybe you missed the "design" page on www.gpss.co.uk/rbdesign.htm ? I don't want to go "off topic" here, but after a few years of mucking about with prototypes, we seem to have a practicable autopilot, based on just GPS, PICAXE computer, and rudder servo. We did have a wind direction sensor and tacking logic, and could always put that back in - if the power and memory consumption justified it. This possible addition of a compass is to see if we get some benefits worth having. e.g. switching off the GPS for a proportion of the time, and steering based on a much lower power consumption compass (1mA vs 30mA+). There may be other benefits, mentioned on that "design" page. You are welcome to contact me directly on robin@gpss.co.uk if you wish, and we can go into more detail. If so, it would be helpful to know a little about you, such as age and engineering background. We can then speak "at the right level". You will find more than enough about me on my www.gpss.co.uk/history.htm - maybe too much :)
 
Last edited:

Robin Lovelock

Senior Member
Hi Folks. Quite a few outstanding hardware questions above, but 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. In doing this, I consulted those documents below, and googled around picaxe pages, but there are plenty of questions remaining on what those parameters should be. This is the simplest version of the program, after removing delays that seemed to have no effect. The good news is that the READI2C command DOES seem to read something - but always the same value :-(
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/Components/HMC6352.pdf - data sheet for HMC6352 Compass Module
http://www.picaxe.com/docs/axe024.pdf - PICAXE AXE024 Servo Controller kit

Code:
'COMPASS.BAS test for HMC6352 Compass Module with PICAXE AXE024 Servo Controller
 #PICAXE 08M2  
 SETFREQ M16
 
 HI2CSETUP I2CMASTER,$43,I2CSLOW_16,0
 
top:
 w0=123 'to confirm w0 is changed by READI2C 
 READI2C (b1,b0) 'w0 should now hold binary Heading 0-3590 tenths of degrees
 SERTXD ( "  H=",#w0," b1=",#b1," b0=",#b0,10,13 ) 'e.g. H=17407 b1=77 b0=255
 goto top
 
'above gives H=17407 b1=77 b0=255 regardless of orientation, etc
 
Last edited:

hippy

Technical Support
Staff member
My test program is below, and avoids the complication of SERVO commands, etc
Make it even simpler. Remove the SETFREQ and any frequency modifiers. The HI2CSETUP should probably be -

HI2CSETUP I2CMASTER, $42, I2CSLOW, I2CBYTE

When reading the data do you not have to specify where you are reading from ? I'm afraid I don't have time to consult the datasheet at present.
 

Robin Lovelock

Senior Member
Thanks Hippy. I've tried lots of variations, and the simplest one is below. All give that same value of 17407. I looked at the HMC6352 data sheet, and added the recommended 10k pull-up resistors on SDA and SCL lines.: no change. I'm still going through the 330Rs to the chip. I saw the data sheet speaks of Hex $42 for write and $43 for read. Variations of both tried. If while running I unplug the SDA lead, I still get 17407. If I unplug SCL, I get 65535 (255,255). I must admit, it does look like I'm reading from the wrong place, but those documents are not that clear.
Robin

Code:
'COMPASS.BAS test for HMC6352 Compass Module with PICAXE AXE024 Servo Controller

 HI2CSETUP I2CMASTER, $42, I2CSLOW, I2CBYTE 
 
top:
 w0=123 'to confirm w0 is changed by READI2C 
 READI2C $43, (b1,b0) 'w0 should now hold binary Heading 0-3590 tenths of degrees
 SERTXD ( "  H=",#w0 ) 'e.g. H=17407 (b1=67 b0=255)
 goto top
 
'above gives H=17407 regardless of orientation, 10k pull-up resistors, etc
 

hippy

Technical Support
Staff member
17407 is $43FF (hex), and the $43 is the chip device address with the read bit set. That is usually symptomatic of the I2C not being correctly wired or some other I2C bus issue.

The forum and Google seems to have a few code examples of using an HMC6352 with a PICAXE.
 

Robin Lovelock

Senior Member
Thanks Hippy. I think I've tried all the variations based on googling. Sounds like hardware related. I've contacted supplier, to see if they have a lead.
 

Armp

Senior Member
The manual seems quite clear - by default the part comes up in Standby Mode, I believe you need to configure it before reading data.

Also check the timings. "A" Command takes 6mS.(Table 3)
 
Last edited:

Robin Lovelock

Senior Member
Thanks Armp, but I think I've already tried that, with one of my many variations, based on examples I found. Below is the latest version, which I just ran again, and got the same result. When you say "configure", is that something different from H12CSETUP ? Any changes you can suggest in the example below ?
Robin
Code:
'COMPASS.BAS test for HMC6352 Compass Module with PICAXE AXE024 Servo Controller
 HI2CSETUP I2CMASTER, $42, I2CSLOW, I2CBYTE  
top:
 w0=123 'to confirm w0 is changed by READI2C 
 WRITEI2C ("A")
 PAUSE 10
 READI2C (b1,b0) 'w0 should now hold binary Heading 0-3590 tenths of degrees
 SERTXD ( "  H=",#w0 ) 'e.g. H=17407 (b1=67 b0=255)
 PAUSE 100
 goto top 
'above gives H=17407 regardless of orientation, 10k pull-up resistors, etc
 

MartinM57

Moderator

hippy

Technical Support
Staff member
If you're using hardware i2c, i.e. the hi2c commands, don't you have to use hi2cout/hi2cin rather than writei2c/readi2c?
The two actually compile to the same code, but if using HI2CSETUP it would be recommended to the use HI2CIN and HI2COUT for consistency.

The only thing in common about these, is that they are all slightly different to your code and between themselves :)...
The two projects appears to have code working so one of those is what I would start with. The davidjbarnes appears to use the same code as geekshed for compass reading, and could be what the geekshed project copied from reading the project description -

hi2csetup i2cmaster, $43, i2cslow, i2cbyte
hi2cout 0, ($41 ,"A")
hi2cin 0, (b1, b0)

The code by Technical in the first link matches the code I would have expected to use from reading the datasheet ( and matches example code for other micros ) but the above code differs to that and I wouldn't have expected it to work!

It is hard to say what is going on or why the linked project code works. It really needs someone with experience of I2C, compass hardware and a logic analyser to figure that out.
 

Robin Lovelock

Senior Member
Thanks Martin and Hippy. I've just tried both, with same result of that H=17407 (b1=67 b0=255).
First I just changed my example above to use HI2COUT and HI2CIN - but not all the combinations of parameters possible.
I then tried that below, with no change in result.

Code:
'COMPASS.BAS test for HMC6352 Compass Module with PICAXE AXE024 Servo Controller
 hi2csetup i2cmaster, $43, i2cslow, i2cbyte 
top:
 w0=123 'to confirm w0 is changed by READI2C 
 hi2cout 0, ($41 ,"A")
 PAUSE 10
 hi2cin 0, (b1, b0) 'w0 should now hold binary Heading 0-3590 tenths of degrees
 SERTXD ( "  H=",#w0 ) 'e.g. H=17407 (b1=67 b0=255)
 PAUSE 100
 goto top 
'above gives H=17407 regardless of orientation, 10k pull-up resistors, etc
 

hippy

Technical Support
Staff member
Thanks Martin and Hippy. I've just tried both, with same result of that H=17407 (b1=67 b0=255).
Unfortunately, without compass hardware and having a working example for the 08M2, it is difficult to give any definitive answers.

You can try accessing an I2C EEPROM to confirm the I2C bus interface is correct, you could try the compass on a 20X2 or 28X1 to see if you can replicate the success of the linked projects with those. Perhaps someone with compass hardware and an 08M2 can check they get the same results as you do.

Have you shorted across the series 330R on the AXE024 for the SDA and SCL lines ? Have you double-checked that SDA and SCL are not crossed over, are connected to the correct pins ?

I don't understand why Technical's code would not work as it is similar to other example code, and I don't understand why the code I would not expect to work apparently does, at least in some cases.

My approach would be to connect a byte-address I2C EEPROM and check that works. Write bit-banged code to access the bus and check it works with the EEPROM, then try using the compass with that. Implement exactly as the datasheet says it should be, check what's happening with a logic analyser, and then tweak to make it work. That's not however going to be a five minute job.
 
Top