Help GPS read with serin


Closed Thread
Results 1 to 8 of 8
  1. #1
    leinske's Avatar
    leinske Guest

    Wink Help GPS read with serin

    Hello evrybody, I am working on a project to read som GPS info from PC serial port and displaying the result on an LCD display.
    Iwant to read the speed and course to display it on an LCD display the GPS output looks like
    $GPRMC,192144.62,A,5041.6058,N,00412.6124,E,0.45,3 57.74,081205,,*0B

    the part I want to read is 0.45 (speed) and 357.74 (course)

    I think it will be possible with the command SERIN and I want to use a PIC16F628 the baut rate must be 4800
    Can anywan help me i think that it can possible with the skip n characters ????
    thanks for helping me

  2. #2
    Join Date
    Sep 2003
    Location
    Vermont
    Posts
    373


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by leinske
    Hello evrybody, I am working on a project to read som GPS info from PC serial port and displaying the result on an LCD display.
    Iwant to read the speed and course to display it on an LCD display the GPS output looks like
    $GPRMC,192144.62,A,5041.6058,N,00412.6124,E,0.45,3 57.74,081205,,*0B

    the part I want to read is 0.45 (speed) and 357.74 (course)

    I think it will be possible with the command SERIN and I want to use a PIC16F628 the baut rate must be 4800
    Can anywan help me i think that it can possible with the skip n characters ????
    thanks for helping me
    First of all, use a crystal or resonator. If you don't, you will waste time tweeking the oscillator, and have it malfunction if the temperature changes.
    I'd use the hardware UART first, then serin2 if necessary. Every character needs to be counted. In other words, commas and spaces too. I don't have the PBP book of revelations with me, so I will get back to you, but do a search on GPS and the Basic stamp. I found exactly what you are looking for. If you don't find it,or no one else chimes in, I will post it later. Quite simply,

    'wait' for "$GPMRC" then skip (nn),speed_var, skip(nn), vector_string / 6.

    This is not correct, but the best my feeble mind can create without the book in front of me. The nn's represent the number of places to skip.

    Hope this helps,
    Ron

  3. #3
    G8RPI's Avatar
    G8RPI Guest


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Be careful if just counting characters. Some of the NMEA 0183 data strings have variable lengths. You need to check the specification for your device.
    I'd concurr on using the hardware serial UART and a crystal.

    Robert G8RPI.

  4. #4
    leinske's Avatar
    leinske Guest


    Did you find this post helpful? Yes | No

    Thumbs up I have the solution

    Thanks evrerybody, i made my prototype for GPS reading and it works perfectly i give my code as somebody can use it for similar applications

    Best regards,
    Leinske

    ' Program to display returned value of a GPS on RB1
    ' LCD in 4-BIT mode PIC16F628 controller 4Mhz clock Fuse PWRT BODEN
    '
    ' LCD should be connected as follows:
    ' LCD PIC
    ' DB4 PortA.0
    ' DB5 PortA.1
    ' DB6 PortA.2
    ' DB7 PortA.3
    ' RS PortA.4 (add 4.7K pullup resistor to 5 volts)
    ' E PortB.3
    ' RW Ground
    ' Vdd 5 volts
    ' Vss Ground
    ' Vo 20K potentiometer (or ground)
    ' DB0-3 No connect
    'GPS sentence: $GPRMC,192144.62,A,5041.6058,N,00412.6124,E,0.45,3 57.74,081205,,*0B



    DEFINE OSC 4
    CMCON = 7
    GPSin VAR PORTB.1
    SW VAR PORTB.5 'optional switch for Man Over Board keeps position on EEPROM when switched on
    TRISB.1=1 'define port B1 as input
    TRISB.5=1 'define port B5 as input
    TRISA.0=0
    TRISA.1=0
    TRISA.2=0
    TRISA.3=0
    TRISA.4=0
    TRISB.3=0


    PORTA=0
    PORTB=0

    'Allocate Variables for GPS:
    TimeOut CON 3000
    baudGPS CON 24764 '16572 + 8192 (bit 13)

    hh VAR BYTE 'hours
    mm VAR BYTE 'minutes
    knots VAR WORD 'speed in knots (units)
    knotsten VAR BYTE 'speed in knots (tens)
    course VAR WORD 'heading
    latdeg VAR BYTE 'degrees latitude
    latmin VAR BYTE 'minutes latitude
    NS VAR BYTE 'north or south
    londeg VAR BYTE 'degrees longitude
    lonmin VAR BYTE 'minutes longitude
    EO VAR BYTE 'east or west
    j VAR BYTE 'day
    m VAR BYTE 'month
    a VAR BYTE 'year

    fix VAR WORD 'GPS fix


    LCDOut $FE, 1 'Clear Screen
    LCDOut " POP CORN"
    LCDOut $fe,$c0
    LCDOut " WELCOME ABOARD"
    Pause 2000
    LCDOut $FE, 1 'Clear Screen
    LCDOut " YOUR SKIPPER"
    LCDOut $fe,$c0
    LCDOut " ALAIN DE VOS"
    Pause 2000
    LCDOut $FE, 1 'Clear Screen

    GPS: 'read GPS

    IF SW=1 Then 'switch for man over board
    GoTo mob
    EndIF

    SerIn2 GPSin,baudGPS,Timeout,Nogps,[wait("$GPRMC"),wait(","),DEC2 hh,DEC2 mm,wait(","),fix,wait(","),DEC2 latdeg,DEC2 latmin,wait(","),NS,wait(","),DEC3 londeg,DEC2 lonmin,wait(","),EO,wait(","),knots,wait("."),DEC2 knotsten,wait(","),DEC3 course,wait(","),DEC2 j,DEC2 m,DEC2 a]



    IF fix="V" Then 'if no GPS fix
    GoTo Nofix
    EndIF
    'write last valid into EEPROM
    Write 0,hh
    Write 1,mm
    Write 2,latdeg
    Write 3,latmin
    Write 4,NS
    Write 5,londeg
    Write 6,lonmin
    Write 7,EO
    Write 8,j
    Write 9,m
    Write 10,a

    GoTo LCD

    LCD:




    'normal display if fix ok
    LCDOut $FE, 1 'Clear Screen
    LCDOut "SPEED :",knots,".",DEC2 knotsten," KNT"
    LCDOut $fe,$c0
    LCDOut "HEADING:",DEC3 course," DEG"
    Pause 3000


    LCDOut $FE, 1 'Clear Screen
    LCDOut "LAT:",DEC2 latdeg,",",DEC2 latmin," ",NS
    LCDOut $fe,$c0
    LCDOut "LON:",DEC2 londeg,",",DEC2 lonmin," ",EO
    Pause 3000
    GoTo GPS


    'display if no gps is present
    Nogps:
    Pause 1000
    LCDOut $FE, 1 'Clear Screen
    LCDOut " NO GPS"
    Pause 1000
    GoTo GPS

    'display if no gps fix
    Nofix:
    'read last valid from EEPROM
    Read 0,hh
    Read 1,mm
    Read 2,latdeg
    Read 3,latmin
    Read 4,NS
    Read 5,londeg
    Read 6,lonmin
    Read 7,EO
    Read 8,j
    Read 9,m
    Read 10,a


    Pause 1000
    LCDOut $FE, 1 'Clear Screen
    LCDOut " NO GPS FIX"
    LCDOut $fe,$c0
    LCDOut " LAST VALID"
    Pause 2000
    LCDOut $FE, 1 'Clear Screen
    LCDOut "DATE: ",DEC2 j,"-",DEC2 m,"-",DEC2 a
    LCDOut $fe,$c0
    LCDOut "TIME: ",DEC2 hh,":",DEC2 mm
    Pause 2000
    LCDOut $FE, 1 'Clear Screen
    LCDOut "LAT:",DEC2 latdeg,",",DEC2 latmin," ",NS
    LCDOut $fe,$c0
    LCDOut "LON:",DEC2 londeg,",",DEC2 lonmin," ",EO
    Pause 2000
    GoTo GPS

    mob: 'man over board
    Read 2,latdeg
    Read 3,latmin
    Read 4,NS
    Read 5,londeg
    Read 6,lonmin
    Read 7,EO

    Pause 1000
    LCDOut $FE, 1 'Clear Screen
    LCDOut " MAN OVER BOARD"
    LCDOut $fe,$c0
    LCDOut " POSITION"
    Pause 2000
    LCDOut $FE, 1 'Clear Screen
    LCDOut "LAT:",DEC2 latdeg,",",DEC2 latmin," ",NS
    LCDOut $fe,$c0
    LCDOut "LON:",DEC2 londeg,",",DEC2 lonmin," ",EO
    Pause 2000
    GoTo GPS

  5. #5
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    leinske, I notice 1 thing, I hope the MOB switch is a push button that can only be actuated 1 time or a push button switch with some kind of software flag to disable the EEPROM update after the first write as the actual MOB location will be over written. I would put some kind of flag that you must reset in a different way to maintain the MOB's actual location. Just a thought.......

    Dave Purola,
    N8NTA

  6. #6
    leinske's Avatar
    leinske Guest


    Did you find this post helpful? Yes | No

    Lightbulb MOB switch

    Hi Dave,
    in fact the MOB switch is a 2 positions ON/OFF toggle switch, there is also a pull down resistor on portB.5.

    when MOB occures, the switch is set to ON then the program goes to the mob label, return to GPS label, test if switch is on if wel, loops to mob solong the switch is not set to off.

    The writing instructions are after the switch test routine, so there are no updates of de EEPROM during the MOB action, I think it's the simplest way to do it ;o)

    regards,
    Leinske

  7. #7
    Join Date
    Jul 2007
    Posts
    7


    Did you find this post helpful? Yes | No

    Default lan lat

    Dear LEINSKE
    Thanks for the source code. I just had a problem with SERIN line now its works well

    Actualy I don't need to see on LCD . I catch all relevant fields of $GPRMC and I am sending by SEROUT2 command to PC by serial cable

    In your code I can catch only 4 digits of the lan and lat how can I catch all lan lat as is ?
    I add lanss and latss variables try to catch all strings I am loosing 0 (zero)

    3202.9876 I get 32.02 and 03412.3452 I get 34.12

    Thanks

    Haim Rodrik

  8. #8


    Did you find this post helpful? Yes | No

    Default Please repost this to the GPS section.

    This post should be moved to the GPS thread I feel. It seems a good thread with useful code and it uses a different way of extracting the data fields than my old post in the GPS section.

    Cheers
    Brian

Similar Threads

  1. Cleaning up code
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2009, 07:14
  2. GPS $GPRMC to PIC16F684. Need help with SERIN2
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th November 2009, 09:47
  3. SEROUT WORD variable problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th April 2009, 11:20
  4. Q: using MCLR for Input on 12F683
    By picster in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 31st January 2009, 15:25
  5. Changing declared variables names on the fly
    By jessey in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th December 2006, 06:34

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts