Interfacing NodeMCU with DS3231 RTC and ST7735 TFT

This tutorial shows how to make a simple digital real time clock using ESP8266 NodeMCU board (ESP-12E) and DS3231 RTC module where time & date can be set with two push buttons connected to the NodeMCU and they are printed (with chip temperature) on ST7735 TFT display.
The ST7735 TFT used in this project is a color display which has a resolution of 128×160 pixel, it communicates with the master device using SPI protocol.

TFT: Thin-Film Transistor
SPI: Serial Peripheral Interface

To see how to interface the NodeMCU board with the ST7735 TFT display, visit this post:
Interfacing ESP8266 NodeMCU with ST7735 TFT

Hardware Required:

  • ESP8266 NodeMCU board
  • ST7735 TFT display module
  • DS3231 module   —->  DS3231 datasheet
  • 2 x push button
  • 2 x 4.7k ohm resistor
  • 3V coin cell battery
  • Micro USB cable (for programming and powering the whole circuit)
  • Breadboard
  • Jumper wires

NodeMCU with DS3231 RTC and ST7735S TFT

NodeMCU with DS3231 RTC and ST7735 TFT display circuit:
Project circuit diagram is shown below.

The ST7735S shown in project circuit diagram has 8 pins: (from right to left): RST (reset), CE (chip enable), DC (or D/C: data/command), DIN (data in), CLK (clock), VCC, BL (back light) and Gnd (ground).

ESP8266 NodeMCU ST7735 TFT DS3231 RTC

The ST7735 display is connected to the NodeMCU board as follows:
RST pin is connected to NodeMCU reset pin (RST),
CS pin is connected to D8 (ESP8266EX GPIO15),
D/C pin is connected to D4 (ESP8266EX GPIO2),
DIN (MOSI) pin is connected to D7 (ESP8266EX GPIO13),
CLK (SCK) pin is connected to D5 (ESP8266EX GPIO14),
VCC and BL are connected to pin 3V3,
GND is connected to pin GND of the NodeMCU board.

Pins D5 (GPIO14), D7 (GPIO13) and D8 (GPIO15) are hardware SPI module pins of the ESP8266EX microcontroller respectively for SCK (serial clock), MOSI (master-out slave-in) and CS (chip select).

The DS3231 RTC module SCL (serial clock) and SDA (serial data) pins are respectively connected to NodeMCU pins D3 (GPIO0) and D2 (GPIO4).

The two push buttons which are connected to NodeMCU pins D1 (GPIO5) and D0 (GPIO16) are for setting time & date of the clock.

NodeMCU with DS3231 RTC and ST7735 TFT code:
The following Arduino code requires 3 libraries from Adafruit Industries:
The first library is a driver for the ST7735 TFT display, download link is below:
Adafruit ST7735 TFT library    —->  direct link

The 2nd library is Adafruit graphics library which can be downloaded from the following link
Adafruit graphics library             —->  direct link

The third library is real time clock library (for DS3231), download link is below:
Adafruit RTC library                   —->  direct link

After the download, go to Arduino IDE —> Sketch —> Include Library —> Add .ZIP Library … and browse for the .zip file (previously downloaded).
The same thing for the other library files.

The previous 3 libraries (& Wire library) are included in the main code as follows:

The connection of ST7735 TFT display with the NodeMCU is as shown below where the display is connected to hardware SPI module of the NodeMCU (pins: SCK and MOSI):

Functions used in the code:
bool debounce (): this function is for button B1 debounce, returns 1 if button is debounced.

void RTC_display(): prints day of the week, date and time on the display.

byte edit(byte parameter): this function is for setting the real time clock, returns the edited parameter.

Rest of code is described through comments.

Full Arduino code:

The result of this project should be as the one shown below where Arduino UNO board is used:

Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top