Shop OBEX P1 Docs P2 Docs Learn Events
GPS Clock — Parallax Forums

GPS Clock

TickTockTonyTickTockTony Posts: 12
edited 2011-03-17 10:19 in BASIC Stamp
Hello All

I have a Basic Stamp 2 and am using it along with a Garmin 18xLVC GPS to make a clock.

I am trying to input the GPGGA sentence into the stamp chip to strip off Hr Min sec

Below is the sentence I capture in Hyperterminal so the correct data is coming out of the GPS. the time here is 21:39:59

$GPGGA,213949,3339.5437,N,11733.7918,W,1,06,2.2,405.7,M,-34.4,M,,*75
$GPGGA,213950,3339.5437,N,11733.7919,W,1,06,2.2,405.7,M,-34.4,M,,*7C
$GPGGA,213951,3339.5437,N,11733.7918,W,1,06,2.2,405.8,M,-34.4,M,,*73
$GPGGA,213952,3339.5436,N,11733.7919,W,1,05,2.8,405.8,M,-34.4,M,,*79
$GPGGA,213953,3339.5436,N,11733.7919,W,1,06,2.2,405.8,M,-34.4,M,,*71
$GPGGA,213954,3339.5436,N,11733.7919,W,1,06,2.2,405.8,M,-34.4,M,,*76
$GPGGA,213955,3339.5436,N,11733.7918,W,1,05,2.8,405.9,M,-34.4,M,,*7E
$GPGGA,213956,3339.5435,N,11733.7918,W,1,05,2.8,405.9,M,-34.4,M,,*7E
$GPGGA,213957,3339.5435,N,11733.7918,W,1,05,2.8,405.9,M,-34.4,M,,*7F
$GPGGA,213958,3339.5434,N,11733.7918,W,1,05,2.8,405.9,M,-34.4,M,,*71
$GPGGA,213959,3339.5433,N,11733.7917,W,1,06,2.2,406.0,M,-34.4,M,,*7B


Problem is I can NOT capture this in my stamp2. I have looked at the demo codes used for the stamp2p and the Parallax GPS and have used elements of these to greater a code that works for me.

below is the code I am using.

Question is am I flogging a dead hoarse and need to go purchase the Stamp2p, or should I
persist?

GPS to stamp via input pin #8 and baud rate 4800 8b noP 1 stop flow hardware

Thanks in advance for your time
TickTockTony
Orange County, CA

' {$STAMP BS2}
' {$PBASIC 2.5}


sec VAR Word
cnt3 VAR Word
cnt3 = 0
sec = 0
tmHrs VAR Byte ' time fields
tmMins VAR Byte
tmSecs VAR Byte
Baud CON Open | 4800 ' Open mode to allow daisy chaining
Open CON $8000
T4800 CON 188


garmin:
'DEBUG ? "eaiting for pulse"
IF (IN4 = 1) THEN
sec = sec + 1

'SERIN 8, 4800, [tmHrs]
SERIN 8, Baud, [tmHrs, tmMins, tmSecs]
DEBUG DEC2 tmHrs, ":", DEC2 tmMins, ":", DEC2 tmSecs, CR
GOTO clock
ELSE
GOTO garmin
ENDIF


'move the clock hands
clock:
'DEBUG ? " move clock hands"

IF (IN4 =1) THEN
GOTO clock
ELSE
IF (cnt3 = 0) THEN
HIGH 12
LOW 11
cnt3 = cnt3 + 1
ELSE
LOW 12
HIGH 11
cnt3 = 0

ENDIF
ENDIF
PAUSE 200
GOTO garmin
«1

