Ticker

6/recent/ticker-posts

Header Ads Widget

How to use internal RTC of ESP32 without using NTP

Hello Guys, In this blog I will guide you to use the internal RTC of ESP32. Now no need to rely on external RTC chips which not only increases the size of PCB, It also increases the cost of the BOM. By using this technique you can easily implement your RTC-based application without using external RTC or any NTP server.

The best part of this project is that you just need an ESP32 board and one USB cable to program it. This ESP32 RTC can work even offline. 

This guide is based on the Arduino framework using ESP32 Arduino core. To use the internal RTC functionality of ESp32, You have to install ESP32Time Library for Arduino.

You can do it by visiting Sketch >> Include Library >> Manage Libraries section.


Now search for ESP32Time and install the below library by fbiego by clicking on the install button. It will take a few seconds to install.


Source Code :

This is an example of how to use the ESP32Time library to set and retrieve the time on an ESP32 microcontroller. The first line of the setup function sets the time to January 17th, 2021 at 15:24:30, and there are several examples of how to retrieve the time and date in various formats. The code also includes commented out examples of how to set the time using NTP and how to retrieve the time as a struct tm. The code also has an option to set a time offset to be used. In the loop function, the time is printed to the serial monitor every second with a specified format.

OUTPUT : 

Once you complete above steps, you can see output as below.

Post a Comment

2 Comments

  1. The internal RTC resets every time the ESP32 is power on, so it has to be set every time. Your code will set the same time, which will become increasingly wrong. You need either an external RTC or a quick call to NTP to get the current time..

    ReplyDelete
    Replies
    1. Hi @slugsie, It is basically a real-time counter instead of clock.

      Delete