BMP280 is a digital temperate and pressure sensor manufactured by Bosch Sensortec. At the end of this post you’ll be able to read values from it in Python.
This sensor is capable to I2C and SPI communication (3V3) making it way easier to use in an ARM device than a DS18B20. This last one uses the 1-Wire protocol that is depend on CPU clock thus not practical. Also BMP280 sensors are so cheap online that it’s not worth to deal with 1-Wire:
In order to connect the BMP280 to the NanoPi M4 I used the following pins that are the I2C port 2 in the board:
PIN Function
17 VCC3V3_SYS
3 I2C2_SDA(3V)
5 I2C2_SCL(3V)
39 GND
Install the required packages and test your connection to the sensor with the i2c-tool
:
$ apt install i2c-tool
$ pip3 install smbus2
$ pip3 install bmp-280
$ i2cdetect -y 2
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 --
We’ve the sensor working at the I2C address 76 as described in the datasheet. Here is an example on how to use it:
#!/usr/bin/env python3
from bmp_280 import BMP280
from time import sleep
bmp = BMP280(
port=2, # Our Board Port 2
mode=BMP280.FORCED_MODE,
oversampling_p=BMP280.OVERSAMPLING_P_x16,
oversampling_t=BMP280.OVERSAMPLING_T_x1,
filter=BMP280.IIR_FILTER_OFF,
standby=BMP280.T_STANDBY_1000
)
pressure = bmp.read_pressure()
temp = bmp.read_temperature()
print("Pressure (hPa): " + str(pressure))
print("Temperature (°C): " + str(temp))
See you soon!