Comments

  • PublisonPublison Posts: 12,366
    edited 2011-03-14 16:50
    Will your BS2 read $GPRMC sentences with the following code?

    I'm not seeing where you test for $GP in the string.



    Hello All

    I have a Basic Stamp 2 and am using it along with a Garmin 18xLVC GPS to make a clock.

    I am trying to input the GPGGA sentence into the stamp chip to strip off Hr Min sec

    Below is the sentence I capture in Hyperterminal so the correct data is coming out of the GPS. the time here is 21:39:59

    $GPGGA,213949,3339.5437,N,11733.7918,W,1,06,2.2,405.7,M,-34.4,M,,*75
    $GPGGA,213950,3339.5437,N,11733.7919,W,1,06,2.2,405.7,M,-34.4,M,,*7C
    $GPGGA,213951,3339.5437,N,11733.7918,W,1,06,2.2,405.8,M,-34.4,M,,*73
    $GPGGA,213952,3339.5436,N,11733.7919,W,1,05,2.8,405.8,M,-34.4,M,,*79
    $GPGGA,213953,3339.5436,N,11733.7919,W,1,06,2.2,405.8,M,-34.4,M,,*71
    $GPGGA,213954,3339.5436,N,11733.7919,W,1,06,2.2,405.8,M,-34.4,M,,*76
    $GPGGA,213955,3339.5436,N,11733.7918,W,1,05,2.8,405.9,M,-34.4,M,,*7E
    $GPGGA,213956,3339.5435,N,11733.7918,W,1,05,2.8,405.9,M,-34.4,M,,*7E
    $GPGGA,213957,3339.5435,N,11733.7918,W,1,05,2.8,405.9,M,-34.4,M,,*7F
    $GPGGA,213958,3339.5434,N,11733.7918,W,1,05,2.8,405.9,M,-34.4,M,,*71
    $GPGGA,213959,3339.5433,N,11733.7917,W,1,06,2.2,406.0,M,-34.4,M,,*7B


    Problem is I can NOT capture this in my stamp2. I have looked at the demo codes used for the stamp2p and the Parallax GPS and have used elements of these to greater a code that works for me.

    below is the code I am using.

    Question is am I flogging a dead hoarse and need to go purchase the Stamp2p, or should I
    persist?

    GPS to stamp via input pin #8 and baud rate 4800 8b noP 1 stop flow hardware

    Thanks in advance for your time
    TickTockTony
    Orange County, CA

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}


    sec VAR Word
    cnt3 VAR Word
    cnt3 = 0
    sec = 0
    tmHrs VAR Byte ' time fields
    tmMins VAR Byte
    tmSecs VAR Byte
    Baud CON Open | 4800 ' Open mode to allow daisy chaining
    Open CON $8000
    T4800 CON 188


    garmin:
    'DEBUG ? "eaiting for pulse"
    IF (IN4 = 1) THEN
    sec = sec + 1

    'SERIN 8, 4800, [tmHrs]
    SERIN 8, Baud, [tmHrs, tmMins, tmSecs]
    DEBUG DEC2 tmHrs, ":", DEC2 tmMins, ":", DEC2 tmSecs, CR
    GOTO clock
    ELSE
    GOTO garmin
    ENDIF


    'move the clock hands
    clock:
    'DEBUG ? " move clock hands"

    IF (IN4 =1) THEN
    GOTO clock
    ELSE
    IF (cnt3 = 0) THEN
    HIGH 12
    LOW 11
    cnt3 = cnt3 + 1
    ELSE
    LOW 12
    HIGH 11
    cnt3 = 0

    ENDIF
    ENDIF
    PAUSE 200
    GOTO garmin
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-03-14 17:10
    SPSTR doesn't work with the BS2. I would try something like this:
    SERIN 8, Baud, [WAIT("GPGGA,"), DEC2 Hr, DEC2 Min, DEC2 Sec]
    
    -Phil
  • TickTockTonyTickTockTony Posts: 12
    edited 2011-03-14 18:12
    Hello All

    I tried the wait and DEC2 statments with no luck. with wait statment the programs halts at the wait. With no wait and the DEC2 parameter the progran loops 5 times slower than it shouls and data is still incorect.

    garmin:
    'SERIN 8, 4800, [tmHrs, tmMins, tmSecs]
    'SERIN 8, 4800, [DEC2 tmHrs, DEC2 tmMins, DEC2 tmSecs]
    SERIN 8, 4800, [WAIT("GPGGA,"), DEC2 tmHrs, DEC2 tmMins, DEC2 tmSecs]
    DEBUG DEC2 tmHrs, ":", DEC2 tmMins, ":", DEC2 tmSecs, CR
    GOTO garmin
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-03-14 18:22
    Read the PBASIC manual about how to specify baudrates. You can't just stick 4800 in the SERIN command.

    -Phil
  • TickTockTonyTickTockTony Posts: 12
    edited 2011-03-14 18:54
    Hi Phil

    Books shows several examples where the baude rate is directley entered .

    Initaly I had my program looking just like the demo example, see below.

    It does not help.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    sec VAR Word
    cnt3 VAR Word
    cnt3 = 0
    sec = 0
    tmHrs VAR Byte ' time fields
    tmMins VAR Byte
    tmSecs VAR Byte
    T4800 CON 188
    Open CON $8000
    Baud CON Open | T4800 ' Open mode to allow daisy chaining
    garmin:
    'SERIN 8, Baud, [tmHrs, tmMins, tmSecs]
    'SERIN 8, Baud, [DEC2 tmHrs, DEC2 tmMins, DEC2 tmSecs]
    SERIN 8, Baud, [WAIT("GPGGA,"), DEC2 tmHrs, DEC2 tmMins, DEC2 tmSecs]
    DEBUG DEC2 tmHrs, ":", DEC2 tmMins, ":", DEC2 tmSecs, CR
    GOTO garmin


    Tony
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-03-14 20:07
    Tony,

    SERIN does not have an OPEN mode modifier. That's only for SEROUT. Try it without the $8000.

    -Phil
  • TickTockTonyTickTockTony Posts: 12
    edited 2011-03-14 23:30
    I removed the open with no luck. manual sujests I use 2400 or lower so i will try this. Problem is My GPS will not switch lower than 4800. I will talk to the Garmin people and get back to the forum when I have an answer
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-03-14 23:41
    What model GPS do you have and how is it connected to the Stamp?

    -Phil
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-03-15 05:43
    Anyone mind if I barge in?
    I think the Garmin is an RS-232 True output, so the Stamp's baudmode should be an Inverted (id est "TTL inverted").
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-03-15 08:24
    Thanks, PJ. That's what I was wondering. In that case the voltage range s a concern, too, without some resistive protection to his Stamp pin.

    -Phil
  • TickTockTonyTickTockTony Posts: 12
    edited 2011-03-15 10:10
    Thanks PJ and Phil

    I have a Garmin 18xLVC. I have 22K ohn resistor in serise with the pin 2 in data. I find the code will not assembel if I use a N4800 for the baud rate statment.

    Garmin replied and said the 18X does not go lower than 4800. That explanes wht the menue selection of 2400 does not work.

    Any and all comments welsome, as I have to get this working.

    Thanks for your time
    Tony
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-03-15 10:23
    Baud rate constants like N4800 are not predefined for the BS2 series; That's only for the BS1. You have to tell the compiler what value it has. The value to use is 16572, i.e. 188 + 16384.

    -Phil
  • TickTockTonyTickTockTony Posts: 12
    edited 2011-03-15 13:13
    Ok partal breakthrough

    The code below gives the correct hrs but incorect value for min and sec. I know this because the debug display shows 19:06:06 and changed to 20:06:06 when UTC time changed the Hrs

    Based in this information the baud rate and wait statment must be OK.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    sec VAR Word
    cnt3 VAR Word
    cnt3 = 0
    sec = 0
    tmHrs VAR Byte ' time fields
    tmMins VAR Byte
    tmSecs VAR Byte
    tmHrs = 0
    tmMins = 0
    tmSecs = 0

    Baud CON 16572
    garmin:

    SERIN 8, Baud, [WAIT("GPGGA,"), DEC2 tmHrs, DEC2 tmMins, DEC2 tmSecs]
    DEBUG DEC2 tmHrs, ":", DEC2 tmMins, ":", DEC2 tmSecs, CR
    GOTO garmin
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-03-15 13:46
    We may be up against the BS2's speed limit then. A couple things to try:

    1. Change all the DEC2s to HEX2. We can worry about converting to decimal later.

    2. Read the time as a 6-byte string:
    Hr  VAR Byte(2)
    Mn  VAR Byte(2)
    Sc  VAR Byte(2)
    
    SERIN 8, Baud, [WAIT("GPGGA,"), STR Hr\6]
    DEBUG STR Hr\2, ":", STR Mn\2, ":", STR Sc\2, CR
    

    -Phil
  • TickTockTonyTickTockTony Posts: 12
    edited 2011-03-15 15:12
    No luck. Getting a Stamp2p, may recieve it tomorow. lets see what it can do.

    Tony
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-03-15 15:21
    Tony,

    I had a syntax error in the latest PBASIC code I posted -- now corrected. ('Too used to Spin syntax these days.) By "no luck" did you mean that the program didn't compile, or that it didn't output the right results?

    -Phil
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-03-15 15:30
    "Speed limit" -- nay way.
    I use/have used the STR'ing successfully with a BS2. Though it's with a different sentence, the principle is the same --
    SERIN 9,188,[WAIT("GLL,"),STR PA\2,STR PM\2,SKIP 1,STR PD\3,SKIP 2,STR NS\1,SKIP 1,STR MA\3,STR MM\2,SKIP 1,STR MD\3,SKIP 2,STR EW\1,SKIP 1,STR [COLOR="red"]TM\6[/COLOR],SKIP 5,STR AV\1]

    TM\6 is the hours, minutes, seconds
    The SKIPs are the commas (CSV).

    I use baudmode = 188 because I always use a MAX232.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-03-15 15:45
    PJ,

    Yes, I would've thought the BS2 could keep up with the STR stuff at 4800 baud. On-the-fly DEC conversions? Maybe not so much. I hope Tony didn't run off and buy a BS2p just because my example code didn't compile.

    -Phil
  • TickTockTonyTickTockTony Posts: 12
    edited 2011-03-15 20:26
    Hello chaps

    Sorry to be brief I had and appointment.

    Original code debug output
    03:06:03
    03:06:05
    03:06:03
    03:06:03
    The 03 hour is correct and will incroment when it should. The min and seconde do not make sence. Is it is not min 06 and it will never increment no matter how long you leave it.

    Replacing Dec2 with Hex2
    03:06:0B
    03:06:0B
    03:06:0B
    Again hour is correct and inrements and min and sec do not make sence.

    changing the time to a string value got did not compile. however i plaied aroud with string and work values and could not get the correct output.

    No phill i am not getting a Stamp2p cos the code did not compile. i ordered it yeaterday cos like this system and need a second processor and the GPS demo code was for a 2P.

    Thanks for your help

    regards Tony
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-03-15 20:51
    C.mon, TTT, this "not compiling stuff" isn't going to make it.
    Please Attach your code, uncompiling or otherwise.
  • TickTockTonyTickTockTony Posts: 12
    edited 2011-03-15 22:25
    Phil

    You mention the syntax error "now corected" Where can I find the corected version?
  • TickTockTonyTickTockTony Posts: 12
    edited 2011-03-15 22:30
    Phil

    The code in the post has a compalation error "expected end of lind "

    at the "\" in Time(2)\2

    Tony
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-03-16 05:45
    TTT,
    Push the "Go Advanced" button and then scroll down a bit and push the "Manage Attachments" button and Attach your code.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-03-16 11:05
    Tony,

    I've made another correction to the code. In addition to the obvious syntax error, PBASIC exhibited a restriction that I didn't know existed. 'Sorry for the misdirection.

    -Phil
  • TickTockTonyTickTockTony Posts: 12
    edited 2011-03-16 15:50
    Hurray! We got it working. Thanks Phil and PJ for your time.

    The ending problem was to implement Paul’s modifies string code.

    Tony
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-03-16 17:32
    Bravo!
    (Now to get that subject title"unsolved" changed to "Solved"; Phil will be over the Moon I'm sure.)
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-03-16 18:58
    PJ Allen wrote:
    Phil will be over the Moon I'm sure.
    I don't know about Phil, but I'm sure Paul will be! :)

    -Phil
  • PublisonPublison Posts: 12,366
    edited 2011-03-16 19:06
    Not sure when Paul ?? jumped in , but I sure would like to see the code published so others can benefit from it.
    I don't know about Phil, but I'm sure Paul will be! :)

    -Phil
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-03-16 19:57
    Well, if you're interested in mine, it's attached.
    I grab the $GPGLL data, format it and send it to
    a 4x20 serial LCD.
    It's been chugging along, 24/7, for >5 years.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-03-16 20:16
    Publison wrote:
    Not sure when Paul ?? jumped in , but I sure would like to see the code published so others can benefit from it.
    PJ Allen wrote:
    Well, if you're interested in mine, it's attached.
    Hey, waaaiit a minute! "PJ" is Paul J Allen? All this time, the Paul Allen has been contributing to our forum? (Now Bill's picture in his avatar makes sooo much more sense!)

    -Phil
Sign In or Register to comment.