Skip to content

Commit 378743d

Browse files
committed
update for latest RTC implementation, tested with i2c GPS
1 parent 07d48aa commit 378743d

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

examples/gps_time_source.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@
99
import adafruit_gps
1010

1111
uart = busio.UART(board.TX, board.RX, baudrate=9600, timeout=10)
12+
#i2c = busio.I2C(board.SCL, board.SDA)
1213

1314
gps = adafruit_gps.GPS(uart, debug=False)
15+
#gps = adafruit_gps.GPS_I2C(i2c, debug=False) # Use I2C interface
16+
1417
gps.send_command(b'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
1518
gps.send_command(b'PMTK220,1000')
1619

1720
print("Set GPS as time source")
1821
rtc.set_time_source(gps)
22+
the_rtc = rtc.RTC()
1923

2024
last_print = time.monotonic()
2125
while True:
@@ -25,6 +29,9 @@
2529
current = time.monotonic()
2630
if current - last_print >= 1.0:
2731
last_print = current
32+
if not gps.timestamp_utc:
33+
print("No time data from GPS yet")
34+
continue
2835
# Time & date from GPS informations
2936
print('Fix timestamp: {:02}/{:02}/{} {:02}:{:02}:{:02}'.format(
3037
gps.timestamp_utc.tm_mon, # Grab parts of the time from the
@@ -36,19 +43,21 @@
3643

3744
#Time & date from internal RTC
3845
print('RTC timestamp: {:02}/{:02}/{} {:02}:{:02}:{:02}'.format(
39-
rtc.RTC.datetime.tm_mon,
40-
rtc.RTC.datetime.tm_mday,
41-
rtc.RTC.datetime.tm_year,
42-
rtc.RTC.datetime.tm_hour,
43-
rtc.RTC.datetime.tm_min,
44-
rtc.RTC.datetime.tm_sec))
46+
the_rtc.datetime.tm_mon,
47+
the_rtc.datetime.tm_mday,
48+
the_rtc.datetime.tm_year,
49+
the_rtc.datetime.tm_hour,
50+
the_rtc.datetime.tm_min,
51+
the_rtc.datetime.tm_sec))
4552

4653
#Time & date from time.localtime() function
4754
local_time = time.localtime()
55+
4856
print("Local time: {:02}/{:02}/{} {:02}:{:02}:{:02}".format(
4957
local_time.tm_mon,
5058
local_time.tm_mday,
5159
local_time.tm_year,
5260
local_time.tm_hour,
5361
local_time.tm_min,
5462
local_time.tm_sec))
63+

0 commit comments

Comments
 (0)