GPS, NEMA extraction for Picaxe

Marcwolf

Senior Member
GPS, NMEA extraction for Picaxe

Hi
This is a GPS extraction routine that make use of the scratchpad for pointer operations. I can be modified to use
stanadard memory as well using th BPTR

I've corrected the format of the code after a fight with the editor.

Enjoy
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 storeptr = 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
 
Last edited:

MPep

Senior Member
You must mean NMEA, not NEMA. NEMA is a totally different mechanical standard.

Thanks for posting though.
 

papaof2

Senior Member
Hi
This is a GPS extraction routine that make use of the scratchpad for pointer operations. I can be modified to use
stanadard memory as well using th BPTR

Enjoy
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 neededSymbol ptrSer = w26  ' Pointer for incoming serialSymbol ptrI2C = w27  ' Pointer for outgoing I2CSymbol SerPoke = 256 ' Start of the Scratchpad area of SerialSymbol I2CPoke = b49 ' Slave I2C store ptr for Master to grabSymbol PokePtr = b51 ' Temp area for extractionSymbol Commas = b50  ' # of comma's to start fromSymbol GPSPort = b.7 ' Where is the GPS' Starts of routineGPS:' Clear scratchpad to spaces ready for dataptr =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 scratchpadserin 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,@ptrincpause 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 I2CPokeCommas = 1: gosub GetString : I2CPoke = 0   : gosub PutString ' TimeCommas = 2: gosub GetString : I2CPoke = 30  : gosub PutString ' LatCommas = 3: gosub GetString : I2CPoke = 110 : gosub PutString ' E/WCommas = 4: gosub GetString : I2CPoke = 45  : gosub PutString ' Long Commas = 5: gosub GetString : I2CPoke = 115 : gosub PutString ' N/SCommas = 9: gosub GetString : I2CPoke = 60  : gosub PutString ' MSLCommas = 10:gosub GetString : I2CPoke = 120 : gosub PutString ' Meters for MSL' Same againptr=SerPokeserin 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,@ptrincPause 100Commas = 2: gosub GetString : I2CPoke = 125 : gosub PutString ' GPS FixCommas = 7: gosub GetString : I2CPoke = 75  : gosub PutString ' speedCommas = 8: gosub GetString : I2CPoke = 90  : gosub PutString ' DirectionCommas = 9: gosub GetString : I2CPoke = 15   : gosub PutString ' Date' now read out the scratchpad to simulate a I2C Master Readptr =0: for b0 = 0 to 150 : ptr = b0: sertxd(@ptr) : next : sertxd(CR,LF)' you can add other functions and processes.GOTO GPSGetString:' Clear temp mem - 15 Bytesfor b0 = 80 to 95: poke b0,32: next' Search along the scratchpad for X number of comma'sptrSer =  SerPokeptr = SerPoke -1b2 = 0  ' count of comma'sdo  ' 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 ifloop' We are at the X comma, check that there is a next characterif @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 commado  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 ifloop' nothing more to do.  GPS extract is in bytes 80 to 95 ready for processingreturn  PutString:' put the memory store back into the correct position of the  SLAVE I2C storeptr = I2CPoke  ' set pointer to the I2C slave areaFor 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 storenextreturn
Look at the semi-colon locations. The code has no CR/LF's in it and thus can't be used.

John
 

westaust55

Moderator
You must mean NMEA, not NEMA. NEMA is a totally different mechanical standard.

Thanks for posting though.
Oh heck,
. . . .and I thought it was electrical

National Electrical Manufacturers Association

now where was that glass house ;)
 

papaof2

Senior Member
This passes the syntax check. I don't have a 28X2 + GPS near this computer so I didn't do a hardware check.

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 storeptr = 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
The abbreviation is NMEA for National Marine Electronics Association, the group behind the protocol of the GPS sentences.

John
 

MPep

Senior Member
Okay, I stand corrected. I had, though, seen another NEMA. Can't remember where though, it was a few years ago.
In NMEA, National means USA. ie they started it.
 
Top