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