Interfacing NodeMCU with ST7789 TFT and DHT22 Sensor

This project shows how to interface ESP8266 NodeMCU board with ST7789 SPI TFT display and DHT22 (AM2302 – RHT03) digital humidity & temperature sensor.
The values of temperature and relative humidity are printed on the ST7789 TFT display respectively in °C and rH%.

The ST7789 TFT module contains a display controller with the same name: ST7789. It’s a color display that uses SPI interface protocol and requires 3, 4 or 5 control pins, it’s low cost and easy to use. This display is an IPS display, it comes in different sizes (1.3″, 1.54″ …) but all of them should have the same resolution of 240×240 pixel, this means it has 57600 pixels. This module works with 3.3V only and it does not support 5V.

TFT: Thin-Film Transistor.
SPI: Serial Peripheral Interface.
IPS: In-Plane Switching.

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

About DHT2 sensor:
This sensor has the following characteristics:

  • Humidity Range: 0 ~ 100% RH
  • Humidity Accuracy: ±2% RH (max ±5% RH)
  • Temperature Range: -40 ~ 80 °C
  • Temperature Accuracy: ±0.5 °C
  • Operating Voltage: 3.3V ~ 5.5V
  • Resolution = 0.1

Hardware Required:

  • ESP8266 NodeMCU board
  • ST7789 TFT display module
  • DHT22 (AM2302, RHT03) humidity and temperature sensor   —->  datasheet
  • 4.7k ohm resistor
  • Micro USB cable (for programming and powering the whole circuit)
  • Breadboard
  • Jumper wires

NodeMCU board with ST7789 TFT and DHT22 sensor

NodeMCU with ST7789 TFT and DHT22 (AM2302) sensor circuit:
Project circuit schematic diagram is shown below.

The DHT22 (AM2302) sensor has 4 pins (from left to right):
Pin 1 is power supply pin, connected to NodeMCU 3V3 pin,
Pin 2: data output pin, connected to NodeMCU pin D2,
Pin 3: not connected pin,
Pin 4: GND (ground), connected to NodeMCU GND pin.

A pull-up resistor of 4.7k ohm is required because the DHT22 sensor has an open drain output.

NodeMCU AM2302 DHT22 sensor ST7789 TFT

The ST7789 display module shown in project circuit diagram has 7 pins: (from right to left): GND (ground), VCC, SCL (serial clock), SDA (serial data), RES (reset), DC (or D/C: data/command) and BLK (back light).

The ST7789 TFT display module is connected to the NodeMCU board as follows:
GND is connected to pin GND of the NodeMCU board,
VCC and BL are connected to pin 3V3,
SCL pin is connected to D5 (ESP8266EX GPIO14),
SDA pin is connected to D7 (ESP8266EX GPIO13),
RES pin is connected to D4 (ESP8266EX GPIO2),
DC pin is connected to D3 (ESP8266EX GPIO0).

If the display module has a CS pin (Chip Select) then it should be connected to NodeMCU pin D8 (GPIO15).

Connecting the BLK pin is optional. The back light turns off when the BLK pin connected to the ground (GND).

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

NodeMCU with ST7789 TFT and DHT22 (AM2302) sensor code:
The following Arduino code requires 3 libraries from Adafruit Industries:
The first library is a driver for the ST7789 TFT display which can be installed from Arduino IDE library manager (Sketch —> Include Library —> Manage Libraries …, in the search box write “st7789” and install the one from Adafruit).

The second library is Adafruit graphics library which can be installed also from Arduino IDE library manager.
The 3rd library is for the DHT22 sensor, it may be installed using library manager (in the search box write “dht” and choose the one from Adafruit).

The 3 libraries can be installed manually, first download them from the following 3 links:
Adafruit ST7789 TFT library    —->  direct link
Adafruit graphics library        —->  direct link
Adafruit DHT library             —->   direct link

You may need to install Adafruit Unified Sensor library if it’s not already installed, download link is below:
Adafruit Unified Sensor 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 other library files.

Hints:
The 3 libraries are included in the main code as follows:

The connection of ST7789 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):

And the TFT display is initialized using the following command:

Definition of sensor type, its data pin connection and the initialization of the DHT library:

Rest of code is described through comments.

Full Arduino code:

Related Project:
ESP8266 NodeMCU Interface with ST7789 TFT and DHT11 Sensor


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