NodeMCU with ST7735 TFT and BMP280 Sensor

This post shows how to interface ESP8266 NodeMCU board (ESP-12E) with BMP280 barometric pressure and temperature sensor from Bosch Sensortec.
The NodeMCU microcontroller (ESP8266EX) reads temperature & pressure values from the BMP280 sensor and print them (respectively in °C and hPa) on ST7735 TFT display.
The ST7735 TFT is a color display which has a resolution of 128×160 pixel, it communicates with the master device using SPI protocol.
In this project the BMP280 sensor is used in I2C mode.

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

About the BMP280 sensor:
The BMP280 sensor from Bosch Sensortec is a low cost pressure and temperature sensor with good accuracy. Because pressure changes with altitude we can use it as an altimeter with ±1 meter accuracy (pressure accuracy = ±1 hPa). Some parameters of the sensor are listed below:

Pressure range: 300…1100 hPa (equivalent to +9000…-500m above/below sea level)
Pressure resolution: 0.01 hPa ( < 10 cm)
Temperature range: -40…85 °C
Temperature resolution: 0.01 °C
Interface: I2C and SPI

Hardware Required:

  • ESP8266 NodeMCU board
  • ST7735 TFT display module
  • BMP280 sensor module   —->  datasheet
  • micro USB cable (for programming and powering the circuit)
  • Breadboard
  • Jumper wires

NodeMCU with BMP280 sensor and ST7735 TFT circuit:
Project circuit schematic 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 BMP280 sensor circuit

The ST7735 TFT 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).

Generally, the BMP280 sensor module has at least 4 pins because it can work in SPI mode or I2C mode. For the I2C mode we need 4 pins: VCC, GND, SDA and SCL where:
GND (ground) is connected to NodeMCU GND pin,
VCC is the supply pin which is connected to NodeMCU 3V3 pin,
SDA is I2C bus serial data line, connected to NodeMCU pin D3 (GPIO0),
SCL is I2C bus serial clock line, connected to NodeMCU pin D2 (GPIO4).

NodeMCU with BMP280 sensor 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 for the BMP280 sensor:
Adafruit BMP280 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 the other library files.

Hints:
In the code there are total of 4 libraries, they’re included in the code as follows:

As any other I2C device, the BMP280 sensor has an I2C slave address which may be 0x76 or 0x77. This address depends on the connection of the SDO pin (used for SPI mode as serial data out or MISO), if the SDO pin is connected (directly or through resistor) to VCC (3.3V) the address will be 0x77, and if it’s connected to GND the address will be 0x76.

The default I2C address of the BMP280 library is defined as 0x77 and my device I2C address is 0x76.
In the code, the definition of the I2C slave address and the initialization of its library are shown below:

The initialization of the BMP280 sensor is done using the function begin() which returns 1 if OK and 0 if error. In the code the initialization with the previously defined address is as shown below:

Reading the values of temperature and pressure:

Note that the BMP280 sensor library returns the value of the pressure in Pa unit and to convert it to hPa we’ve to divide it by 100.

1 bar = 10000 Pa = 100 hPa. ( 1 hPa = 100 Pa = 1 millibar)
Pa: Pascal
hPa: hectoPascal

Temperature and pressure values are displayed on the ST7735 TFT display.
If there is a problem with the BMP280 sensor (for example wrong device address) the screen will display Connection Error

Full Arduino Code:

NodeMCU (ESP-12E) with ST7735S TFT and BMP280 sensor


Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

1 thought on “NodeMCU with ST7735 TFT and BMP280 Sensor”

  1. This was fun, worked first time, great site for my off and on hobby, easy tutorial to follow and shows the code and what it does, Thanks

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