Is there a quick way to set RTC, maybe from REPL? (8523)

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
electromechpro
 
Posts: 23
Joined: Wed Jan 25, 2023 3:56 pm

Is there a quick way to set RTC, maybe from REPL? (8523)

Post by electromechpro »

Hi, all,
Time change time again. I was wondering if there is a quick and easy way to set the RTC? (mine's an 8523 on a datalogger shield with a Metro ESP32-S2 running Circuitpython 8.x). It would seem the REPL is a powerful and versatile tool and could do so, but I am having trouble finding anything on it.
I new to Circuitpython, and am working on migrating some of our UNO based instruments onto Metro platforms. It is a pretty steep learning curve from Arcuino/C++ to Circuitpython, but I am making headway, and the ecosystem is still growing. All our instruments are standalone, not connected to any network.
There has to be a better way than unplugging the RTC/shield from the Metro, putting it on an UNO with an RTC set sketch on it, then reinstalling on the Metro!
Thank you for help with my previous questions.

User avatar
dastels
 
Posts: 15658
Joined: Tue Oct 20, 2015 3:22 pm

Re: Is there a quick way to set RTC, maybe from REPL? (8523)

Post by dastels »

You should be able to do it in the REPL.

Set the datetime property, from the example:

Code: Select all

import time
import board
import adafruit_pcf8523

rtc = adafruit_pcf8523.PCF8523(board.I2C())
t = time.struct_time((2017, 10, 29, 10, 31, 0, 0, -1, -1))
# you must set year, mon, date, hour, min, sec and weekday
# yearday is not supported, isdst can be set but we don't do anything with it at this time
rtc.datetime = t
Dave

User avatar
electromechpro
 
Posts: 23
Joined: Wed Jan 25, 2023 3:56 pm

Re: Is there a quick way to set RTC, maybe from REPL? (8523)

Post by electromechpro »

Thank you for the reply. I had been setting the RTC in Arduino with the following code
//RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
(uncommenting, downloading, recommenting, download), and was looking for a similar way in Circuitpython. I had tried the more lengthy code from the example but messed something up. I will try the more concise example you gave me in the REPL (I had also not imported 8523 library in the REPL).

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”