Shop OBEX P1 Docs P2 Docs Learn Events
Using GPS module to update an RTC module every once in a while — Parallax Forums

Using GPS module to update an RTC module every once in a while

MarcusGMarcusG Posts: 6
edited 2008-03-24 16:32 in Propeller 1
I've found that sparkfun's RTC modules drift a bit too much, it looses over an hour a week. So my plan is to have a gps module that is woken up once a day or something and set the RTC off of it. I happened to have a EB85a around so I'm using that. Using Perry's GPS_IO_mini.spin I am able to read the NMEA output and print it to an LCD just fine. The problem is that I need to be able to pull the hours, minutes and seconds out on their own so I can set the RTC module's time with them. I can't figure out what the actual format of "GPGGAa[noparse][[/noparse]0]" is or how to parse out the three character groups I need (first and second, third and fourth, fifth and sixth). I know it's not a string because printing "strsize (variable that is set to GPGGAa[noparse][[/noparse]0])" to the LCD puts random ASCII to the screen instead of a valid number; a blank square followed by a lowercase "h" then a "(".

Any help would be greatly appreciated.

Thanks much,
-Marcus

Comments

  • PerryPerry Posts: 253
    edited 2008-03-21 01:47
    For this type of application you might be better off to use the "smart GPS driver" , it takes requests rather than , as my driver does continously copying things down( it's in the obex )

    Perry
  • pgbpsupgbpsu Posts: 460
    edited 2008-03-21 01:54
    Marcus-

    You may also want to check out this post from earlier this week (or last):

    http://forums.parallax.com/showthread.php?p=715452

    I've never worked with an LCD before so I may be way off on this, but it sounds like you are printing ASCII values to the screen rather than numbers. If the LCD object you're using requires a conversion from ascii to number before printing to the display that may also be causing your problem.

    p

    I mis-read your post. It sounds like you are successfully writing to the LCD but are unable to get usable values for your RTC. That does sound like a int vs string problem. The RTC wants numbers. I think all this is covered in the post above.

    Best of luck.

    Post Edited (pgbpsu) : 3/21/2008 1:59:17 AM GMT
  • Chuck RiceChuck Rice Posts: 210
    edited 2008-03-21 08:31
    .

    Here ar some of the date and time changes I made to Perry's object. Sorry, I have not updated the documentation comments yet, or generalized the time zone calculations. It requires the "Calendar.spin" object.

    .

    [noparse][[/noparse]code]

    pub timehh | hh

    hh := to_hex(byte[noparse]/noparse]GP_GGA_a[noparse][[/noparse] 0[noparse][[/noparse] 0 ]) *10 'uses existing hex lookup as a decimal lookup
    hh += to_hex(byte[noparse]/noparse]GP_GGA_a[noparse][[/noparse] 0[noparse][[/noparse] 1 ])
    return hh

    pub timemm | mm
    mm := to_hex(byte[noparse]/noparse]GP_GGA_a[noparse][[/noparse] 0[noparse][[/noparse] 2 ]) *10 'uses existing hex lookup as a decimal lookup
    mm += to_hex(byte[noparse]/noparse]GP_GGA_a[noparse][[/noparse] 0[noparse][[/noparse] 3 ])
    return mm

    pub timess | ss
    ss := to_hex(byte[noparse]/noparse]GP_GGA_a[noparse][[/noparse] 0[noparse][[/noparse] 4 ]) *10 'uses existing hex lookup as a decimal lookup
    ss += to_hex(byte[noparse]/noparse]GP_GGA_a[noparse][[/noparse] 0[noparse][[/noparse] 5 ])
    return ss



    pub localtime(dateStr,timeStr) | hh,mm,ss, month,day,yyyy

    hh := timehh
    mm := timemm
    ss := timess

    month := dateMonth
    day := dateDay
    yyyy := dateYear

    Cal.ConvertUTCtoLocaltime( -6, yyyy, month, day, hh, mm, ss, true, dateStr, timeStr)


    pub timeHHMMSS

    '' UTC time of fix HHMMSS

    return GP_GGA_a[noparse][[/noparse] 0 ]

    pub dateDay | dd
    dd := to_hex(byte[noparse]/noparse]GP_RMC_a[noparse][[/noparse] 8[noparse][[/noparse] 0 ]) *10 'uses existing hex lookup as a decimal lookup
    dd += to_hex(byte[noparse]/noparse]GP_RMC_a[noparse][[/noparse] 8[noparse][[/noparse] 1 ])
    return dd

    pub dateMonth | mm
    mm := to_hex(byte[noparse]/noparse]GP_RMC_a[noparse][[/noparse] 8[noparse][[/noparse] 2 ]) *10 'uses existing hex lookup as a decimal lookup
    mm += to_hex(byte[noparse]/noparse]GP_RMC_a[noparse][[/noparse] 8[noparse][[/noparse] 3 ])
    return mm

    pub dateYear | yy
    yy := to_hex(byte[noparse]/noparse]GP_RMC_a[noparse][[/noparse] 8[noparse][[/noparse] 4 ]) *10 'uses existing hex lookup as a decimal lookup
    yy += to_hex(byte[noparse]/noparse]GP_RMC_a[noparse][[/noparse] 8[noparse][[/noparse] 5 ])
    return yy + 2000

    pub dateDDMMYY

    '' DDMMYY

    return GP_RMC_a[noparse][[/noparse] 8 ]
    /code]

    Post Edited (Chuck Rice) : 3/21/2008 8:46:01 AM GMT
  • Paul_HPaul_H Posts: 85
    edited 2008-03-21 20:48
    Marcus,

    I've been reusing this AtoI PUB for converting ASCII string value to a number. the author was MK Borri (another great source forGPS code) Sorry if that’s not the correct attribution!

    Pub GetTimeInUnits
      HH := atoi(gps.time,2)                            ' converting the first 2 bytes to #. the 2 is the number of chars read in from left to right.
      MM := atoi(gps.time,4) - atoi(gps.time,2)*100     ' HHMM - HH00
      SS := atoi(gps.time,6) - atoi(gps.time,4)*100     ' HHMMSS - HHMM00
    
    
    


    where the conversion occurs:
    PUB atoi( pptr,c)| ptrr                                 ' convert c characters into number
      result := sign := 0
      if byte[noparse][[/noparse]pptr] == "-"
          sign++
          pptr++
      c--    
      repeat ptrr from 0 to c
        if byte[noparse][[/noparse]pptr+ptrr] == 0                             ' stop if null
             quit
             
        if byte[noparse][[/noparse]pptr+ptrr] == "."                           ' stop if decimal point
             quit
        else     
           result := result * 10 + (byte[noparse][[/noparse]pptr+ptrr] - "0")
      if sign == 1
        result := -result
    
    
    


    pptr is the string address of the GPS data
    C = is the number to characters to convert.

    Sure, I call the routine a bunch of times, but its still simple!

    Let us know if this works for you.

    Paul

    Post Edited (Paul H) : 3/22/2008 3:09:50 AM GMT
  • MarcusGMarcusG Posts: 6
    edited 2008-03-24 16:32
    Thanks guys for all the help, works perfectly. Sorry pgbpsu, I had actually skimmed over that post a week ago, but I hadn’t run into this problem yet and didn’t realize the relevance. By reminding me of it I think you preemptively guided me through my next step [noparse]:D[/noparse]

    Thanks again
Sign In or Register to comment.