Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

ESP32-Based Digital Clock with TFT Display and RTC Module

Image of ESP32-Based Digital Clock with TFT Display and RTC Module

Circuit Documentation

Summary

This circuit integrates an ESP32 microcontroller with a 1.8-inch Adafruit TFT display and a Real-Time Clock (RTC) module. The ESP32 is responsible for controlling the display and maintaining accurate time using the RTC. The display shows the current time, which is updated every second. The circuit is designed to be powered by a 5V supply connected to the ESP32, which also provides 3.3V to the RTC module.

Component List

ESP32 (30 pin)

  • Description: A 30-pin ESP32 microcontroller module.
  • Purpose: Acts as the central processing unit of the circuit, interfacing with the TFT display and RTC module to display the current time.

Adafruit TFT 1.8 inch 160x128 w/ microSD

  • Description: A small TFT display with a resolution of 160x128 pixels and an integrated microSD card slot.
  • Purpose: Displays the current time and other user interface elements as controlled by the ESP32.

RTC

  • Description: A Real-Time Clock module.
  • Purpose: Keeps track of the current time, even when the microcontroller is powered off, ensuring accurate timekeeping.

Wiring Details

ESP32 (30 pin)

  • EN: Not connected
  • VP: Not connected
  • VN: Not connected
  • D34-D27, D14-D13, TX0, RX0, TX2, RX2: Not connected
  • D32: Connected to RTC RST
  • GND: Common ground with Adafruit TFT and RTC
  • Vin: Connected to Adafruit TFT +5V
  • D23: Connected to Adafruit TFT MOSI
  • D22: Connected to RTC CLK
  • D21: Connected to RTC DAT
  • D19: Connected to Adafruit TFT MISO
  • D18: Connected to Adafruit TFT SCLK
  • D5: Connected to Adafruit TFT TFTCS
  • D4: Connected to Adafruit TFT CARDCS
  • D2: Connected to Adafruit TFT TFTDC
  • D15: Connected to Adafruit TFT RESET
  • 3V3: Connected to RTC VCC

Adafruit TFT 1.8 inch 160x128 w/ microSD

  • LITE: Not connected
  • MISO: Connected to ESP32 D19
  • SCLK: Connected to ESP32 D18
  • MOSI: Connected to ESP32 D23
  • TFTCS: Connected to ESP32 D5
  • CARDCS: Connected to ESP32 D4
  • TFTDC: Connected to ESP32 D2
  • RESET: Connected to ESP32 D15
  • +5V: Connected to ESP32 Vin
  • GND: Common ground with ESP32

RTC

  • VCC: Connected to ESP32 3V3
  • GND: Common ground with ESP32
  • CLK: Connected to ESP32 D22
  • DAT: Connected to ESP32 D21
  • RST: Connected to ESP32 D32

Documented Code

#include <RtcDS1302.h>
#include <ThreeWire.h>
/*
 * This Arduino Sketch is for an ESP32 microcontroller to create a clock
 * with a TFT display and an RTC module. The code initializes the TFT
 * display and the RTC module, then displays the current time on the TFT
 * display. The time is updated every second.
 */

#include <TFT_eSPI.h> // Include the graphics library
#include <SPI.h>     // Include the SPI library
#include <Wire.h>    // Include the Wire library for I2C
#include <RTClib.h>  // Include the RTC library
 
const int IO = 27;    // DAT
const int SCLK = 14;  // CLK
const int CE = 26;    // RST

ThreeWire myWire(IO, SCLK, CE);
RtcDS1302<ThreeWire> Rtc(myWire);

TFT_eSPI tft = TFT_eSPI(); // Create TFT object
RTC_DS3231 rtc;            // Create RTC object

void setup() {
  tft.init();
  tft.setRotation(1); // Set the rotation of the display
  tft.fillScreen(TFT_BLACK); // Clear the screen
  tft.setTextColor(TFT_WHITE, TFT_BLACK); // Set text color
  tft.setTextSize(2); // Set text size
  tft.println("Kello");

  if (!rtc.begin()) {
    tft.println("Couldn't find RTC");
    Serial.print("Couldn't find RTC");
    while (1);
  }

  if (rtc.lostPower()) {
    tft.println("RTC lost power, let's set the time!");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
}

void loop() {
  DateTime now = rtc.now();

  tft.fillScreen(TFT_BLACK); // Clear the screen
  tft.setCursor(0, 0); // Set cursor to top-left corner
  tft.printf("%02d:%02d:%02d", now.hour(), now.minute(), now.second());
  tft.println("Kellooo");
  Serial.printf("%02d:%02d:%02d", now.hour(), now.minute(), now.second());

  delay(1000); // Wait for 1 second
}

Filename: sketch.ino

This code is designed to run on the ESP32 microcontroller. It initializes the TFT display and the RTC module, then enters a loop where it continuously updates the display with the current time. The time is formatted as hours, minutes, and seconds, and is updated every second. If the RTC has lost power, the time is set to the time the code was compiled.