Serial in from Garmin GPS
I'm using a Garmin GPS18 5hz because i need a refresh rate of 5 times a second versus the 1 time per second that most other GPS receivers provide. I'm starting with a Garmin GPS18LVC with a refresh rate of 1 times per second to get the serial code working before i bump up the amount of data i need to process. I need to extract Latitude, longitude, altitude and heading from the GPS data. Therefore i have the GPS outputting two sentences and their format is as follows:
$GPGGA,123818,4313.2502,N,07524.5382,W,2,12,0.8,159.3,M,-33.8,M,,*7A
$GPVTG,289,T,302,M,000.0,N,0000.0,K*7C
I need the underlined and bolded numbers. As follows is the "SERIN" code that i've attempted to implement. I'm using a bs2px.
TIME······· VAR·· Word···· 'TIME
LAT········ VAR·· Word···· 'LATITUDE
LONG······· VAR·· Word···· 'LONGITUDE
ALT········ VAR·· Word···· 'ALTITUDE
SDAT2······ CON·· 14······ 'GPS DATA IN
BAUD2······ CON·· 813····· 'GPS DATA IN BUAD RATE
SERIN SDAT2, BAUD2,[noparse][[/noparse]TIME, LAT, LONG, ALT]
I'm then debugging and looking at the variables and they look nothing like they should. I played with using the DEC option to format them correctly as numbers and not ascii code. The stange thing is if i replace
SERIN SDAT2, BAUD2,[noparse][[/noparse]TIME, LAT, LONG, ALT]
with
SERIN SDAT2, BAUD2,[noparse][[/noparse]dec TIME, dec LAT, dec LONG, dec ALT]
I get nothing from the debug monitor. I never get a reading. If anyone could give me an idea what i'm doing wrong, that would be great. Thanks.
Brendon Poland
$GPGGA,123818,4313.2502,N,07524.5382,W,2,12,0.8,159.3,M,-33.8,M,,*7A
$GPVTG,289,T,302,M,000.0,N,0000.0,K*7C
I need the underlined and bolded numbers. As follows is the "SERIN" code that i've attempted to implement. I'm using a bs2px.
TIME······· VAR·· Word···· 'TIME
LAT········ VAR·· Word···· 'LATITUDE
LONG······· VAR·· Word···· 'LONGITUDE
ALT········ VAR·· Word···· 'ALTITUDE
SDAT2······ CON·· 14······ 'GPS DATA IN
BAUD2······ CON·· 813····· 'GPS DATA IN BUAD RATE
SERIN SDAT2, BAUD2,[noparse][[/noparse]TIME, LAT, LONG, ALT]
I'm then debugging and looking at the variables and they look nothing like they should. I played with using the DEC option to format them correctly as numbers and not ascii code. The stange thing is if i replace
SERIN SDAT2, BAUD2,[noparse][[/noparse]TIME, LAT, LONG, ALT]
with
SERIN SDAT2, BAUD2,[noparse][[/noparse]dec TIME, dec LAT, dec LONG, dec ALT]
I get nothing from the debug monitor. I never get a reading. If anyone could give me an idea what i'm doing wrong, that would be great. Thanks.
Brendon Poland
Comments
Thanks.
SERIN SDAT2, BAUD2,[noparse][[/noparse]WAIT("$GPG"),SPSTR 60]
then use GET to retrieve the data
FOR idx=0 TO 59
GET idx, value
DEBUG value
NEXT
that should retrieve and display the first set of data which you would need to parse using the comma seperators. You would use a similar method for the second data but use a different wait string $GPV.
Jeff T.
I am always surprised by a 5Hz refresh rate on a GPS since that implies that the baud rate will be higher on the output. Most GPS Modules that I have seen have a 4800 bps serial output. At that rate it takes just under 1 second to get all the strings from the module. If you were to get them all at 5Hz you would need to, in theory, increase the baud rate by a factor of 5, which would be 24K (closest standard baud rate would be 28.8K). While a BS2p could do this, with overhead processing of the string from the GPS you would never realize 5Hz worth of processing. In fact you would be lucky to get 1Hz. Assuming the GPS does transmit at higher baud rates I would recommend an SX or Propeller for this application if you need 5Hz processing.
As for your issue with the SERIN command…You’re actually trying to input each digit as a single binary value in the first line. In the second line you’re trying to convert them into decimal, however many of the fields are higher value than a 16-bit Word variable can hold. Instead read the data into the SPRAM and decode it from there. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
my one thought was that if i use the "DEC" command like this:
SERIN ... [noparse][[/noparse]DEC Time]
That it will wait automatically until it sees its first numerical character.
Are you familiar with that?
As I explained above, the values you are trying to input exceed what a byte can hold. The decimal input is read until a non-numeric character is encountered. Also, using a formatter like that at high speed would diminish the BASIC Stamp’s ability to decode successive variables. You will need to input the string and decode it. You will also need Word sized variables and you will not be able to input fractional (floating point) values.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
' {$STAMP BS2px}
' {$PBASIC 2.5}
idx VAR Byte
value VAR Byte
SDAT2 CON 14 'GPS DATA IN
BAUD2 CON 813 'GPS DATA IN BUAD RATE
TIME VAR Word 'TIME
LAT VAR Word 'LATITUDE
LONG VAR Word 'LONGITUDE
ALT VAR Word 'ALTITUDE
MAIN:
DO
SERIN SDAT2, BAUD2,[noparse][[/noparse]WAIT("$GPG"),SPSTR 60]
FOR idx=0 TO 59
GET idx, value
DEBUG value
NEXT
How do you have your GPS18LVC connected to the Stamp? Looking at the datasheet, it appears that, even though the serial output voltage ranges from 0 to the supply voltage, the polarity is negative (i.e. marking low), in conformance with RS232 standards. So, unless you're using an inverter or an RS232 receiver, you will need to set your BAUD2 constant to 17197, instead of 813.
-Phil
Perhaps these Nut & Volts·columns, customer applications and NMEA data links will help:
http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol3/col/nv83.pdf
http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol4/col/nv103.pdf
http://www.parallax.com/dl/docs/cusapps/NearSpace4.pdf
http://www.roboeducators.org/downloads/prog%20inst/Datalogging%20with%20a%20GPS.PDF
http://www.gpsinformation.org/dale/nmea.htm
I hope this helps.
SJW
Brendon