WiFi Real-Time Clock/Calendar/Weather Station Project with TFT 3.5” LCD Display and NodeMCU ESP8266

Introduction
In this blog post, we will take a deep dive into the Renewed WiFi Real-Time Clock/Calendar/Weather Station Project, which showcases the power and versatility of the TFT 3.5” LCD Display and the NodeMCU ESP8266 microcontroller. This project has been completely revised since its initial presentation in February 2023, leveraging improved components and simplifying the design to enhance user experience and reduce costs.
This project integrates multiple functionalities, including a real-time clock, a calendar, and a weather station, all within a compact and user-friendly device. By utilizing the WiFi capabilities of the NodeMCU8266, we eliminate the need for an external Real-Time Clock (RTC) module, instead relying on the Network Time Protocol (NTP) for accurate timekeeping. Additionally, the project features a BME280 sensor, which collects data on temperature, humidity, and pressure, both indoors and outdoors, while also fetching external weather data from platforms like Thingspeak.
The end product presents a wealth of information on a single display, including:
- Exact Time: Automatically adjusts for daylight saving time.
- Date and Year: Clear visibility of the current date and year.
- Indoor Environmental Conditions: Displays temperature, humidity, and atmospheric pressure, along with minimum and maximum values recorded over a 24-hour period.
- Outdoor Weather Data: Includes temperature and humidity data sourced externally.
- Heat Index Calculation: Provides a comprehensive understanding of how the temperature feels in relation to humidity.
This project serves not only as a practical device but also as an engaging learning experience for those interested in electronics and programming.
Supplies and Materials Used
To successfully build this project, the following components are necessary:
- NodeMCU8266 Board: This microcontroller serves as the heart of the project, providing WiFi connectivity and processing capabilities. Its compact size and integrated WiFi make it an ideal choice for IoT projects.
- 3.5” TFT Display (480x320): The TFT display features an SPI interface with an ILI9488 driver. Its size and resolution allow for clear and vibrant visuals, essential for displaying real-time data.
- BME280 Sensor: This high-precision sensor measures temperature, humidity, and pressure, crucial for gathering accurate weather data. It operates using the I2C communication protocol, making it easy to integrate with the NodeMCU.
- Plastic Enclosure (80x125x32 mm): A protective case to house the components, safeguarding them from external elements while providing a neat appearance.
- Pre-drilled Base for Connector: This component aids in assembling the display securely within the enclosure.
- Various Fasteners: Such as bolts and nuts, necessary for securing the components and ensuring stability.
Additional Tools and Components
In addition to the main components listed, here are some additional items that may be useful during the build process:
- Soldering Iron and Solder: Essential for making secure electrical connections between components.
- Wires: Various lengths and types to facilitate connections between the microcontroller, sensor, and display.
- Breadboard: Useful for prototyping and testing connections before final assembly.
- Dremel Tool: Handy for making adjustments or creating openings in the enclosure for display fitting.
- 3D Printer: For creating a custom enclosure, if desired.
Connections
Proper wiring is crucial for ensuring that all components communicate effectively with one another. Below, we will outline the connections required for both the TFT display and the BME280 sensor.
Display Connections
The 3.5” TFT display has a 14-pin connector. For this project, only 8 pins are necessary, as we will not be utilizing the touchscreen functionality. The connections to the NodeMCU8266 are as follows:
TFT Pin NodeMCU8266 Pin Description Vcc +3.3V Power supply for the display Gnd Gnd Ground connection CS D8 Chip select (used to control display) Rst D4 Reset pin to reset the display DC/RS D3 Data/command selection pin SDI/MOSI D7 Master Out Slave In (data line) SCK D5 Serial Clock for SPI communication LED +3.3V Power for display backlight

Sensor Connections
The BME280 sensor connects to the NodeMCU as follows:
BME280 Pin NodeMCU Pin Description Vcc +3.3V Power supply for the sensor Gnd Gnd Ground connection SCL D1 Serial Clock Line for I2C SDA D2 Serial Data Line for I2C

