#********************************************************************************************************************************************************* # Title : AtSAMD51 Internal Real Time Clock tester * # * # Author : Gert van Biljon * # * # EMail : gertvb@gmail.com * # * #********************************************************************************************************************************************************* #********************************************************************************************************************************************************* # What am I : Small program to test: * # 1. Setting the time on the internal real time clock of the AtSAMD51 as found on the ADAFruit Feather M4 * # 2. Checking the time in the RTC after pressing RESET on the Feather M4 * # * # Why : After updating CircuitPython from 5.3.1 to 6.2.0, I've found that upon pressing the RESET button the values in the internal RTC are all now * # discarded or rather set to 2000/1/1 . . * # * # Background : I am using a Feather M4 with a LiPoly battery as controller for the borehole pumps supplying drinking water to our house and farm. * # * # With the luxury of the Flash storage on the Feather M4, I log the times when the pumps are started and stopped, grabbing the time from * # the internal RTC on the AtSAMD51 * # * # What is VERY useful on CircuitPython 5.3.1 is that the internal RTC doesn't lose its time, even when the reset button on the Feather is * # pressed! * # * # This means that you only have to set the time ONCE with : * # my_real_time_clock.datetime = time.struct_time((2021, 03, 16, 07, 43, 2, 0, -1, -1)) * # and thereafter the Feather keeps the time as long as the LiPoly is connected and full, and the above code can be commented out * # * # Hardware : ADAFruit Feather M4 Express, (Atmel AtSAMD51 ARM M4) * # LiPoly battery * #********************************************************************************************************************************************************* #********************************************************************************************************************************************************* # History : 2021/04/08 : Updated CircuitPython from 5.3.1 to 6.2.0 and found that the time values stored in the RTC are now discarded when pressing * # RESET * # Created this as sample for filing the issue to GitHub * #********************************************************************************************************************************************************* #********************************************************************************************************************************************************* # $Author:: Gert_v_B $ * # $Date:: 2021-04-08 09:23:19 +0200 (Thu, 08 Apr 2021) $ * # $Id:: code.py 1395 2021-04-08 07:23:19Z Gert_v_B $ * # $Header:: https://techexplorer/svn/SVN_Repository/python/circuitpython_rtc_persistency_test/code.py 1395 2021-04-08 07:23:19Z Gert_v_B $ * #********************************************************************************************************************************************************* import rtc import time import supervisor my_real_time_clock = rtc.RTC() #Uses Internal ADC on AtSAMD51 #To set the time one has to run this script with the following line uncommented. #With the Lipoly battery connected to the Feather, the internal RTC keeps correct time, even when pressing the reset button #This should only be needed to run once in the lifetime of the project #my_real_time_clock.datetime = time.struct_time((2021, 04, 08, 08, 54, 05, 0, -1, -1)) while True: current_time = my_real_time_clock.datetime my_datestring = "{:2d}".format(current_time.tm_year) + "/{:02d}".format(current_time.tm_mon) + "/{:02d}".format(current_time.tm_mday) my_timestring = "{:02d}".format(current_time.tm_hour) + ":{:02d}".format(current_time.tm_min) + ":{:02d}".format(current_time.tm_sec) if supervisor.runtime.serial_connected: print ("Time : ", my_datestring, " ", my_timestring, "\n", sep = "") time.sleep(1) #while True: