Simple test

Ensure your device works with this simple test.

examples/bmp280_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""Simpletest Example that shows how to get temperature,
 5   pressure, and altitude readings from a BMP280"""
 6import time
 7import board
 8
 9# import digitalio # For use with SPI
10import adafruit_bmp280
11
12# Create sensor object, communicating over the board's default I2C bus
13i2c = board.I2C()  # uses board.SCL and board.SDA
14# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
15bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
16
17# OR Create sensor object, communicating over the board's default SPI bus
18# spi = board.SPI()
19# bmp_cs = digitalio.DigitalInOut(board.D10)
20# bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, bmp_cs)
21
22# change this to match the location's pressure (hPa) at sea level
23bmp280.sea_level_pressure = 1013.25
24
25while True:
26    print("\nTemperature: %0.1f C" % bmp280.temperature)
27    print("Pressure: %0.1f hPa" % bmp280.pressure)
28    print("Altitude = %0.2f meters" % bmp280.altitude)
29    time.sleep(2)

Normal Mode

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

examples/bmp280_normal_mode.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5Example showing how the BMP280 library can be used to set the various
 6parameters supported by the sensor.
 7Refer to the BMP280 datasheet to understand what these parameters do
 8"""
 9import time
10import board
11import adafruit_bmp280
12
13# Create sensor object, communicating over 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
16bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
17
18# OR Create sensor object, communicating over the board's default SPI bus
19# spi = busio.SPI()
20# bmp_cs = digitalio.DigitalInOut(board.D10)
21# bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, bmp_cs)
22
23# change this to match the location's pressure (hPa) at sea level
24bmp280.sea_level_pressure = 1013.25
25bmp280.mode = adafruit_bmp280.MODE_NORMAL
26bmp280.standby_period = adafruit_bmp280.STANDBY_TC_500
27bmp280.iir_filter = adafruit_bmp280.IIR_FILTER_X16
28bmp280.overscan_pressure = adafruit_bmp280.OVERSCAN_X16
29bmp280.overscan_temperature = adafruit_bmp280.OVERSCAN_X2
30# The sensor will need a moment to gather inital readings
31time.sleep(1)
32
33while True:
34    print("\nTemperature: %0.1f C" % bmp280.temperature)
35    print("Pressure: %0.1f hPa" % bmp280.pressure)
36    print("Altitude = %0.2f meters" % bmp280.altitude)
37    time.sleep(2)