Enclosure and Hardware Modifications
Creating a custom frame for the TFT display within the plastic enclosure is essential for a polished final product. A Dremel tool can be used to carefully cut the necessary openings for the display. For those with access to a 3D printer, designing a custom enclosure can enhance the aesthetic appeal of the project.
Update and LED Control
One valuable update to the project involves the ability to control the display’s LED backlighting. By modifying the circuit, you can set the display’s LEDs to turn off automatically after midnight and reactivate in the morning. This is achieved by interrupting the connection between the “LED” pin of the display and the +3.3V of the board, incorporating a small circuit featuring a diode, a resistor, a low-power NPN transistor, and a normally open button.
To implement this, you will need to make modifications to the code as well to manage the LED state. This feature not only enhances the device’s energy efficiency but also provides a more user-friendly experience.
Software Requirements
The software component is critical to the functionality of the project. The following libraries are essential for the operation of the NodeMCU, TFT display, and BME280 sensor:
- BME280I2C.h: This library is used to interface with the BME280 sensor, allowing you to retrieve temperature, humidity, and pressure data.
- TimedAction.h: This library enables the execution of timed actions, facilitating regular updates of the displayed data.
- SPI.h: Required for SPI communication, which is necessary for interfacing with the TFT display.
- Wire.h: This library is used for I2C communication, allowing the NodeMCU to communicate with the BME280 sensor.
- TFT_eSPI.h: This library controls the TFT display, enabling graphical output of data.
- NTPClient.h: This library facilitates fetching the current time via NTP.
- ESP8266WiFi.h: This library manages WiFi connections, enabling the device to connect to the internet for data fetching.
- WiFiUdp.h: This library is necessary for handling UDP communication, which is used by the NTP client.
- Timezone.h: This library handles timezone conversions, ensuring the displayed time is accurate for the user’s location.
- ArduinoJson.h: This library is used for parsing JSON data received from external sources like Thingspeak.
Configuring the TFT_eSPI Library
To successfully utilize the 3.5” SPI ILI9488 display, certain modifications to the TFT_eSPI library are necessary. Follow these steps:
- Open the User_Setup_Select.h File: Within the TFT_eSPI library folder, locate and open the
User_Setup_Select.h
file. Uncomment the following line:
#include <User_Setups/Setup20_ILI9488.h>
- Open the User_Setup.h File: Next, open the
User_Setup.h
file and uncomment the line:
#define ILI9488_DRIVER
These adjustments ensure the TFT display functions correctly with the NodeMCU8266 board, allowing for the display of weather and time data.
Code Development
Developing the code for this project is a critical step. Although I’m not an expert programmer, I utilized tools such as Copilot and Gemini for assistance in writing the sketch. Below, I will provide an overview of the main components of the code and how they interact with the hardware.
Setting Up WiFi Connection
The first step in the code is to establish a WiFi connection to enable data fetching from NTP and Thingspeak.
#include <ESP8266WiFi.h>
const char* ssid = "your_SSID"; // Replace with your WiFi SSID
const char* password = "your_PASSWORD"; // Replace with your WiFi password
void setup() {
Serial.begin(115200); // Initialize serial communication
WiFi.begin(ssid, password); // Start the WiFi connection
while (WiFi.status() != WL_CONNECTED) { // Wait for the connection
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi"); // Confirmation message
}
Fetching Time via NTP
Next, to get the current time from NTP, use the NTPClient
library.
#include <NTPClient.h>
#include <WiFiUdp.h>
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", 0, 60000); // NTP client setup
void setup() {
// Existing setup code...
timeClient.begin(); // Start the NTP client
}
void loop() {
timeClient.update(); // Update time
String formattedTime = timeClient.getFormattedTime(); // Get formatted time
// Display the time on the TFT...
}
Reading Sensor Data
To read data from the BME280 sensor, include the following code:
#include <BME280I2C.h>
BME280I2C bme; // Create an instance of the BME280 class
void setup() {
// Existing setup code...
if (!bme.begin()) { // Initialize the BME280 sensor
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
}
void loop() {
// Existing loop code...
float temperature = bme.readTemperature(); // Read temperature
float humidity = bme.readHumidity(); // Read humidity
float pressure = bme.readPressure() / 100.0F; // Read pressure
// Display the data on the TFT...
}
Displaying Data on the TFT
Finally, manage the output on the TFT screen using the following code:
#include <TFT_eSPI.h>
TFT_eSPI tft = TFT_eSPI(); // Create a TFT instance
void setup() {
tft.init(); // Initialize the TFT
tft.setRotation(1); // Set display rotation
tft.fillScreen(TFT_BLACK); // Clear the display
}
void loop() {
// Existing loop code...
tft.setTextColor(TFT_WHITE);
tft.setTextSize(2);
tft.setCursor(0, 0);
tft.println("Time: " + formattedTime);
tft.print("Temp: ");
tft.println(temperature);
tft.print("Humidity: ");
tft.println(humidity);
tft.print("Pressure: ");
tft.println(pressure);
// Add more display functions as needed...
}
Improving the Code
While the initial code structure functions, there are numerous areas for improvement to enhance efficiency and readability. Suggested enhancements include:
- Modularizing Code: Organizing the code into functions to improve readability and maintainability.
- Error Handling: Implementing error handling for sensor readings and network connections to enhance robustness.
- Optimizing Updates: Reducing the frequency of updates for less critical data to save power and processing time.
Conclusion
The Renewed WiFi Real-Time Clock/Calendar/Weather Station Project not only serves as a functional device but also offers an excellent learning opportunity for those interested in electronics, programming, and IoT applications. By integrating a NodeMCU ESP8266, a TFT 3.5” LCD display, and a BME280 sensor, you can create a versatile weather station that provides real-time data while adding a decorative touch to your home.
This project encourages hands-on experience with hardware and software integration, offering ample opportunities for further expansion and improvement. Whether you’re a hobbyist or an experienced developer, there’s something to learn and create with this project.
Feel free to explore additional features, such as integrating a custom alarm, notifications based on weather conditions, or even data logging for long-term analysis. The possibilities are endless!
If you have any questions, need further assistance, or want to share your modifications, feel free to reach out. Happy building and experimenting with your IoT projects!