Hi guys, in one of our previous tutorials, we built a real-time clock with temperature monitor using the DS3231 and the 16×2 LCD display shield. Today, we will build an upgrade to that project by replacing the 16×2 LCD display with an ST7735 based 1.8″ colored TFT display.
Apart from changing the display, we will also upgrade the features of the project by displaying the highest and lowest temperature that has been measured over time. This feature could be useful in scenarios where there is a need to measure the maximum and minimum temperature experienced in a place over a particular time range.
This tutorial is based on the ability and features of the DS3231 RTC module. The DS3231 is a low power RTC chip, it has the ability to keep time with incredible accuracy such that even after power has been disconnected from your project, it can still run for years on a connected coin cell battery. Asides from its ability to accurately keep time, this module also comes with an accurate temperature sensor which will be used to obtain temperature readings during this tutorial.
The main upgrade to the previous tutorial mentioned above is the use of the 1.8″ colored TFT display and details about the features and use of this display have been covered in a recent tutorial here.
The following components are required to build this project;
Go over the connections once more to ensure everything is as it should be.
The code for this project is fairly simple, we will use two main libraries; the Sodaq library which can be downloaded from this link and is used to communicate with the DS3231 and the ST7735 Arduino library to communicate with the ST7735 TFT Display.
The first thing we do in the code is to include the libraries that will be needed for this project. In addition to the two libraries mentioned above, we will add the Adafruit GFX library, the SPI library, and the wire.h library.
/////////////////////////////////////////////////////////////////// Arduino Real Time Clock fahrenheit v1.02 //// Get the latest version of the code here: //// http://educ8s.tv/arduino-real-time-clock/ ///////////////////////////////////////////////////////////////////#include <Adafruit_ST7735.h>#include <Adafruit_GFX.h>#include <Wire.h>#include "Sodaq_DS3231.h"#include <SPI.h>
Next, we declare the pins of the Arduino to which the TFT display is connected and create an object of the TFT class with the declared pins.
Next, we create placeholders for the temperature, its max, and min value on the display.
printText("TEMPERATURE", ST7735_GREEN,30,65,1); // Temperature Static Text
We also include the setRTCTime() function which will be used to set the time on the RTC before it is used. After setting the time, this part of the code should be commented out and the code re-uploaded to the Arduino board.
Next, is the void loop() function. The void loop function handles the sensing of temperature, extraction of time information from the DS3231 and the display of information on the TFT display. Since the changes of the environment temperature are slow, we will only update the temperature when there is a difference between the last temperature displayed on the screen and current temperature. This is done to counter a major downside of the 1.8″ TFT display, which is the slow speed with which the screen is updated when new information is sent to it.
The slow speed leads to the occurrence of a visible flicker on the TFT display and makes things a little bit messy. To solve this problem, we will be leveraging on the fact that we can update a section of the TFT display, without updating the whole display. This means a faster update time as less information will be passed up to the screen reducing the processing time and eliminating the resulting flicker.
Install all the libraries, open an instance of the Arduino IDE and upload the code to the Arduino board, you should see the TFT display light up with the temperature, time and date information on display as shown in the image below.
That’s it for this tutorial guys. While this might look like an ordinary temperature and clock project, it could be the launch pad for something as cool as a thermostat to control the temperature in your home or smart farm and any other cool stuff you can think of. Feel free to share and ask any question via the comment section.
Till next time!
You can watch the video of this tutorial on youtube here.