|
1 |
| -import busio, board, time, rtc |
| 1 | +# Simple script using GPS timestamps as RTC time source |
| 2 | +# The GPS timestamps are available without a fix and keep the track of |
| 3 | +# time while there is powersource (ie coin cell battery) |
| 4 | + |
| 5 | +import time |
| 6 | +import board |
| 7 | +import rtc |
| 8 | +import busio |
2 | 9 | import adafruit_gps
|
3 | 10 |
|
4 |
| -uart = busio.UART(board.TX, board.RX, baudrate = 9600, timeout=3000) |
| 11 | +uart = busio.UART(board.TX, board.RX, baudrate=9600, timeout=3000) |
5 | 12 |
|
6 | 13 | gps = adafruit_gps.GPS(uart, debug=False)
|
7 | 14 | gps.send_command(b'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
|
|
18 | 25 | current = time.monotonic()
|
19 | 26 | if current - last_print >= 1.0:
|
20 | 27 | last_print = current
|
| 28 | + # Time & date from GPS informations |
21 | 29 | print('Fix timestamp: {:02}/{:02}/{} {:02}:{:02}:{:02}'.format(
|
22 | 30 | gps.timestamp_utc.tm_mon, # Grab parts of the time from the
|
23 | 31 | gps.timestamp_utc.tm_mday, # struct_time object that holds
|
24 | 32 | gps.timestamp_utc.tm_year, # the fix time. Note you might
|
25 | 33 | gps.timestamp_utc.tm_hour, # not get all data like year, day,
|
26 | 34 | gps.timestamp_utc.tm_min, # month!
|
27 | 35 | gps.timestamp_utc.tm_sec))
|
| 36 | + |
| 37 | + #Time & date from internal RTC |
28 | 38 | print('RTC timestamp: {:02}/{:02}/{} {:02}:{:02}:{:02}'.format(
|
29 | 39 | rtc.RTC.datetime.tm_mon,
|
30 | 40 | rtc.RTC.datetime.tm_mday,
|
31 | 41 | rtc.RTC.datetime.tm_year,
|
32 | 42 | rtc.RTC.datetime.tm_hour,
|
33 | 43 | rtc.RTC.datetime.tm_min,
|
34 | 44 | rtc.RTC.datetime.tm_sec))
|
| 45 | + |
| 46 | + #Time & date from time.localtime() function |
35 | 47 | local_time = time.localtime()
|
36 | 48 | print("Local time: {:02}/{:02}/{} {:02}:{:02}:{:02}".format(
|
37 | 49 | local_time.tm_mon,
|
|
0 commit comments