Seting up RTC based on GPS data

  • 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: 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 ( == (0, 0, 0) and counter < 10):
        print("Waiting for gps signal: "+str(counter)+" "+str(" "+str(my_gps.timestamp))
        counter +=1
    print("Date: "+str(
    print("GPS signal is found")
    print("Time: "+str(my_gps.timestamp))
    print("Setting up the RTC")
    rtc = machine.RTC()
    print("RTC before init: {}".format(
    dateYear = int(str(20) + str([2]))
    rtc.init((dateYear,[1],[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(

Log in to reply

Pycom on Twitter