Header Ads Widget

BME280 Interfacing with Raspberry Pi Pico RP2040

Hello guys, In this blog I am going to interface BME280 sensor with Raspberry Pi Pico using micropython. The breakout module is equipped with a BME280 digital temperature, humidity and pressure sensor, which is a successor to the popular BMP180 and BMP183 sensors.

This BME280 sensor can measure temperature from -40°C - 85°C with ±1.0°C of accuracy, Humidity from 0-100 with ±3% of accuracy and Pressure from 300Pa - 1100 hPa with +1% hPa of accuracy.

For this blog i am going to use BME280 breakout board which comes with inbuilt LM6206 3.3 volt voltage regulator and voltage level translator for I2C. this module comes with pre-calibrated sensor with easy to use interface.

Note: BME280 SDO pin act as address select line, If ground is connected using pulldown resistor on SDO pin, Address will be 0x76. If 3.3V is connected using pull up resistor on SDO pin, Address will be 0x77 .

Circuit Diagram

Source Code (MicroPython)

The Source code is using the MicroPython libraries "machine" and "bme280" to communicate with a BME280 sensor over the I2C communication protocol. The I2C object is created using the machine library, with the frequency set to 399361, and the SCL and SDA pins are defined as Pin 21 and Pin 20, respectively. The BME280 object is then created using the bme280 library, with the I2C object and the sensor's address (0x76) passed as arguments. The code then prints the temperature, pressure, and humidity values read from the sensor using the "values" attribute of the BME280 object.
import machine
import bme280
i2c = I2C(0, freq=399361, scl=Pin(21), sda=Pin(20))
bme = bme280.BME280(i2c=i2c, address=0x76)
print("Temp: {temp} Pressure: {pre} Hum: {hum}".format(temp=bme.values[0],pre=bme.values[1],hum=bme.values[2]))

BME280 Library 

save below file as bme280.py in Raspberry pi pico before running the source code.


Post a Comment