Shop OBEX P1 Docs P2 Docs Learn Events
Serial in from Garmin GPS — Parallax Forums

Serial in from Garmin GPS

Brendon PolandBrendon Poland Posts: 7
edited 2008-01-11 13:19 in BASIC Stamp
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

Comments

  • Brendon PolandBrendon Poland Posts: 7
    edited 2008-01-09 16:00
    Here is the complete program if some is interested. Just ignore the commented lines of code. They were for a different application for the ideas i'm working with.

    Thanks.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-01-09 16:39
    Hi Brendon, because of the long length of the string you are trying to capture you need to make use of the WAIT instruction and px's scratch pad ram to collect the data.

    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.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-01-09 17:19
    Brendon,

    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
  • Brendon PolandBrendon Poland Posts: 7
    edited 2008-01-09 18:02
    jeff,

    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?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-01-09 18:17
    Brendon,

    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
  • Brendon PolandBrendon Poland Posts: 7
    edited 2008-01-09 19:15
    With the following code, the debug window pops up but no values are displayed. What do you think?



    ' {$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
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-01-09 20:12
    Brendon,

    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
  • Brendon PolandBrendon Poland Posts: 7
    edited 2008-01-11 13:19
    Wow, these are some great leads, it will be a while until i can process all this data and see what final problems I end up with. Thanks for all the comments, very helpful. You will hear from me as the project moves forward. Thanks again.

    Brendon
Sign In or Register to comment.