Gene N replied to the topic 'RTC with PI PICO and DS3231' in the forum. 1 year ago

More project work on the dongle, adding GPS module and supported API

Parts cost:
PI PICO: < $8
RTC w/flash chip: $5, DS3231 with temp compensated xtal
GPS module: $9 (GY-NEO6MV2)
8X dupont wires + case + usb cable

Code supports mix and match:
PICO + RTC
PICO + GPS
PICO + RTC + GPS

Note: Without RTC + scratchpad, GPS data always streams

API:
:c Set the RTC time in unixtime Zulu
:c1676732144
Code to read from system and write to RTC
cmd = "date +%s"
print("System current unix time")
cmd1 = "\"{}\"".format(os.system(cmd))
unixtime = "{}".format(os.popen(cmd).read())
settime = unicode(":c"+unixtime[:-1])
self.ser_io.write(settime)

:C Read the RTC, response format in Zulu time
2023/02/18 14:48:34
Suitable for use in unix date set
self.ser_io.write(unicode(":C"))
self_id = self.ser_io.readline()
print("RTC current time")
print(self_id)
cmd = "date"
print("Current system time")
os.system(cmd)
cmd = "date -s \"{}Z\"".format(self_id)
print("Setting time")
os.system(cmd)

:S Status of GPS lock
Response
1 = locked
0 = not locked

:G Stream GPS data, state remembered across restarts if scratchpad available
Direct input to GPSD

:g Stop stream of GPS data, state remembered across restarts if scratchpad available

:D Read the GPS date and time, response format
2023/02/18 14:52:41
Suitable for use in unix date set, see :C command above

:L Read the GPS Longitude, response format
-77:01:02
Where negative = West

:l Read the GPS Latitude, response format
+38:01:02
Where negative = South

:Q Read GPS Lat and Long, response format
+38.123456,-77.123456

:d Read GPS time, response format
15:07:15

:T Read temperature of DS3231, response format
18.00




=========================
Scratchpad flash supported if contained on RTC module

:WXXXX,YYY Write scratchpad flash
Where XXXX = address to write to, YYY = data to write
XXXX and YYY in decimal
Max value of XXXX based on which flash on the RTC module
All digits in XXXX and YYY required

:RXXXX Read scratchpad flash
Where XXXX = address to read
XXXX in decimal
Max value of XXXX based on which flash on the RTC module
All digits in XXXX required

NOTE: address 4095 is used to store state of :Q/:q GPS streaming enable

Read More...