logo elektroda
logo elektroda
X
logo elektroda

RTC in ESP and MicroPython - clock inaccuracy, speeds up by tens of seconds

opaaa 234 7
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 21201035
    opaaa
    Level 4  
    Hi. Have any of you guys used the RTC on ESP chips? I've recently played around a bit with writing code in micropython for this chip and from my observations it appears that it is very inaccurate the clock can speed up by tens of seconds in 10 minutes of operation. If you have any experience with RTC on these chips then please let me know your findings. I also take into account that I wrote something wrong in the code.
  • ADVERTISEMENT
  • #2 21201054
    k45i89o98j66
    Level 39  
    And what RTC do you have? Where did you buy it?
  • ADVERTISEMENT
  • #3 21201118
    khoam
    Level 42  
    opaaa wrote:
    Have any of you used RTC in ESP circuits? I've recently played around a bit with writing code in micropython for this chip and from my observations it comes out to be very inaccurate the clock can speed up by tens of seconds in 10 minutes of operation.
    .
    I am not surprised. The RTC in the ESP is simply not suitable for (reasonably) accurate timekeeping until it is configured to use from an external 32768 kHz quartz oscillator.
  • #4 21201339
    opaaa
    Level 4  
    >>21201054 RTC its internal ESP. I have no way of connecting the 32.768kHz quartz to those pins on the board. Unless I am mistaken.
  • #5 21201666
    khoam
    Level 42  
    How you connect an external 32.768 kHz oscillator to the ESP32 is explained in the documentation " ESP Hardware Design Guidelines ":
    https://docs.espressif.com/projects/esp-hardw...atic-checklist.html#rtc-clock-source-optional

    RTC in ESP and MicroPython - clock inaccuracy, speeds up by tens of seconds .

    The problem, however, is also of a software nature. It requires changing the parameter CONFIG_ESP32_RTC_CLK_SRC for ESP-IDF and recompiling it. This is "somewhat" difficult with the Arduino SDK or MicroPython (the ESP-IDF libraries are already in binary), so it might be better to consider using e.g. the DS3231.
  • ADVERTISEMENT
  • #6 21201813
    opaaa
    Level 4  
    As it is in the documentation I will not be able to connect the quartz because I have such a circuit https://i0.wp.com/randomnerdtutorials.com/wp-...o-pin.png?quality=100&strip=all&ssl=1
    Unless there is something I don't know about.
    How accurate are the DS3231 chips? When I was playing around a bit with the DS1307 I can't remember exactly anymore but I think it wasn't very accurate.

    I pulled the DS1307 chip the one I used to try to do something with on an atmega8. Either I am doing something wrong or this chip is mega not accurate. After 5 minutes of operation it sped up by 8 seconds :) . Poor.
  • ADVERTISEMENT
  • #7 21429984
    Mocny Amper
    Level 10  
    I have also come across this problem, in a device that sleeps 24 hours, does a short activity, and sleeps 24 hours again. In addition, it has no internet access, and cannot download time.
    In my case, during light sleep, there was an acceleration of about 11 minutes per day. Not wanting to bury a soldering iron in a ready-made development board, I simply made a software adjustment to the sleep time. This is a stopgap admittedly, as a different module may have a different spread of RTC oscillator parameters, but it reduced the inaccuracy to 1 minute per day - not a bad result.
  • #8 21430003
    tos18
    Level 42  
    opaaa wrote:
    Unless there is something I don't know about.
    .
    A colleague has an ESP8266 and this does not have a hardware RTC.

Topic summary

The discussion addresses the inaccuracy of the internal RTC on ESP chips when used with MicroPython, with observed time drift of tens of seconds over 10 minutes. The internal RTC lacks precision unless configured to use an external 32.768 kHz quartz oscillator, which requires hardware modifications and recompiling ESP-IDF with adjusted parameters (CONFIG_ESP32_RTC_CLK_SRC). Many ESP development boards, such as the WeMos D1 Mini based on ESP8266/ESP32, do not provide accessible pins for connecting an external crystal. As a practical alternative, external RTC modules like the DS3231 are recommended for accurate timekeeping, as the DS1307 has been reported to exhibit significant drift (e.g., 8 seconds in 5 minutes). Some users mitigate RTC drift in software by calibrating sleep durations, reducing error to about 1 minute per day. It is also noted that the ESP8266 lacks a hardware RTC altogether.
Summary generated by the language model.
ADVERTISEMENT