bmp280_simpletest.py
1 """Simpletest Example that shows how to get temperature, 2 pressure, and altitude readings from a BMP280""" 3 import time 4 import board 5 6 # import digitalio # For use with SPI 7 import busio 8 import adafruit_bmp280 9 10 # Create library object using our Bus I2C port 11 i2c = busio.I2C(board.SCL, board.SDA) 12 bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c) 13 14 # OR create library object using our Bus SPI port 15 # spi = busio.SPI(board.SCK, board.MOSI, board.MISO) 16 # bmp_cs = digitalio.DigitalInOut(board.D10) 17 # bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, bmp_cs) 18 19 # change this to match the location's pressure (hPa) at sea level 20 bmp280.sea_level_pressure = 1013.25 21 22 while True: 23 print("\nTemperature: %0.1f C" % bmp280.temperature) 24 print("Pressure: %0.1f hPa" % bmp280.pressure) 25 print("Altitude = %0.2f meters" % bmp280.altitude) 26 time.sleep(2)