BME280 Environmental Sensor

Overview

This product is a high-precision Environmental sensor, the BME280 sensor to achieve temperature, humidity and barometric pressure monitoring, the chip temperature sensing in -40~+85 °C, humidity sensing in 0~100%, barometric pressure sensing in 300~1100hPa. PH2.0 6PIN wire is used to connect the module to the development board for environmental detection, Arduino and Raspberry Pi C and python and STM32 versions of demo codes are available, demo codes enable real-time monitoring of temperature, humidity and barometric pressure.

Parameters

sensor chipBME280
Signal interfaceI2C/SPI
Supply voltage3.3V/5V
Temperature sensing-40~85°C (resolution 0.01°C, accuracy ±1°C)
Humidity sensing0~100%RH (resolution 0.008%RH, accuracy ±3%RH)
Barometric Pressure sensing300~1100hPa (resolution 0.18Pa, accuracy ±1hPa)
Size30mm(Length) x 18mm(width)
Weight2.6g

BME280 Environmental Sensor Interface definition diagram

  • ① PH2.0 6PIN Module wire
  • ② RT9193-33 LDO Regulato
  • ③ BME280 Precision Sensor
  • ④ DIP switch is used to select the I2C address

Usage

Hardware interface configuration instructions

BME280 sensor wiring instructions

PINI2CSPI
VCCPower supply positive (3.3V/5V)Power supply positive (3.3V/5V)
GNDPower supply groundPower supply ground
SCKclock lineclock input
MOSIdata linedata input
MISO/ADDRNCdata output
CSNC

SPI chip selection pin

(active at low level)

Raspberry Pi Demo Codes Usage

Wiring instructions

The example program in the Raspberry Pi motherboard uses the wiringPi coded pin definition and the definition of the wiring with the Raspberry Pi motherboard is shown in the table below.

BME280I2CBCM NumberwiringPiNumber
VCC3.3V/5V3.3V/5V3.3V/5V
GNDGNDGNDGND
SCKSCL139
MOSISDA128
MISO/ADDRNCNCNC
CSNCNCNC

Table2-2 Pin definition of the module wiring to the Raspberry Pi in I2C

BME280SPIBCM NumberwiringPiNumber
VCC3.3V/5V3.3V/5V3.3V/5V
GNDGNDGNDGND
SCKSCK1114
MOSIMOSI1012
MISO/ADDRMISO913
CSGPIO.6256

Table2-3 Pin definition of the module wiring to the Raspberry Pi in SPI

The program defaults to I2C wiring mode and changes #define USE_IIC 1 in the main.c program from 1 to 0 when SPI is required.

Wiringpi library installation

First, use the "gpio -v" command on the terminal to check whether the wiringpi library has been installed. If the information of 2.52 appears, it means that the installation has been successful. You can skip this part of the content, otherwise you need to install it as follows:

sudo apt-get install wiringpi

#For Raspberry Pi systems after May 2019 (earlier ones do not need to be executed), an upgrade may be required:wget https://project-downloads.drogon.net/wiringpi-latest.deb

#Version 4B upgrade of Raspberry Pi,If your download fails or the #speed is very slow, you can download it at the following linkand then #and copy it to the Raspberry Pi mainboard:

#https://github.com/seengreat/wiringpi-library

sudo dpkg -i wiringpi-latest.deb
gpio -v

If version 2.52 appears, the installation is successful

#For the Bullseye branch system, use the following command:

git clone https://github.com/WiringPi/WiringPi
cd WiringPi
./build
gpio -v

#Running gpio - v will result in version 2.70. If it does not appear, it indicates an installation error.

If the error prompt "ImportError: No module named 'wiringpi'" appears when running the python version of the sample program, run the following command. #For Python 2. x version

pip install wiringpi

#For Python 3. x version

pip3 install wiringpi

Note: If the installation fails, you can try the following compilation and installation:

git clone --recursive https://github.com/WiringPi/WiringPi-Python.git

Note: The -- recursive option can automatically pull the submodule, otherwise you need to download it manually.

Enter the WiringPi Python folder you just downloaded, enter the following command, compile and install:

#For Python 2. x version

sudo python setup.py install

#For Python 3. x version

sudo python3 setup.py install

If the following error occurs:

BME280 Environmental Sensor

