def __init__(self, sensor_pin): """docstring for .""" self.sensor_pin = sensor_pin self.spi = busio.SPI(board.SCK, board.MOSI, board.MISO) self.bmp_cs = digitalio.DigitalInOut(self.sensor_pin) self.bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI( self.spi, self.bmp_cs) self.bmp280.sea_level_pressure = 1013.25
def get_bmp280_data(): spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) cs = digitalio.DigitalInOut(board.D4) bmp280_sensor = adafruit_bmp280.Adafruit_BMP280_SPI(spi, cs) print("Reading temperature from BMP280") temperature = bmp280_sensor.temperature * 1.8 + 32.0 print("Reading pressure from BMP280") pressure = bmp280_sensor.pressure return (temperature, pressure)
import math import statistics #1 alarmBuzzer = digitalio.DigitalInOut(board.D12) alarmBuzzer.direction = digitalio.Direction.OUTPUT alarmBuzzer.value = False plt.style.use('ggplot') print('set up sensors...') spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) print('init sensor 1') cs1 = digitalio.DigitalInOut(board.D5) print('init sensor 2') cs2 = digitalio.DigitalInOut(board.D6) sensor1 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, cs1) sensor2 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, cs2) # print('test sensors') # print('sensor1 pressure: ', sensor1.pressure) # print('sensor2 pressure: ', sensor2.pressure) #constants used in flow calculation print('set up constants for flow...') beta = 0.54545 #ratio of d/D little diameter to big diameter beta_thing = 1.047432587 #saves recalculating coeff = 1.0 area = 0.0001130973 rho = 1.204 time_now = 0
import time import board import digitalio # For use with SPI import busio import adafruit_bmp280 # Create library object using our Bus I2C port # i2c = busio.I2C(board.SCL, board.SDA) # bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c) # OR create library object using our Bus SPI port spi = busio.SPI(board.SCK, board.MOSI, board.MISO) bmp_cs = digitalio.DigitalInOut(board.D5) bmp280 = adafruit_bmp280.Adafruit_BMP280_SPI(spi, bmp_cs) # change this to match the location's pressure (hPa) at sea level bmp280.sea_level_pressure = 1013.25 def get_measurements(): try: temperature = bmp280.temperature return { 'altitude': bmp280.altitude, # meters 'pressure': bmp280.pressure, # hPa 'temperature_c': temperature, 'temperature_f': temperature * (9 / 5) + 32 } except Exception as error: