Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to work with RTC correctly? #37

Open
kropochev opened this issue Nov 4, 2024 · 0 comments
Open

How to work with RTC correctly? #37

kropochev opened this issue Nov 4, 2024 · 0 comments

Comments

@kropochev
Copy link

There is M5Stack StickC Plus2 with firmware UIFlow2.0 v.2.1.7.

I load the following code:

import os, sys, io
import M5
from M5 import *
from hardware import *
import time

rtc = None

def setup():
  global rtc
  rtc = RTC()
  rtc.init((2024, 11, 4, 0, 21, 51, 15, 504))
  M5.begin()

def loop():
  global rtc
  M5.update()
  print(time.mktime(time.localtime()))
  print(rtc.datetime())

if __name__ == '__main__':
  try:
    setup()
    while True:
      loop()
  except (Exception, KeyboardInterrupt) as e:
    try:
      from utility import print_error_msg
      print_error_msg(e)
    except ImportError:
      print("please update to latest firmware")

I see the current time and date in the console, then I comment the line

# rtc.init((2024, 11, 4, 0, 21, 51, 15, 504))

and boot again and see the current time in the console.

But if I turn off the board with the button on the left side and then turn it on, the time will reset to:
(2000, 2, 2, 3, 10, 13, 29, 894534)
949468409

Why does this happen? Shouldn't the time be saved when turned off?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant