Shop OBEX P1 Docs P2 Docs Learn Events
bs2 gps lcd — Parallax Forums

bs2 gps lcd

brodbrod Posts: 16
edited 2012-10-26 09:55 in BASIC Stamp
Hi all
I am new to coding and need a little help with this.
Parts used
BOE BS2 PMB-648 2 x 16 LCD
Basically the code works i.e. I can get a fix and the results are correct, but if I move position the lcd does not refresh the data.

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


LatDeg VAR Byte
LatMin VAR Byte
LatMinD VAR Word
LatSign VAR Byte
LatDir VAR Byte


LonDeg VAR Byte
LonMin VAR Byte
LonMinD VAR Word
LonSign VAR Byte
LonDir VAR Byte


wVal VAR Word


'
[ Constants ]


LcdBLon CON 17 ' backlight on






'Baud rates (non-inverted):
n4800 CON 188
n19200 CON 32












'
lcd start up
SEROUT 0, n19200, [22, 12] 'initalize lcd
SEROUT 0, n19200, [LcdBLon] 'turn on lcd backlight


Main:
DO
'Get GPSRMC statement from pin 15
SERIN 15, n4800, [WAIT("RMC,"),SKIP 13,
DEC2 LatDeg, DEC LatMin, SKIP 1, DEC LatMinD, SKIP 1, LatSign,
DEC3 LonDeg, DEC LonMin, SKIP 1, DEC LonMinD, SKIP 1, LonSign]








'lcd information


wVal = (LatMin * 1000 / 6) + (LatMinD / 60) 'convert to min/seconds
SEROUT 0, n19200, [REP "-"\ LatDir, DEC LatDeg, ".", DEC4 wVal, " S ", 13]


wVal = (LonMin * 1000 / 6) + (LonMinD / 60) 'convert to min/seconds
SEROUT 0, n19200, [REP "-"\ LonDir, DEC LonDeg, ".", DEC4 wVal, " W ",128]




GOSUB AddSign
PAUSE 500


LOOP




AddSign:
IF LatSign = "S" THEN
LatDir = 1
ELSE
LatDir = 0
ENDIF


IF LonSign = "W" THEN
LonDir = 1
ELSE
LonDir = 0
ENDIF


RETURN

Thanks
Brod
«1

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-10-20 05:33
    You're skipping the status character (A / V), that would tell you if you're getting a solid fix (A) or not (V).
    but if I move position the lcd does not refresh the data.
    You need to walk down the road or something.
    It's not going to pin-point your position in the front room.
  • brodbrod Posts: 16
    edited 2012-10-20 05:45
    Thanks for your reply PJ Allen
    I am getting a solid red light on the GPS so I took it for granted I was getting a solid fix.
    I am also taking the readings out doors and no matter how far I walk the LCD does not change, but if I switch off and back on the data refreshes.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-10-20 06:15
    If you include the seconds characters, or at least the "ones" character, on your LCD then you could see something change with each pass through the DO..LOOP
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-10-20 06:23
    I guess you're trying to effect some kind of graphic with REP"-"\ LonDir
  • brodbrod Posts: 16
    edited 2012-10-20 08:52
    Not sure what REP means, copied the code from Parallax kickstart and tried to change it from displaying results in Debug to LCD
    As I said earlier very new to coding.
    Thanks again
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-10-20 10:24
    I believe the following will capture the seconds characters and the status character and print that out on the LCD.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    status  VAR Byte
    secs_10 VAR Byte
    secs_01 VAR Byte
    
    ' -----[ Constants ]------------------
    LcdBLon CON 17 ' backlight on
    
    'Baud rates (non-inverted):
    n4800 CON 188
    n19200 CON 32
    
    '--------------lcd start up-----------
    SEROUT 0, n19200, [22, 12, $19, $00] 'initalize lcd
    SEROUT 0, n19200, [LcdBLon]          'lcd bklt on
    
    ' $GPRMC example
    ' $GPRMC,161229.487,A,3723.2475,N,12158.3416,W,0.13,309.62,120598, ,*10
    '            xx     x
    
    Main:
    DO
    ' Get $GPRMC statement from pin 15
    SERIN 15, n4800, [WAIT("RMC,"),SKIP 4,STR secs_10\1,
    STR secs_01\1,SKIP 5,STR status\1]
    ' print it
    SEROUT 0, n19200, [" ",STR secs_10\1,STR secs_01\1,
    "s  stat= ",STR status\1,$01]
    
    LOOP
    
    

    May The Force be with you.
  • brodbrod Posts: 16
    edited 2012-10-20 10:58
    Ok
    ran your code and without a fix you get seconds counting up and V,s.
    When fixed seconds counting up and A,s (fixed confirmed)

    When running my code it definitely does not refresh from the gps, if I press the reset button on the BOE lcd flashes but displays the same reading, but if you turn off the BOE and back on again the readings change to the correct ones.
    Its as if it gets a lock and does not bother looking for an update.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-10-20 11:38
    OK.
    I don't know what the objective of the kickstart code you've posted is.
    REP makes it REPeat dashes LatDir or LonDir number of times? :zombie: Whatever.
    Let's try ditching that part.

    Maybe change the "wval =" lines..
    wVal = (LatMin * 1000 / 6) + (LatMinD / 60) 'convert to min/seconds
    SEROUT 0, n19200, [DEC LatDeg, ".", DEC4 wVal, [COLOR="#FF0000"]$10, $13[/COLOR]]
    
    wVal = (LonMin * 1000 / 6) + (LonMinD / 60) 'convert to min/seconds
    SEROUT 0, n19200, [DEC LonDeg, ".", DEC4 wVal, [COLOR="#FF0000"]$02[/COLOR]]
    
    and see how that goes.
  • SapphireSapphire Posts: 496
    edited 2012-10-20 11:50
    The GOSUB AddSign should be moved up above the SEROUT commands, just after the SERIN if you want the "-" sign to be displayed.
  • SapphireSapphire Posts: 496
    edited 2012-10-20 12:06
    PJ,

    The "-"\REP LatDir command just displays zero or one "-" signs for the direction, but the GOSUB was in the wong place.

    Not sure why you changed the 13 to $10,$13. The 13 (CR) is supposed to move the cursor to the next line, but I would use 192 instead to exactly place it on the 2nd line. The 128 in the second SEROUT places the cursor back home, $02 is compose character 2.

    I usually place the cursor positioning commands at the beginning of the SEROUT, not the end, to ensure the cursor is at the right spot before sending data. I suspect data may be written off-screen.

    Adding a few DEBUGs before and after the SERIN would help:
    DEBUG "Waiting for GPS... "
    SERIN ...
    DEBUG "Got GPS data!",CR
    

    and then possibly showing the data with a DEBUG too.
  • brodbrod Posts: 16
    edited 2012-10-20 12:37
    Thanks for the code P J Allen but when run I get loads of numbers making no sense.
    Sapphire I have added the Debug commands but as my PC is indoors I cant get a GPS fix.
    On monday i will bring my laptop home from work and try it on that outdoors, so I can observe the Debug results.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-10-20 12:44
    Right. $10, $13 - My Error.
    Should be 10, 13 ($0A, $0C $0D): Line Feed (same position, next line) and Form Feed Carriage Return (to left-most of current line)

    $02 (or 2) is Home Cursor (upper left corner, contents unaffected)

    PE - $0C to $0D, FF to CR. Out in the sun too long, today. 10, 13 are right though (what's the matter with me?) :zombie:
  • SapphireSapphire Posts: 496
    edited 2012-10-20 13:06
    PJ,
    Out in the sun too long, today.

    I didn't think there was much sun where you are!
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-10-20 13:18
    Everything's relative.
  • brodbrod Posts: 16
    edited 2012-10-22 06:49
    Quick update
    Still no joy, put Debug in as suggested by Sapphire and got the same results as I did with the Lcd.
    Its just not refreshing the data from the gps.
    The Debug comand is refreshing but not the data from the gps. ie "Got Gps data".
    Have I missed some code that would make it look for new data at each loop?
  • PublisonPublison Posts: 12,366
    edited 2012-10-22 09:41
    Have you tried running the code with 9600 Baud to the LCD as suggested in the Kickstart code? 19.2K on a BS2 may not be achievable without flow control.
  • brodbrod Posts: 16
    edited 2012-10-22 10:21
    Thanks for the reply Publison, I tried the LCD @ 9600but still no joy I even put a 3 second delay in before the get gps routine but nothing.
    This is starting to annoy me now, it must be something simple that I am missing.
    Its strange that even if you press the reset button on the BOE it still doesn't update until you turn off and back on again.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-10-22 10:42
    It's been awhile since I've used that LCD, but I'm betting that for each new datum, you need to issue a HOME command to the LCD, so that the new data starts at the top of the screen. IIRC, the LCD does not scroll the same way the DEBUG screen does. At least that would explain the RESET vs. power-up behavior.

    -Phil
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-10-22 10:44
    Hmmm...
    See Reply #13
  • brodbrod Posts: 16
    edited 2012-10-22 12:19
    PJ Allen
    Not sure what I am supposed to enter from your post #13 sorry bit thick
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-10-22 13:39
    wVal = (LatMin * 1000 / 6) + (LatMinD / 60) 'convert to min/seconds
    SEROUT 0, n19200, [DEC LatDeg, ".", DEC4 wVal, [COLOR="#0000CD"]10, 13[/COLOR]]

    wVal = (LonMin * 1000 / 6) + (LonMinD / 60) 'convert to min/seconds
    SEROUT 0, n19200, [DEC LonDeg, ".", DEC4 wVal, [COLOR="#0000CD"]2[/COLOR]]

    I messed up those numbers last time, but I made the corrections.
    So, include the numbers at the end, as above.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-10-22 13:46
    PJ,

    'Sorry, I missed your HOME recommendation. I'll go now ...

    -Phil
  • brodbrod Posts: 16
    edited 2012-10-22 14:16
    PJ thats what I thought you ment. But that doesn't make any differance.
    I have modified my code like this,

    wVal = (LatMin * 1000 / 6) + (LatMinD / 60) 'convert to min/seconds
    SEROUT 0, n9600, [REP"-"\ LatDir, DEC LatDeg, ".", DEC4 wVal, " S ",13]

    wVal = (LonMin * 1000 / 6) + (LonMinD / 60) 'convert to min/seconds
    SEROUT 0, n9600,128, [REP"-"\ LonDir, DEC LonDeg, ".", DEC4 wVal, " W ",12]

    This makes the LCD refresh at every loop[ but the data stiil doesn't change.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-10-22 14:24
    You missed the 10 in the first iteration of the wVal =
    You kept the REP"-" stuff that I'd omitted.

    I can't win.
  • brodbrod Posts: 16
    edited 2012-10-22 14:43
    PJ if I keep the 10 in it puts al the data on one line, and without the REP stuff you lose the - sign from the result.
    Thanks
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-10-22 15:35
    In the second iteration of wVal=, you've put 12 at the end of the line instead of 2 ?

    What LCD are you using, by the way?
    Where's a link to this 'kickstart'?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-10-22 15:57
    Can you try the following?
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    
    status  VAR Byte
    secs_10 VAR Byte
    secs_01 VAR Byte
    lat     VAR Byte (7)
    lon     VAR Byte (8)
    
    ' -----[ Constants ]------------------
    LcdBLon CON 17 ' backlight on
    
    'Baud rates (non-inverted):
    n4800 CON 188
    n19200 CON 32
    
    '--------------lcd start up-----------
    SEROUT 0, n19200, [22, 12, $19, $00] 'initalize lcd
    SEROUT 0, n19200, [LcdBLon]          'lcd bklt on
    
    ' $GPRMC example
    ' $GPRMC,161229.487,A,3723.2475,N,12158.3416,W,0.13,309.62,120598, ,*10
    '            xx     x xxxxxxx     xxxxxxxx
    
    Main:
    SERIN 15, n4800, [WAIT("RMC,"),SKIP 4,STR secs_10\1,STR secs_01\1,
    SKIP 5,STR status\1,SKIP 1,STR lat\7,SKIP 5,STR lon\8]
    
    ' print it
    SEROUT 0, n19200, [$02,STR secs_10\1,STR secs_01\1," ",STR status\1,
    " ",STR lat\7," ",$0A,$0D,STR lon\8]
    
    ' $02 = home the cursor, non-destructive
    ' $0A = cursor to next line, same column
    ' $0D = cursor to furthest left on current line
    
    GOTO Main
    
  • brodbrod Posts: 16
    edited 2012-10-23 10:17
    Hi again PJ
    OK here we go, according to the LCD info 12 clears the screen and returns cursor to the home position.
    The LCD I m using is the Parallax,

    Item code
    27977.
    Kickstart link, Example KickStart Circuits & Code
    P
    arallax lcd docs, Parallax Serial LCD Docs v3.0

    R
    an the new code and got this,

    Line 0 = 00234.55?46 a 51
    Line 1 = 00234.55?47 a 51

    Seconds count up and V changes to A when gps fix, ? = strange character.
    None of the other data changes with position change.

    Thanks again




  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-10-23 11:32
    Made changes to SEROUT line, but here's the whole bit:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    
    status  VAR Byte
    secs_10 VAR Byte
    secs_01 VAR Byte
    lat     VAR Byte (7)
    lon     VAR Byte (9)
    
    ' -----[ Constants ]------------------
    LcdBLon CON 17 ' backlight on
    
    'Baud rates (non-inverted):
    n4800 CON 188
    n19200 CON 32
    
    '--------------lcd start up-----------
    SEROUT 0, n19200, [22, 12, $19, $00] 'initalize lcd
    SEROUT 0, n19200, [LcdBLon]          'lcd bklt on
    
    ' $GPRMC example
    ' $GPRMC,161229.487,A,3723.2475,N,12158.3416,W,0.13,309.62,120598, ,*10
    '            xx     x xxxxxxx     xxxxxxxxx
    
    Main:
    SERIN 15, n4800, [WAIT("RMC,"),SKIP 4,STR secs_10\1,STR secs_01\1,
    SKIP 5,STR status\1,SKIP 1,STR lat\7,SKIP 5,STR lon\9]
    
    ' print it
    SEROUT 0, n19200, [$0C]
    PAUSE 5
    SEROUT 0,n19200 [STR secs_10\1,STR secs_01\1," ",STR status\1,
    " ",STR lat\7,$0D,STR lon\9]
    
    ' $02 = home the cursor, non-destructive
    ' $0A = cursor to next line, same column
    ' $0D = carriage return
    ' $0C = Form Feed, Clear screen and Home cursor
    
    GOTO Main
    

    SEROUT 0, n19200, [$0C,STR secs_10\1,STR secs_01\1," ",STR status\1," ",STR lat\7,$0D,STR lon\9]

    $0C - erase screen and home cursor, pause 5msec per docs
    str secs_10/1, str secs_01\1 - prints seconds
    print a space
    str status\1 - print status char
    print a space
    str lat\7 - print ddmm.mmm of latitude
    $0D - go to next line and full left
    str lon\9 - print dddmm.mmm of longitude
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-10-23 11:40
    Just noticed...
    The GPS kickstart that you've posted has:
    SEROUT 0, n19200, [22, 12, $19, $00] 'initalize lcd

    I note that it too uses a "12" ($0C), but it is not followed by a 5msec pause that the documentation calls out as necessary
    (See its Page 8 of 11), eyebrows raised
Sign In or Register to comment.