The BME280 is an environmental sensor communicating via I2C. The sensor can read the current temperature, humidity and atmospheric pressure.
The BME280 has usually four pins and a single mounting hole. There might be other variants out there, but be careful: Some shop might try fool you and sell you the cheaper BMP280 instead, which lacks the humidity feature and has usually a different board with six pins and two mounting holes. The case parts are not prepared to mount this variant.
Also, following the datasheets, some variants needs to be supplied with 3.3 V, while others expect 5 V instead. Read carefully.
In my case, it was documented with 3.3 V.
BME280 Pin | Raspberry Pi Pin |
---|---|
GND | GND |
VIn | VCC (3.3 V) |
SDA | SDA (GPIO 2) |
SCL | SCL (GPIO 3) |
I2C is a bus system. Other devices can be connected to the same pins, but still work at the same time if they have different addresses. BME280 are usually using address 0x76.
Install i2c-tools
if not already done:
sudo apt install i2c-tools
Check if the module is recognized correctly:
sudo i2cdetect -y 1
This command should return an entry in the matrix for 0x76 (or a different address if the module has a different one, example):
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- 76 --
Open a python console and test it out:
>>> import smbus2
>>> import bme280
>>> bus = smbus2.SMBus(1)
>>> address = 0x76 # address of your sensor board, as shown in i2cdetect
>>> bme280.sample(bus, address)
compensated_reading(id=... timestamp=..., temp=23.020 °C, pressure=1002.68 hPa, humidity=38.15 % rH)
If the reading returns just zeroes for temp
, pressure
and humidity
, check your wiring. The reading was not
successful, unless you are living in an extremely dry, but cool place in outer space, and the values are actually
correct.