42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
import busio, board, time, rtc
|
|
import adafruit_gps
|
|
|
|
uart = busio.UART(board.TX, board.RX, baudrate = 9600, timeout=3000)
|
|
|
|
gps = adafruit_gps.GPS(uart, debug=False)
|
|
gps.send_command(b'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
|
|
gps.send_command(b'PMTK220,1000')
|
|
|
|
print("Set GPS as time source")
|
|
rtc.set_time_source(gps)
|
|
|
|
last_print = time.monotonic()
|
|
while True:
|
|
|
|
gps.update()
|
|
# Every second print out current time from GPS, RTC and time.localtime()
|
|
current = time.monotonic()
|
|
if current - last_print >= 1.0:
|
|
last_print = current
|
|
print('Fix timestamp: {:02}/{:02}/{} {:02}:{:02}:{:02}'.format(
|
|
gps.timestamp_utc.tm_mon, # Grab parts of the time from the
|
|
gps.timestamp_utc.tm_mday, # struct_time object that holds
|
|
gps.timestamp_utc.tm_year, # the fix time. Note you might
|
|
gps.timestamp_utc.tm_hour, # not get all data like year, day,
|
|
gps.timestamp_utc.tm_min, # month!
|
|
gps.timestamp_utc.tm_sec))
|
|
print('RTC timestamp: {:02}/{:02}/{} {:02}:{:02}:{:02}'.format(
|
|
rtc.RTC.datetime.tm_mon,
|
|
rtc.RTC.datetime.tm_mday,
|
|
rtc.RTC.datetime.tm_year,
|
|
rtc.RTC.datetime.tm_hour,
|
|
rtc.RTC.datetime.tm_min,
|
|
rtc.RTC.datetime.tm_sec))
|
|
local_time = time.localtime()
|
|
print("Local time: {:02}/{:02}/{} {:02}:{:02}:{:02}".format(
|
|
local_time.tm_mon,
|
|
local_time.tm_mday,
|
|
local_time.tm_year,
|
|
local_time.tm_hour,
|
|
local_time.tm_min,
|
|
local_time.tm_sec))
|