This post shows how to interface Arduino UNO board with BMP280 barometric pressure and temperature sensor from Bosch Sensortec.
The Arduino reads temperature & pressure values from the BMP280 sensor and print them (respectively in °C and hPa) on ST7735 TFT display.
In this project the BMP280 sensor is used in I2C mode.
The ST7735 TFT used in this project is a color display which has a resolution of 128×160 pixel and it communicates with the master device using SPI (Serial Peripheral Interface) protocol.
To see how to interface Arduino with ST7735 TFT display, visit the following post:
Arduino ST7735 1.8″ TFT display example
And to see how to interface Arduino with BMP280 sensor for the first time, take a look at this post:
Interfacing Arduino with BMP280 pressure and temperature sensor
Hardware Required:
- Arduino board
- ST7735S (ST7735R) TFT screen
- BMP280 sensor module (with built-in 3.3V regulator and level shifter) —-> BMP280 datasheet
- 5 x 1k ohm resistor
- Breadboard
- Jumper wires
Arduino with ST7735 display and BMP280 sensor circuit:
The image below shows project circuit diagram.
Hint:
The BMP280 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 BMP280 chip) into 5V (goes to the ATmega328P) and vice versa. This level shifter is for the I2C bus lines (clock and data).
The BMP280 module shown in project circuit diagram has a built-in 3.3V regulator and level shifter.
Generally, the BMP280 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 Arduino GND pin,
VCC is the supply pin which is connected to Arduino 5V 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 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 (5V or 3.3V), BL (back light) and Gnd (ground).
Normally the ST7735 display works with 3.3V only, but many boards of this display have a built-in 3.3V regulator (AMS1117 3V3) like the one shown in the circuit diagram. This regulator supplies the display controller with 3.3V from 5V source.
All Arduino UNO board output pins are 5V, connecting a 5V pin directly to the ST7735 display board may damage its controller circuit. To avoid that, I connected each control line of the display to the Arduino board through 1k ohm resistor.
So, the ST7735 display is connected to the Arduino board as follows (each one through 1k resistor):
RST pin is connected to Arduino digital pin 8,
CS pin is connected to Arduino digital pin 9,
D/C pin is connected to Arduino digital pin 10,
DIN pin is connected to Arduino digital pin 11,
CLK pin is connected to Arduino digital pin 13.
Arduino with ST7735 display and BMP280 sensor 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 display library
The 2nd library is Adafruit graphics library which can be downloaded from the following link
Adafruit graphics library —-> direct link
The 3rd one is for the BMP280 sensor:
Adafruit BMP280 Library —-> direct link
You may need to install the 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.
The previous 3 libraries are included in the main code as follows:
1 2 3 | #include <Adafruit_GFX.h> // include Adafruit graphics library #include <Adafruit_ST7735.h> // include Adafruit ST7735 TFT library #include <Adafruit_BMP280.h> // include Adafruit BMP280 sensor library |
The ST7735 TFT display is connected to Arduino hardware SPI module pins (clock and data), the other pins which are: RST (reset), CS (chip select) and DC (data/command) are defined as shown below:
1 2 3 | #define TFT_RST 8 // TFT RST pin is connected to arduino pin 8 #define TFT_CS 9 // TFT CS pin is connected to arduino pin 9 #define TFT_DC 10 // TFT DC pin is connected to arduino pin 10 |
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 is shown below:
1 2 | // define device I2C address: 0x76 or 0x77 (0x77 is library default address) #define BMP280_I2C_ADDRESS 0x76 |
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:
1 | bmp280.begin(BMP280_I2C_ADDRESS) |
Reading the values of temperature and pressure is done as shown below:
1 2 3 | // get temperature, pressure and altitude from library float temp = bmp280.readTemperature(); // get temperature float pressure = bmp280.readPressure(); // get 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.
If there is a problem with the BMP280 sensor (for example wrong device address) the screen will display Connection Error.
Full Arduino Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | /* * Arduino interface with ST7735 color TFT (128x160 pixel) display and * BMP280 barometric pressure & temperature sensor. * This is a free software with NO WARRANTY. * http://simple-circuit.com/ */ #include <Adafruit_GFX.h> // include Adafruit graphics library #include <Adafruit_ST7735.h> // include Adafruit ST7735 TFT library #include <Adafruit_BMP280.h> // include Adafruit BMP280 sensor library #define TFT_RST 8 // TFT RST pin is connected to arduino pin 8 #define TFT_CS 9 // TFT CS pin is connected to arduino pin 9 #define TFT_DC 10 // TFT DC pin is connected to arduino pin 10 // initialize ST7735 TFT library Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST); // define device I2C address: 0x76 or 0x77 (0x77 is library default address) #define BMP280_I2C_ADDRESS 0x76 Adafruit_BMP280 bmp280; // initialize Adafruit BMP280 library void setup(void) { tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab tft.fillScreen(ST7735_BLACK); // fill screen with black color tft.drawFastHLine(0, 50, tft.width(), ST7735_WHITE); // draw horizontal white line at position (0, 50) tft.setTextColor(ST7735_WHITE, ST7735_BLACK); // set text color to white and black background tft.setTextSize(1); // text size = 1 tft.setCursor(4, 16); // move cursor to position (4, 16) pixel tft.print("ARDUINO + ST7735 TFT"); tft.setCursor(19, 33); // move cursor to position (19, 33) pixel tft.print("+ BMP280 SENSOR"); // initialize the BMP280 sensor if( bmp280.begin(BMP280_I2C_ADDRESS) == 0 ) { // connection error or device address wrong! tft.setTextColor(ST7735_RED, ST7735_BLACK); // set text color to red and black background tft.setTextSize(2); // text size = 2 tft.setCursor(5, 86); // move cursor to position (5, 86) pixel tft.print("Connection"); tft.setCursor(35, 110); // move cursor to position (35, 110) pixel tft.print("Error"); while(1); // stay here } tft.drawFastHLine(0, 102, tft.width(), ST7735_WHITE); // draw horizontal white line at position (0, 102) tft.setTextColor(ST7735_RED, ST7735_BLACK); // set text color to red and black background tft.setCursor(25, 61); // move cursor to position (25, 61) pixel tft.print("TEMPERATURE ="); tft.setTextColor(ST7735_GREEN, ST7735_BLACK); // set text color to green and black background tft.setCursor(34, 113); // move cursor to position (34, 113) pixel tft.print("PRESSURE ="); tft.setTextSize(2); // text size = 2 } // main loop void loop() { char _buffer[8]; // read temperature and pressure from BMP280 sensor float temp = bmp280.readTemperature(); // get temperature float pressure = bmp280.readPressure(); // get pressure // print temperature (in °C) if(temp < 0) // if temperature < 0 sprintf( _buffer, "-%02u.%02u", (int)abs(temp), (int)(abs(temp) * 100) % 100 ); else // temperature >= 0 sprintf(_buffer, " %02u.%02u", (int)temp, (int)(temp * 100) % 100 ); tft.setTextColor(ST7735_YELLOW, ST7735_BLACK); // set text color to yellow and black background tft.setCursor(11, 78); tft.print(_buffer); tft.drawCircle(89, 80, 2, ST7735_YELLOW); // print degree symbol ( ° ) tft.setCursor(95, 78); tft.print("C"); // 2: print pressure (in hPa) sprintf( _buffer, "%04u.%02u", (int)(pressure/100), (int)((uint32_t)pressure % 100) ); tft.setTextColor(0xFD00, ST7735_BLACK); // set text color to orange and black background tft.setCursor(3, 130); tft.print(_buffer); tft.setCursor(91, 130); tft.print("hPa"); delay(1000); // wait a second } // end of code. |
The following video shows a simple circuit of the project:
Discover more from Simple Circuit
Subscribe to get the latest posts sent to your email.
Thank you verrrrrrrry much for uploading video
thank you verrrrrry much for uploading video
Hi
Why dont you upload movie about circuit operation?