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
14bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
15
16# OR Create sensor object, communicating over the board's default SPI bus
17# spi = board.SPI()
18# bmp_cs = digitalio.DigitalInOut(board.D10)
19# bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, bmp_cs)
20
21# change this to match the location's pressure (hPa) at sea level
22bmp280.sea_level_pressure = 1013.25
23
24while True:
25    print("\nTemperature: %0.1f C" % bmp280.temperature)
26    print("Pressure: %0.1f hPa" % bmp280.pressure)
27    print("Altitude = %0.2f meters" % bmp280.altitude)
28    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
15bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
16
17# OR Create sensor object, communicating over the board's default SPI bus
18# spi = busio.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
24bmp280.mode = adafruit_bmp280.MODE_NORMAL
25bmp280.standby_period = adafruit_bmp280.STANDBY_TC_500
26bmp280.iir_filter = adafruit_bmp280.IIR_FILTER_X16
27bmp280.overscan_pressure = adafruit_bmp280.OVERSCAN_X16
28bmp280.overscan_temperature = adafruit_bmp280.OVERSCAN_X2
29# The sensor will need a moment to gather inital readings
30time.sleep(1)
31
32while True:
33    print("\nTemperature: %0.1f C" % bmp280.temperature)
34    print("Pressure: %0.1f hPa" % bmp280.pressure)
35    print("Altitude = %0.2f meters" % bmp280.altitude)
36    time.sleep(2)