Skip to content

How to work with RTC correctly? #37

@kropochev

Description

@kropochev

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions