Arduino Real time clock with ST7735 color TFT and DS1307

This post shows how to build a real time clock & calendar with color TFT display using Arduino UNO board and DS1307 RTC chip.
In this project time and date are displayed on ST7735 SPI TFT display (128 x 160 pixel resolution) and they could be set with two push buttons connected to the Arduino board.

To see how to interface Arduino with ST7735 TFT display, visit the following post:
Arduino ST7735 1.8″ TFT display example

Hardware Required:

  • Arduino board
  • ST7735S (ST7735R) TFT screen
  • DS1307 RTC              —->    datasheet
  • 32.768 kHz crystal oscillator
  • 2 x 10k ohm resistor
  • 5 x 1k ohm resistor
  • 2 x push button
  • 3V coin cell battery
  • Breadboard
  • Jumper wires

Arduino clock with ST7735 display and DS1307 circuit:
The following image shows project circuit schematic diagram.

Arduino DS1307 ST7735 TFT circuit

The ST7735S shown in the 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 (5V or 3.3V), BL (back light) and Gnd (ground).

Normally the ST7735 display works with 3.3V only, but many boards of this display have a built-in 3.3V regulator (AMS1117 3V3) like the one shown in the circuit diagram. This regulator supplies the display controller with 3.3V from 5V source.

All Arduino UNO board output pins are 5V, connecting a 5V pin to the ST7735 display board may damage its controller circuit. To avoid that, I connected each control line of the display to the Arduino board through 1k ohm resistor.

So, the ST7735 display is connected to the Arduino board as follows (each one through 1k resistor):
RST pin is connected to Arduino digital pin 8
CS pin is connected to Arduino digital pin 9
D/C pin is connected to Arduino digital pin 10
DIN pin is connected to Arduino digital pin 11
CLK pin is connected to Arduino digital pin 13

The DS1307 RTC SDA (serial data) and SCL (serial clock) pins are respectively connected to Arduino A4 and A5 pins (ATmega328P hardware I2C module pins).

Arduino clock with ST7735 display and DS1307 code:
The following Arduino code requires 3 libraries from Adafruit Industries:
Adafruit ST7735 display library
Adafruit graphics library             —->  direct link
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 3 libraries are included in the main code as follows:

The ST7735 TFT display is connected to Arduino hardware SPI module pins (clock and data), the other pins which are: RST (reset), CS (chip select) and DC (data/command) are defined as shown below:

And the two push buttons are defined in the code as:

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

void RTC_display(): displays 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 following picture shows a protoboard circuit of the project:

Arduino with ST7735S SPI TFT display and DS1307 RTC

Leave a Reply

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