Arduino with ST7789 TFT and BME280 Sensor – Weather Station Project

This tutorial shows how to build a simple weather station using Arduino board and BME280 barometric pressure, temperature & humidity sensor.
The Arduino microcontroller (ATmega328P for uno, Nano …) reads temperature & humidity & pressure values from the BME280 sensor and prints them (respectively in °C & rH% & hPa) on ST7789 TFT display.

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.
The ST7789 TFT 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 (some may come with 320×240 pixel), this means it has 57600 pixels. This module works with 3.3V only and it doesn’t support 5V (not 5V tolerant).

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

To see how to interface Arduino with ST7789 TFT display, visit this post:
Interfacing Arduino with ST7789 TFT Display – Graphics Test Example

About the BME280 sensor:
The BME280 sensor from Bosch Sensortec is a low cost digital pressure, temperature and humidity 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
Humidity range: 0 … 100 %
Interface: I2C and SPI
Supply voltage range: 1.71 … 3.6 V

In this project the BME280 sensor is used in I2C mode.

Arduino BME280 sensor ST7789 TFT weather station

Hardware Required:

  • Arduino board
  • ST7789 TFT display module (1.3″, 1.54″ …)
  • BME280 sensor module (with built-in 3.3V regulator and level shifter)   —->  BME280 datasheet
  • 4 x 3.3k ohm resistor (+1 if the display module has CS pin)
  • 4 x 2.2k ohm resistor (+1 if the display module has CS pin)
  • Breadboard
  • Jumper wires

Arduino with ST7789 TFT and BME280 sensor circuit:
Project circuit schematic diagram is shown below.

Hint:
The BME280 chip works with maximum voltage of 3.6V (supply voltage range is from 1.71 to 3.6V) which means we’ve to use a 3V3 voltage regulator to supply it from a 5V source.
Also, if we’re working with a 5V system (development board, microcontroller …) like the Arduino UNO board (ATmega328P microcontroller), we’ve to use a voltage level shifter (level converter) which converts the 3.3V (comes from the BME280 chip) into 5V (goes to the ATmega328P) and vice versa. This level shifter is for the I2C bus lines (clock and data).
The BME280 module shown in project circuit diagram has a built-in 3.3V regulator and level shifter.

BME280 sensor Arduino ST7789 TFT circuit

Generally, the BME280 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:
VCC is power supply pin, it is connected to Arduino 5V pin,
GND (ground) is connected to Arduino GND pin,
SDA is I2C bus serial data line, connected to Arduino analog pin 4 (A4),
SCL is I2C bus serial clock line, connected to Arduino analog pin 5 (A5).

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).
Connecting the BLK pin is optional. The back light turns off when the BLK pin connected to the ground (GND).

As mentioned above, the ST7789 TFT display controller works with 3.3V only (power supply and control lines). The display module is supplied with 3.3V (between VCC and GND) which comes from the Arduino board.

All Arduino UNO board output pins are 5V, connecting a 5V pin to the ST7789 TFT display may damage its controller.
To connect the Arduino to the display module, I used voltage divider for each line which means there are 4 voltage dividers. Each voltage divider consists of 2.2k and 3.3k resistors, this drops the 5V into 3V which is sufficient.

If the display module has a CS pin (Chip Select) then it should be connected to Arduino digital pin 10 through another voltage divider.

So, the ST7789 TFT display is connected to the Arduino board as follows (each one through voltage divider):
RST pin is connected to Arduino digital pin 8,
DC pin is connected to Arduino digital pin 9,
SDA pin is connected to Arduino digital pin 11,
SCL pin is connected to Arduino digital pin 13.

Other pins are connected as follows:
VCC pin is connected to Arduino 3V3 pin,
GND pin is connected to Arduino GND pin,
BL (LED) pin is connected to Arduino 3V3 pin (optional).

Arduino with ST7789 TFT and BME280 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 BME280 sensor, it may be installed using library manager (in the search box write “bme280” and choose the one from Adafruit).

The 3 libraries can be installed manually, first download them from the following links:
Adafruit ST7789 TFT library    —->  direct link
Adafruit graphics library        —->  direct link
Adafruit BME280 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:
The libraries are included in the main code as follows:

The ST7789 TFT module pins (CS, RST and DC) connections are defined as shown below (even the display module has no CS pin but its definition is required by the Adafruit ST7789 library):

The other display pins (SDA and SCL) are connected to Arduino hardware SPI module pins (digital pin 11 and digital pin 13 respectively for MOSI and SCLK).

The Adafruit ST7789 library is initialized with this line:

And the TFT display is initialized using the following command:

As any other I2C device, the BME280 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 BME280 library is defined as 0x77 and my device I2C address is 0x76.
In the code, the definition of BME280 sensor I2C slave address and the initialization of its library are as shown below:

The initialization of the BME280 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, humidity and pressure:

Note that the BME280 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 ST7789 TFT display.
If there is a problem with the BME280 sensor (bad connection, wrong device address …) the screen will display Connection Error.

Full Arduino Code:

The following video shows my simple hardware circuit:

Related Project:
Arduino with BMP280 Sensor and ST7789 TFT Display


Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

1 thought on “Arduino with ST7789 TFT and BME280 Sensor – Weather Station Project”

  1. Joseph T Tannenbaum

    This can easily be change for the ILI9341 TFT! Use the proper library and change all instances of st7789 to ILI9341.

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