Simple GPS for Picaxe

Marcwolf

Senior Member
Hi Folks.
I want to thank all of those who have gone before me in writing GPS extraction code. Without your insight this project would not be done.

Basically I wanted to make an I2C slave that would process information in the background from several sources and present it in the scratchpad for a Master to pick up.

I tried using HSerIn but to no avail (either no input or missed characters) and I also needed storage space to put the GPS information in.

I was please to find that I could serial in straight to the scratchpad using the @ptrinc , and that gave me some idea's to work with
Serin has the advantage that you can give it the exact GPS NEMA code to look for, and then guesimate the maximum number of characters to read in to the scratchpad.
Once it is there then you can process at your leisure.

Anyway - here is the code. Enjoy.
Take Care
Dave
Code:
; *******************************
; ***** GPS I2C Slave       *****
; *******************************
;    Filename: GPS_Pixaxe  
;    Date:   04/09/2011 
;    File Version: 1.5 
;    Written by:  Marcwolf 
;    Function:  Decode GPS Signals
;    Last Revision:
;    Target PICAXE: 28X2
; ******************************* 

' This should work on any Picaxe with a scratchpad and variable space
' The scratchpad is split into 2 parts
' 0 to 256 (changable as we only really need 130.. But this is only the 
' start for this project.
' and 256 + for info retrieved from the GPS unit (EM406A but can be any)
' The target conept is to have a Slave I2C PicAxe that will gather 
' GPS, Temp, Voltage etc data and present it in the scratchpad
' ready for the master to collect it.
' There is no special speed constraints on this so no SetFreq is needed

Symbol ptrSer = w26  ' Pointer for incoming serial
Symbol ptrI2C = w27  ' Pointer for outgoing I2C
Symbol SerPoke = 256 ' Start of the Scratchpad area of Serial
Symbol I2CPoke = b49 ' Slave I2C store ptr for Master to grab
Symbol PokePtr = b51 ' Temp area for extraction
Symbol Commas = b50  ' # of comma's to start from
Symbol GPSPort = b.7 ' Where is the GPS
' Starts of routine
GPS:
' Clear scratchpad to spaces ready for data
ptr =0: for b0 = 0 to 150 : ptr = b0 : @ptr = 32 : next
 
ptr=SerPoke ' Set pointer to start of GPS store
' Get the GPS info in. Had issues with HSERIn so now just use the scratchpad
serin GPSPort,T4800,("GPGGA"),@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc
pause 100 ' pause to take processing breath
' Get the information
' Search GPS scratchpad for the number of Comma's
' then put the resulting text into the scratchpad
' starting at potion I2CPoke
Commas = 1: gosub GetString : I2CPoke = 0   : gosub PutString ' Time
Commas = 2: gosub GetString : I2CPoke = 30  : gosub PutString ' Lat
Commas = 3: gosub GetString : I2CPoke = 110 : gosub PutString ' E/W
Commas = 4: gosub GetString : I2CPoke = 45  : gosub PutString ' Long 
Commas = 5: gosub GetString : I2CPoke = 115 : gosub PutString ' N/S
Commas = 9: gosub GetString : I2CPoke = 60  : gosub PutString ' MSL
Commas = 10:gosub GetString : I2CPoke = 120 : gosub PutString ' Meters for MSL

' Same again
ptr=SerPoke
serin GPSPort,T4800,("GPRMC"),@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc,@ptrinc
Pause 100
Commas = 2: gosub GetString : I2CPoke = 125 : gosub PutString ' GPS Fix
Commas = 7: gosub GetString : I2CPoke = 75  : gosub PutString ' speed
Commas = 8: gosub GetString : I2CPoke = 90  : gosub PutString ' Direction
Commas = 9: gosub GetString : I2CPoke = 15   : gosub PutString ' Date
' now read out the scratchpad to simulate a I2C Master Read
ptr =0: for b0 = 0 to 150 : ptr = b0: sertxd(@ptr) : next : sertxd(CR,LF)
' you can add other functions and processes.
GOTO GPS

GetString:
' Clear temp mem - 15 Bytes
for b0 = 80 to 95: poke b0,32: next
' Search along the scratchpad for X number of comma's
ptrSer =  SerPoke
ptr = SerPoke -1
b2 = 0  ' count of comma's
do  ' look until we find the comma we are looking for
  if @ptrinc = "," then ' We found a comma
    inc b2 
    if b2 = Commas then exit ' Are we X Comma's along. If so then exit
  end if
loop
' We are at the X comma, check that there is a next character
if @ptrinc = "," then return : end if ' empty string as in ,,
dec ptr :PokePtr = 80 ' Step back one position and reset the temp memory ptr
' Now get the string to the next comma
do
  b0 = @ptrinc ' Get the valid character
  if b0 = "," then  ' Are we at the next delimiter
    exit ' ok jump out of loop
  else
     poke PokePtr, b0 ' put the actual value into the memory store
     inc  PokePtr ' increment memory store ptr
  end if
loop
' nothing more to do.  GPS extract is in bytes 80 to 95 ready for processing
return  

PutString:
' put the memory store back into the correct position of the  SLAVE I2C store
ptr = I2CPoke  ' set pointer to the I2C slave area
For b0 = 80 to 95 ' loop through memory store
   peek b0,b1 ' get the info
   if b1 = 32 then return: end if ' A space - then we are at the end of the string
   @ptrinc  = b1 ' poke the value into the I2C store
next
return
 

westaust55

Moderator
Great to read that you have your code functioning.

Although I have hand held type GPS for walk in the Australia bush (forests for others) and on my bicycle for easy location for ad-hoc travelling to know where a track or turn-off might lead, I have not experimented with GPS in conjunction with the PICAXE chips.

Your information may do well to be posted in the Finished Projects area where is is not lost amongst the continuing steam of thread - at least quite so rapidly.
Let the moderators know if you would like it moved and this can easily be done for you.
 
Last edited:

Marcwolf

Senior Member
Hi Westaust

Is there a Fishing Projects section?

I created this routine because I wanted to fee it's output into a Heads Up Display

Many thanks
Dave
 

westaust55

Moderator
Hi Westaust

Is there a Fishing Projects section?

I created this routine because I wanted to fee it's output into a Heads Up Display

Many thanks
Dave
There is always some one "Fishing" for information
But in this case seems iPhone auto correct over corrected for my Fiendishly Flailing Fingers.

Finished Projects area was the intended destination,
Not tied to a lump of lead and submerged.

What's the $ fee for a Heads up display?
Or is that a red herring ;)
 
Top