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
10# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
11bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
12
13# OR create sensor object, using the board's default SPI bus.
14# spi = board.SPI()
15# bme_cs = digitalio.DigitalInOut(board.D10)
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)

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
15# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
16bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
17
18# OR create sensor object, using the board's default SPI bus.
19# SPI setup
20# from digitalio import DigitalInOut
21# spi = board.SPI()
22# bme_cs = digitalio.DigitalInOut(board.D10)
23# bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs)
24
25# Change this to match the location's pressure (hPa) at sea level
26bme280.sea_level_pressure = 1013.25
27bme280.mode = adafruit_bme280.MODE_NORMAL
28bme280.standby_period = adafruit_bme280.STANDBY_TC_500
29bme280.iir_filter = adafruit_bme280.IIR_FILTER_X16
30bme280.overscan_pressure = adafruit_bme280.OVERSCAN_X16
31bme280.overscan_humidity = adafruit_bme280.OVERSCAN_X1
32bme280.overscan_temperature = adafruit_bme280.OVERSCAN_X2
33# The sensor will need a moment to gather initial readings
34time.sleep(1)
35
36while True:
37    print("\nTemperature: %0.1f C" % bme280.temperature)
38    print("Humidity: %0.1f %%" % bme280.relative_humidity)
39    print("Pressure: %0.1f hPa" % bme280.pressure)
40    print("Altitude = %0.2f meters" % bme280.altitude)
41    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)