|
9 | 9 | import adafruit_gps
|
10 | 10 |
|
11 | 11 | uart = busio.UART(board.TX, board.RX, baudrate=9600, timeout=10)
|
| 12 | +#i2c = busio.I2C(board.SCL, board.SDA) |
12 | 13 |
|
13 | 14 | gps = adafruit_gps.GPS(uart, debug=False)
|
| 15 | +#gps = adafruit_gps.GPS_I2C(i2c, debug=False) # Use I2C interface |
| 16 | + |
14 | 17 | gps.send_command(b'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
|
15 | 18 | gps.send_command(b'PMTK220,1000')
|
16 | 19 |
|
17 | 20 | print("Set GPS as time source")
|
18 | 21 | rtc.set_time_source(gps)
|
| 22 | +the_rtc = rtc.RTC() |
19 | 23 |
|
20 | 24 | last_print = time.monotonic()
|
21 | 25 | while True:
|
|
25 | 29 | current = time.monotonic()
|
26 | 30 | if current - last_print >= 1.0:
|
27 | 31 | last_print = current
|
| 32 | + if not gps.timestamp_utc: |
| 33 | + print("No time data from GPS yet") |
| 34 | + continue |
28 | 35 | # Time & date from GPS informations
|
29 | 36 | print('Fix timestamp: {:02}/{:02}/{} {:02}:{:02}:{:02}'.format(
|
30 | 37 | gps.timestamp_utc.tm_mon, # Grab parts of the time from the
|
|
36 | 43 |
|
37 | 44 | #Time & date from internal RTC
|
38 | 45 | 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)) |
45 | 52 |
|
46 | 53 | #Time & date from time.localtime() function
|
47 | 54 | local_time = time.localtime()
|
| 55 | + |
48 | 56 | print("Local time: {:02}/{:02}/{} {:02}:{:02}:{:02}".format(
|
49 | 57 | local_time.tm_mon,
|
50 | 58 | local_time.tm_mday,
|
51 | 59 | local_time.tm_year,
|
52 | 60 | local_time.tm_hour,
|
53 | 61 | local_time.tm_min,
|
54 | 62 | local_time.tm_sec))
|
| 63 | + |
0 commit comments