Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Is the time in the RTC preserved after hard reset w/o power down?

    Scheduled Pinned Locked Moved LoPy
    lopyrtcbattery powered
    6 Posts 4 Posters 4.1k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R Offline
      rolandvs
      last edited by

      It seems that the RTC from the ESP32 "forgets" the time when a reset is issued. Could be worthwhile to mention it in the docs. If true it makes the use of the RTC sort of worthless in situations where you want to keep time with an attached battery without the possibility to use Wi-Fi to NTP your time like with LoPy or SiPy...

      For completeness

      from machine import RTC
      rtc = RTC()
      this_moment = rtc.now()
      # (1970,....)
      rtc.init( (2017,08,23,10,10,0,0,0) )
      # (2017, ....)
      # press reset button, power still on, even battery
      from machine import RTC
      rtc = RTC()
      this_moment = rtc.now()
      # (1970,....)
      

      One tip: put a RTC chip on the deep_sleep, pysense, pytrack, pywhatever... if one would like to use this in the field on a battery... along with a backup battery for clock (and gps)... Possibly the PIC chip that is used for USB among other things can do some time keeping too....

      bmarkusB 1 Reply Last reply Reply Quote 0
      • J Offline
        jmarcelino
        last edited by jmarcelino

        Yes, the RTC on the ESP32, much like almost all micro controllers and computers like the Raspberry Pi loses its time on reset.

        There are ways around this, for example on the LoPy and SiPy you can have your app request the current time as a downlink from the network (won't be as accurate as NTP but good enough for many purposes)

        You can also approximate the time by storing the current into flash before doing a reset or deep sleep and then adding the calculated elapsed time (considering that the Py boards once programmed generally take roughly the same amount of time to restart)

        Or attach one of the many cheap RTC boards via I2C or SPI.

        But true it would have been nice for Pycom to have it on their shields, it's not a massive extra cost on the BOM.

        1 Reply Last reply Reply Quote 0
        • R Offline
          rolandvs
          last edited by

          Well I'm spoiled with my PYBoard with the STM32 :-). Disappointing though. Now I use my Pytrack to get the time and set the RTC, but then this is lacking backup power for the GPS so no quick fix functionality.

          1 Reply Last reply Reply Quote 0
          • L Offline
            loboris
            last edited by

            ESP32 RTC time is preserved during deepsleep, and you can wake up after defined time, by external pin, by touch event, or by any activity which can be handled by ULP. If 32.768 kHz crystal is used the time is very accurate, even without it it is still usable. Why would you want to reset the ESP32 by reset pin (and expect the time to be preserved) ?

            R 1 Reply Last reply Reply Quote 0
            • R Offline
              rolandvs @loboris
              last edited by

              @loboris

              I would like the RTC to keep running even when a watchdog or reset is necessary and the power (battery) is still on. If the system fails for whatever reason either a watchdog reset or pin-reset should be enough to start again and keep the RTC alive. Deep-sleep is something by choice.

              The ESP32 datasheet and other documents are not very clear in describing what happens. Some bits and pieces: The RTC has a separate power domain (and also supplies the CPU?) (that's good)
              The RTC consists of memory than can be retained, peripherals and ULP processor that can have its own program (also good)
              The watchdog has a RWDT and MWDT. The RWDT resets everything including the RTC. So what is the xxPy using?
              I did not check, but is the xxPy using an external 32kHz crystal "under the hood"?

              1 Reply Last reply Reply Quote 0
              • bmarkusB Offline
                bmarkus @rolandvs
                last edited by

                @rolandvs said in Is the time in the RTC preserved after hard reset w/o power down?:

                If true it makes the use of the RTC sort of worthless in situations where you want to keep time with an attached battery without the possibility to use Wi-Fi to NTP your time like with LoPy or SiPy...

                It doesn't solve the original issue, but you can update time without network connection using GPS receiver, e.g. on the pytrack extension board.

                1 Reply Last reply Reply Quote 0

                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                With your input, this post could be even better 💗

                Register Login
                • 1 / 1
                • First post
                  Last post

                Pycom on Twitter

                Pycom