🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Time - RTC vs ESP32 Clocks

    Scheduled Pinned Locked Moved Arduino
    1 Posts 1 Posters 1.3k Views
    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.
    • TomKattT Offline
      TomKatt
      last edited by TomKatt

      Want to better understand if there is a difference between controllers with an RTC and 'software' time of an ESP32. Perhaps I am overthinking this...

      I have a DinMeter based on a StampS3 that also includes a BM8563 RTC chip. Looking through example code for NTP sync time, I see the following:

          auto dt = DinMeter.Rtc.getDateTime();
          Serial.printf("RTC   UTC  :%04d/%02d/%02d (%s)  %02d:%02d:%02d\r\n",
                        dt.date.year, dt.date.month, dt.date.date,
                        wd[dt.date.weekDay], dt.time.hours, dt.time.minutes,
                        dt.time.seconds);
          DinMeter.Display.setCursor(0, 0);
          DinMeter.Display.printf("RTC   UTC  :%04d/%02d/%02d (%s)  %02d:%02d:%02d",
                              dt.date.year, dt.date.month, dt.date.date,
                              wd[dt.date.weekDay], dt.time.hours, dt.time.minutes,
                              dt.time.seconds);
      
          /// ESP32 internal timer///
          auto t = time(nullptr);
          {
              auto tm = gmtime(&t);  // for UTC.
              Serial.printf("ESP32 UTC  :%04d/%02d/%02d (%s)  %02d:%02d:%02d\r\n",
                            tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
                            wd[tm->tm_wday], tm->tm_hour, tm->tm_min, tm->tm_sec);
              DinMeter.Display.setCursor(0, 20);
              DinMeter.Display.printf("ESP32 UTC  :%04d/%02d/%02d (%s)  %02d:%02d:%02d",
                                  tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
                                  wd[tm->tm_wday], tm->tm_hour, tm->tm_min,
                                  tm->tm_sec);
          }
      

      It looks to me like the first section is getting the time data from the RTC. The comment 'ESP32 Internal Timer' makes me think that perhaps the 2nd section is getting time data from a software clock routine. Is that a correct understanding? Could the software time drift from the RTC time?

      I'm not sure how the M5Stack software handles this - it could be that the 'software time' is always sourced from the RTC for controllers that have that option. My project requires time accuracy, so I want to ensure that I'm using the RTC as opposed to any 'software' time driven by the cpu clock.

      Thoughts?

      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
      • First post
        Last post