Home

Awesome

PiicoDev® BME280 MicroPython Module

This is the firmware repo for the Core Electronics PiicoDev® Atmospheric Sensor BME280.

This module depends on the PiicoDev Unified Library.

See the Quickstart Guides:

Usage

Simple Example

main.py is a simple example to get started.

from PiicoDev_BME280 import PiicoDev_BME280
from PiicoDev_Unified import sleep_ms # cross-platform compatible sleep function

sensor = PiicoDev_BME280() # initialise the sensor

while True:
    tempC, presPa, humRH = sensor.values() # read all data
    pres_hPa = presPa / 100 # convert Pascals to hPa (mbar)
    print(str(tempC)+" °C  " + str(pres_hPa)+" hPa  " + str(humRH)+" %RH")
    sleep_ms(100)

Advanced Example

This example sets oversampling modes, filtering, and a local mean-sea-level-pressure.

from PiicoDev_BME280 import PiicoDev_BME280
from PiicoDev_Unified import sleep_ms # cross-platform compatible sleep function

sensor = PiicoDev_BME280(t_mode=2, p_mode=5, h_mode=1,iir=2)
zeroAlt = sensor.altitude(pressure_sea_level=1013.25)
while True:
    tempC, presPa, humRH = sensor.values()
    pres_hPa = presPa / 100
    print(str(tempC)+" °C  " + str(pres_hPa)+" hPa  " + str(humRH)+" %RH")
    print(sensor.altitude() - zeroAlt) # show the CHANGE in altitude, since the script began
    sleep_ms(100)

Changing default I2C configuration (Raspberry Pi Pico Only)

You can initialise the sensor with different I2C settings (frequency, bus, pins) by eg.

sdaPin=machine.Pin(6)
sclPin=machine.Pin(7)

sensor = PiicoDev_BME280(bus=1, freq=100000, sda=sdaPin, scl=sclPin, address=0x77)

Details

PiicoDev_BME280(bus=, freq=, sda=, scl=, t_mode=2, p_mode=5, h_mode=1,iir=1, address=0x77)

ParameterTypeRangeDefaultDescription
busint0,1Raspberry Pi Pico: 0, Raspberry Pi: 1I2C Bus. Ignored on Micro:bit
freqint100-1000000Device dependentI2C Bus frequency (Hz). Ignored on Raspberry Pi
sdaPinDevice DependentDevice DependentI2C SDA Pin. Implemented on Raspberry Pi Pico only
sclPinDevice DependentDevice DependentI2C SCL Pin. Implemented on Raspberry Pi Pico only
t_modeint1-52Controls the oversampling of temperature data
p_modeint1-55Controls the oversampling of pressure data
h_modeint1-51Controls the oversampling of humidity data
iirint0-71Controls the time constant of the IIR filter
addressint0x76, 0x770x77This address needs to match the PiicoDev Atmospheric Sensor BME280 hardware address configured by the jumper or ADR pin

PiicoDev_BME280.altitude(pressure_sea_level=1013.25)

ParameterTypeRangeDefaultDescription
pressure_sea_levelfloatany1013.25Enter the current sea level pressure. This value is available from your favourite weather service (hPa).
returnedfloatAltitude (m)

PiicoDev_BME280.values()

ParameterTypeDescription
returned 1stfloatTemperature (degC)
returned 2ndfloatPressure (Pa)
returned 3rdfloatRelative humidity (%)

License

This project is open source - please review the LICENSE.md file for further licensing information.

Attribution

Code in this repo has been ported from a repo by neliogodoi to include RPi Pico functionality.

If you have any technical questions, or concerns about licensing, please contact technical support on the Core Electronics forums.

"PiicoDev" and the PiicoDev logo are trademarks of Core Electronics Pty Ltd.