bmp280_normal_mode.py
1 """ 2 Example showing how the BMP280 library can be used to set the various 3 parameters supported by the sensor. 4 Refer to the BMP280 datasheet to understand what these parameters do 5 """ 6 import time 7 8 import board 9 import busio 10 import adafruit_bmp280 11 12 # Create library object using our Bus I2C port 13 i2c = busio.I2C(board.SCL, board.SDA) 14 bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c) 15 16 # OR create library object using our Bus SPI port 17 # spi = busio.SPI(board.SCK, board.MOSI, board.MISO) 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 22 bmp280.sea_level_pressure = 1013.25 23 bmp280.mode = adafruit_bmp280.MODE_NORMAL 24 bmp280.standby_period = adafruit_bmp280.STANDBY_TC_500 25 bmp280.iir_filter = adafruit_bmp280.IIR_FILTER_X16 26 bmp280.overscan_pressure = adafruit_bmp280.OVERSCAN_X16 27 bmp280.overscan_temperature = adafruit_bmp280.OVERSCAN_X2 28 # The sensor will need a moment to gather inital readings 29 time.sleep(1) 30 31 while True: 32 print("\nTemperature: %0.1f C" % bmp280.temperature) 33 print("Pressure: %0.1f hPa" % bmp280.pressure) 34 print("Altitude = %0.2f meters" % bmp280.altitude) 35 time.sleep(2)