Simple test

Ensure your device works with this simple test.

examples/bme280_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import time
 5import board
 6from adafruit_bme280 import basic as adafruit_bme280
 7
 8# Create sensor object, using the board's default I2C bus.
 9i2c = board.I2C()  # uses board.SCL and board.SDA
10bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
11
12# OR create sensor object, using the board's default SPI bus.
13# spi = board.SPI()
14# bme_cs = digitalio.DigitalInOut(board.D10)
15# bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs)
16
17# change this to match the location's pressure (hPa) at sea level
18bme280.sea_level_pressure = 1013.25
19
20while True:
21    print("\nTemperature: %0.1f C" % bme280.temperature)
22    print("Humidity: %0.1f %%" % bme280.relative_humidity)
23    print("Pressure: %0.1f hPa" % bme280.pressure)
24    print("Altitude = %0.2f meters" % bme280.altitude)
25    time.sleep(2)

Normal Mode

Example showing how the BME280 library can be used to set the various parameters supported by the sensor

examples/bme280_normal_mode.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5Example showing how the BME280 library can be used to set the various
 6parameters supported by the sensor.
 7Refer to the BME280 datasheet to understand what these parameters do
 8"""
 9import time
10import board
11import adafruit_bme280.advanced as adafruit_bme280
12
13# Create sensor object, using the board's default I2C bus.
14i2c = board.I2C()  # uses board.SCL and board.SDA
15bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
16
17# OR create sensor object, using the board's default SPI bus.
18# SPI setup
19# from digitalio import DigitalInOut
20# spi = board.SPI()
21# bme_cs = digitalio.DigitalInOut(board.D10)
22# bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs)
23
24# Change this to match the location's pressure (hPa) at sea level
25bme280.sea_level_pressure = 1013.25
26bme280.mode = adafruit_bme280.MODE_NORMAL
27bme280.standby_period = adafruit_bme280.STANDBY_TC_500
28bme280.iir_filter = adafruit_bme280.IIR_FILTER_X16
29bme280.overscan_pressure = adafruit_bme280.OVERSCAN_X16
30bme280.overscan_humidity = adafruit_bme280.OVERSCAN_X1
31bme280.overscan_temperature = adafruit_bme280.OVERSCAN_X2
32# The sensor will need a moment to gather initial readings
33time.sleep(1)
34
35while True:
36    print("\nTemperature: %0.1f C" % bme280.temperature)
37    print("Humidity: %0.1f %%" % bme280.relative_humidity)
38    print("Pressure: %0.1f hPa" % bme280.pressure)
39    print("Altitude = %0.2f meters" % bme280.altitude)
40    time.sleep(2)

RP Pico Example

Example showing how the BME280 library using a RP Pico

examples/bme280_simpletest_pico.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import time
 5import board
 6import busio
 7from adafruit_bme280 import basic as adafruit_bme280
 8
 9# Create sensor object, using the board's default I2C bus.
10i2c = busio.I2C(board.GP1, board.GP0)  # SCL, SDA
11bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
12
13# OR create sensor object, using the board's default SPI bus.
14# spi = busio.SPI(board.GP2, MISO=board.GP0, MOSI=board.GP3)
15# bme_cs = digitalio.DigitalInOut(board.GP1)
16# bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs)
17
18# change this to match the location's pressure (hPa) at sea level
19bme280.sea_level_pressure = 1013.25
20
21while True:
22    print("\nTemperature: %0.1f C" % bme280.temperature)
23    print("Humidity: %0.1f %%" % bme280.relative_humidity)
24    print("Pressure: %0.1f hPa" % bme280.pressure)
25    print("Altitude = %0.2f meters" % bme280.altitude)
26    time.sleep(2)