At this time, enter the command sudo apt install swig to install swig. After that, compile and install sudo python3 setup.py install. If a message similar to the following appears, the installation is successful.

BME280 Environmental Sensor

Open SPI interface

sudo raspi-config

Enable I2C interface:

Interfacing Options -> I2C -> Yes

Enable SPI interface:

Interfacing Options -> SPI -> Yes

Restart the device.

sudo reboot

Run the command to check whether I2C and SPI are started.

lsmod

If i2c_bcm2835 and spi_bcm2835 are displayed, it means I2C, the SPI module is started.

BME280 Environmental Sensor

Install the i2c-tools tool to confirm

sudo apt-get install i2c-tools

View connected I2C devices

i2cdetecty -y 1

The connection between BME280 and Raspberry Pi is successful. ADDR is connected to high level by default, and the address is 0X77. If ADDR is connected to low power level, the address is 0X76.

Open the directory demo codes\raspberry-pi, copy the c folder under the directory to the Raspberry Pi, open the Raspberry Pi terminal into the C folder, and then run the following command.

cd /home/pi/raspberry-pi/c
sudo make clean
sudo make
sudo ./main

Real-time temperature, humidity, and barometric pressure information can be seen at the Raspberry Pi terminal.

BME280 Environmental Sensor

If SPI driven: Wire the BME280 module according to the SPI bus wiring method in the interface description, change the USEIIC macro definition in the main.c file to 0, and then recompile and run the program.

Arduino Demo Codes Usage

Wiring instructions

The wiring between the BME280 and the Arduino development board is shown in the table below:

BME280I2CSPI
VCC3.3V/5V3.3V/5V
GNDGNDGND
SCKSCLD13
MOSISDAD11
MISO/ADDRNCD12
CSNCD10

The program defaults to I2C wiring mode, change #define USE_IIC 1 from 1 to 0 when SPI is required, and then recompile and run the program.

Installation of libraries

Open the directory demo codes\Arduino\bme280, open the bme280.ino file with Arduino software, and install the Adafruit Unified Sensor library and Adafruit's BME280 library. To install libraries, navigate to Sketch > Include Library > Manage Libraries and wait for the library manager to download the library index and update the list of installed libraries.

BME280 Environmental Sensor

Search for Adafruit Unified Sensor in the Library Manager, scroll down to find Adafruit Unified Sensor and install it.

BME280 Environmental Sensor

The same is true for Adafruit's BME280 library, which is searched for bme280 in the library manager to find and install it.

BME280 Environmental Sensor

Verify and upload procedures

After installation, click Close, return to the main interface, verify again, upload to the development board after verification, click Tools, open the serial port monitor, set the baud rate to 115200, and observe the data changes.

BME280 Environmental Sensor
BME280 Environmental Sensor

STM32 Demo Codes Usage

Wiring instructions

The wiring between the BME280 and the STM32 development board is shown in the table below:

BME280I2CSPI
VCC3.3V3.3V
GNDGNDGND
SCKPB10PB13
MOSIPB11PB15
MISO/ADDRNCPB14
CSNCPB12

The program defaults to I2C wiring mode, and when SPI is required, change #define USE_IIC 1 in the program from 1 to 0.

After the program is downloaded, you need to use the serial port debugging assistant, open the directory demo codes\STM32\SYSTEM\usart, and then open the usart.c file, you can see the following program;

GPIO_InitStructure. GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure. GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure. GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure. GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure. GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);

It can be seen from the program that GPIOA9 is the TXD end of the sending end connected to the serial port debugging tool, and GPIOA10 is the RXD end of the receiving end connected to the serial port debugging tool.

Open the project, compile and burn

After connecting the BME280 module with STM32 and serial port debugging tools according to 2.4.1, open the directory demo codes\STM32\USER, and then use Keil uVision5 software to open the main.uvprojx project in the directory, compile first, compile correctly, and then download the program to the STM32 development board, as shown below.
BME280 Environmental Sensor

Open the serial assistant and observe the test value

Open the serial port assistant, select the serial port number, set the baud rate to 115200, and then click the open button to observe the value change of the serial port debugging assistant window, and the serial port is displayed as shown below.

BME280 Environmental Sensor

Resources

Schematic

Product

Data Sheet

BME280

RT9193

TXS0104E

Demo Codes

Technical Support

Technical Support and Product Notes