×

INDI Library v2.0.7 is Released (01 Apr 2024)

Bi-monthly release with minor bug fixes and improvements

RTC with PI PICO and DS3231

  • Posts: 276
  • Thank you received: 52
For my travel scope I use a PI 4 in a case with a 7inch DSI display.
Given there is no room in the case for standard methods of plugging module itself into the SDA/SCL lines and given the display uses the lines already another solution was needed for as low a cost as possible.

Seems PI PICO's have become available again for non-scalper prices and DS3231 modules with battery are readily available so a bit of code on the PICO and a few wires to the DS3231 module coupled with some python scripts on the PI to allow plugging the gadget (PICO+DS3231) into PI's USB and both setting the time into the gadget and setting system time from the gadget.

The solution is pretty much universal and can be used on basically any linux or windows or mac machine where there is admin access to modify the system time.

If any interest, I can provide more info, code, wiring, etc.

Gene
1 year 2 months ago #90578

Please Log in or Create an account to join the conversation.

  • Posts: 1309
  • Thank you received: 226

Replied by Andrew on topic RTC with PI PICO and DS3231

I commend you for your ingenuity. But there is a simpler way to go about this.
You can have multiple devices sharing the same I2C pins on the GPIO since they get unique addresses. So it is a relatively simple matter of wiring it up to the Pi using jumper wires soldered to the underside if you can not stack the module in the usual location.
1 year 2 months ago #90579

Please Log in or Create an account to join the conversation.

  • Posts: 276
  • Thank you received: 52

Replied by Gene N on topic RTC with PI PICO and DS3231

Hi Andrew,

For sure soldering in or making dupont splitters would work but a real tight fit in the display case but needed a project and wanted portability across multiple platforms.
That coupled with the price of PI's currently said don't open case, don't solder, don't break or mod what works.

Gene
1 year 2 months ago #90581

Please Log in or Create an account to join the conversation.

  • Posts: 276
  • Thank you received: 52

Replied by Gene N on topic RTC with PI PICO and DS3231

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
1 year 2 months ago #90655

Please Log in or Create an account to join the conversation.

Time to create page: 1.109 seconds