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 chip | BME280 |
Signal interface | I2C/SPI |
Supply voltage | 3.3V/5V |
Temperature sensing | -40~85°C (resolution 0.01°C, accuracy ±1°C) |
Humidity sensing | 0~100%RH (resolution 0.008%RH, accuracy ±3%RH) |
Barometric Pressure sensing | 300~1100hPa (resolution 0.18Pa, accuracy ±1hPa) |
Size | 30mm(Length) x 18mm(width) |
Weight | 2.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
PIN | I2C | SPI |
---|---|---|
VCC | Power supply positive (3.3V/5V) | Power supply positive (3.3V/5V) |
GND | Power supply ground | Power supply ground |
SCK | clock line | clock input |
MOSI | data line | data input |
MISO/ADDR | NC | data output |
CS | NC | 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.
BME280 | I2C | BCM Number | wiringPiNumber |
---|---|---|---|
VCC | 3.3V/5V | 3.3V/5V | 3.3V/5V |
GND | GND | GND | GND |
SCK | SCL1 | 3 | 9 |
MOSI | SDA1 | 2 | 8 |
MISO/ADDR | NC | NC | NC |
CS | NC | NC | NC |
Table2-2 Pin definition of the module wiring to the Raspberry Pi in I2C
BME280 | SPI | BCM Number | wiringPiNumber |
---|---|---|---|
VCC | 3.3V/5V | 3.3V/5V | 3.3V/5V |
GND | GND | GND | GND |
SCK | SCK | 11 | 14 |
MOSI | MOSI | 10 | 12 |
MISO/ADDR | MISO | 9 | 13 |
CS | GPIO.6 | 25 | 6 |
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:
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.
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.
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.
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:
BME280 | I2C | SPI |
VCC | 3.3V/5V | 3.3V/5V |
GND | GND | GND |
SCK | SCL | D13 |
MOSI | SDA | D11 |
MISO/ADDR | NC | D12 |
CS | NC | D10 |
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.
Search for Adafruit Unified Sensor in the Library Manager, scroll down to find Adafruit Unified Sensor and install it.
The same is true for Adafruit's BME280 library, which is searched for bme280 in the library manager to find and install it.
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.
STM32 Demo Codes Usage
Wiring instructions
The wiring between the BME280 and the STM32 development board is shown in the table below:
BME280 | I2C | SPI |
VCC | 3.3V | 3.3V |
GND | GND | GND |
SCK | PB10 | PB13 |
MOSI | PB11 | PB15 |
MISO/ADDR | NC | PB14 |
CS | NC | PB12 |
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.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.
Resources
Data Sheet