Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Seting up RTC based on GPS data

    Scheduled Pinned Locked Moved MicroPython
    gpspytrackrtc
    1 Posts 1 Posters 643 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T Offline
      tttadam
      last edited by

      Hello,
      I want to connect to the GPS, and wait until the find the correct satellites to get the time and date.
      My code for that is look like this. This is sometimes working sometimes not...
      Issues:
      my_gps.date is always (0,0,0) inside the while loop but however sometimes the rtc set correctly.
      I could use my_gps.timestamp for conditions for the while loop, but sometimes it's got some
      wrong values beside (0,0,0)
      Other cases it's works perfectly. (Usually after few run..(Is the rtc still working after the code is finished?)
      Can you gave me some tip how can I improve it? What is the best practice for that?
      (I am using a lopy4 with a pytrack)
      Thank you, :)

      #Setting up the gps:
      py = Pytrack()
      my_gps = MicropyGPS(local_offset=1,location_formatting='dd')
      L76micropyGPS = L76micropyGPS(my_gps, py)
      gpsThread = L76micropyGPS.startGPSThread()
      print("Waiting for gps signal")
      counter = 0
      while (my_gps.date == (0, 0, 0) and counter < 10):
          print("Waiting for gps signal: "+str(counter)+" "+str(my_gps.date)+" "+str(my_gps.timestamp))
          counter +=1
          time.sleep(1)
      time.sleep(2)
      print("Date: "+str(my_gps.date))
      print("GPS signal is found")
      print("Time: "+str(my_gps.timestamp))
      time.sleep(2)
      print(my_gps.date[0])
      print(my_gps.date[1])
      print(my_gps.date[2])
      
      
      print("Setting up the RTC")
      rtc = machine.RTC()
      print("RTC before init: {}".format(rtc.now()))
      dateYear = int(str(20) + str(my_gps.date[2]))
      rtc.init((dateYear, my_gps.date[1], my_gps.date[0], my_gps.timestamp[0], my_gps.timestamp[1], int(my_gps.timestamp[2]), 0, 0)) #seting up the rtc 
      print("RTC is set : {}".format(rtc.now()))
      
      1 Reply Last reply Reply Quote 0

      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

      With your input, this post could be even better 💗

      Register Login
      • 1 / 1
      • First post
        Last post

      Pycom on Twitter

      Pycom