def start(self): """ Setup the BMP280 sensor driver. :return: """ # Ensure a bus object exists and is ready. self.ensure_bus() # Initialize the hardware driver. try: # MicroPython # https://github.com/dafvid/micropython-bmp280 # Adafruit CircuitPython if platform_info.vendor == platform_info.MICROPYTHON.RaspberryPi: import adafruit_bmp280 self.driver = adafruit_bmp280.Adafruit_BMP280_I2C( i2c=self.bus.adapter, address=self.address) else: raise NotImplementedError( 'BMP280 driver not implemented on this platform') return True except Exception as ex: log.exc(ex, 'BMP280 hardware driver failed') return False
def _connect_to_hardware(self): import board import busio import adafruit_bmp280 i2c = busio.I2C(board.SCL, board.SDA) #bmp280.sea_level_pressure = 1013.25 self.sensor = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, 0x76)
def __init__(self): # Define I2C: self._i2c = board.I2C() # Define touch: # Initially, self._touches stores the pin used for a particular touch. When that touch is # used for the first time, the pin is replaced with the corresponding TouchIn object. # This saves a little RAM over using a separate read-only pin tuple. # For example, after `clue.touch_2`, self._touches is equivalent to: # [board.D0, board.D1, touchio.TouchIn(board.D2)] self._touches = [board.D0, board.D1, board.D2] self._touch_threshold_adjustment = 0 # Define buttons: self._a = digitalio.DigitalInOut(board.BUTTON_A) self._a.switch_to_input(pull=digitalio.Pull.UP) self._b = digitalio.DigitalInOut(board.BUTTON_B) self._b.switch_to_input(pull=digitalio.Pull.UP) self._gamepad = gamepad.GamePad(self._a, self._b) # Define LEDs: self._white_leds = digitalio.DigitalInOut(board.WHITE_LEDS) self._white_leds.switch_to_output() self._pixel = neopixel.NeoPixel(board.NEOPIXEL, 1) self._red_led = digitalio.DigitalInOut(board.L) self._red_led.switch_to_output() # Define audio: self._mic = audiobusio.PDMIn( board.MICROPHONE_CLOCK, board.MICROPHONE_DATA, sample_rate=16000, bit_depth=16, ) self._sample = None self._samples = None self._sine_wave = None self._sine_wave_sample = None # Define sensors: # Accelerometer/gyroscope: self._accelerometer = adafruit_lsm6ds.LSM6DS33(self._i2c) # Magnetometer: self._magnetometer = adafruit_lis3mdl.LIS3MDL(self._i2c) # DGesture/proximity/color/light sensor: self._sensor = adafruit_apds9960.apds9960.APDS9960(self._i2c) # Humidity sensor: self._humidity = adafruit_sht31d.SHT31D(self._i2c) # Barometric pressure sensor: self._pressure = adafruit_bmp280.Adafruit_BMP280_I2C(self._i2c) # Create displayio object for passing. self.display = board.DISPLAY
def __init__(self, i2c): self._sensor = adafruit_bmp280.Adafruit_BMP280_I2C(i2c) self._sensor.sea_level_pressure = 1013.25 self._sensor.mode = adafruit_bmp280.MODE_NORMAL self._sensor.standby_period = adafruit_bmp280.STANDBY_TC_500 self._sensor.iir_filter = adafruit_bmp280.IIR_FILTER_X16 self._sensor.overscan_pressure = adafruit_bmp280.OVERSCAN_X16 self._sensor.overscan_temperature = adafruit_bmp280.OVERSCAN_X2 self._altitude = 0
def BuildBMP280BarometerSensor(self, sensorType, i2c): try: if self.bmp280 == None: self.bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(self.i2c) sensor = bmp280BarometerSensor(self.bmp280) except ValueError: log.error(sensorType + " sensor not found") self.bmp280 = None sensor = None return sensor
def __init__(self, sea_level): self.error = False self.offset = 0 try: # self.bmp_280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c) self.bmp_280.sea_level_pressure = sea_level except: self.error = True
def start(self): try: # Create library object using our Bus I2C port i2c = busio.I2C(board.SCL, board.SDA) self.bmp_i2c = adafruit_bmp280.Adafruit_BMP280_I2C( i2c, address=self.address) except Exception as e: raise e else: # change this to match the location's pressure (hPa) at sea level self.bmp_i2c.sea_level_pressure = self.sea_level_pressure self.active = True
def _init_sensor(self): """ Initialize sensor (simply save the module), no complicated init needed. """ # use the old Adafruit driver, the new one is more unstable import adafruit_bmp280 import board # pylint: disable=import-outside-toplevel i2c = board.I2C() # uses board.SCL and board.SDA self._sensor_driver = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, address=0x76) # change this to match the location's pressure (hPa) at sea level weather = self._comps.weather_info.get_current_weather() if weather: self._sensor_driver.sea_level_pressure = weather.pressure_sea_level
def __init__(self): # Define I2C: self._i2c = cutebot._i2c # Define buttons: self._a = digitalio.DigitalInOut(board.BUTTON_A) self._a.switch_to_input(pull=digitalio.Pull.UP) self._b = digitalio.DigitalInOut(board.BUTTON_B) self._b.switch_to_input(pull=digitalio.Pull.UP) self._gamepad = gamepad.GamePad(self._a, self._b) # Define LEDs: self._white_leds = digitalio.DigitalInOut(board.WHITE_LEDS) self._white_leds.switch_to_output() self._pixel = neopixel.NeoPixel(board.NEOPIXEL, 1) self._red_led = digitalio.DigitalInOut(board.L) self._red_led.switch_to_output() # Define audio: self._mic = audiobusio.PDMIn( board.MICROPHONE_CLOCK, board.MICROPHONE_DATA, sample_rate=16000, bit_depth=16, ) self._sample = None self._samples = None self._sine_wave = None self._sine_wave_sample = None # Define sensors: # Accelerometer/gyroscope: self._accelerometer = adafruit_lsm6ds.lsm6ds33.LSM6DS33(self._i2c) # Magnetometer: self._magnetometer = adafruit_lis3mdl.LIS3MDL(self._i2c) # DGesture/proximity/color/light sensor: self._sensor = adafruit_apds9960.apds9960.APDS9960(self._i2c) # Humidity sensor: self._humidity = adafruit_sht31d.SHT31D(self._i2c) # Barometric pressure sensor: self._pressure = adafruit_bmp280.Adafruit_BMP280_I2C(self._i2c) # Create displayio object for passing. self.display = board.DISPLAY
def detect_pressure_bmp280(self): try: import board import busio import adafruit_bmp280 i2c = busio.I2C(board.SCL, board.SDA) #device test self.sensor_bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c) self.sensor_bmp280.mode = adafruit_bmp280.MODE_NORMAL self.sensor_bmp280.standby_period = adafruit_bmp280.STANDBY_TC_250 self.sensor_bmp280.iir_filter = adafruit_bmp280.IIR_FILTER_X16 self.sensor_bmp280.overscan_pressure = adafruit_bmp280.OVERSCAN_X16 self.sensor_bmp280.overscan_temperature = adafruit_bmp280.OVERSCAN_X1 return True except: return False
def __init__(self): self._i2c = busio.I2C(board.SCL, board.SDA) self._bmp_sensor = adafruit_bmp280.Adafruit_BMP280_I2C(i2c=self._i2c) # change BMP280_LOCAL_SEA_LEVEL in .env to match the location's pressure (hPa) at sea level self._local_sea_level = env.float("BMP280_LOCAL_SEA_LEVEL", default=None) # Set location's pressure (hPa) at sea level if self._local_sea_level is not None: self._bmp_sensor.seaLevelhPa = self._local_sea_level else: raise ValueError( "BMP280: Necessary to inform location's pressure (in hPa) at sea level" )
def __init__(self): try: i2c = board.I2C() # Creamos el constructor que lee los datos sensor = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, address=0x76) # Se le suma 8 a la presión porque tras meses de pruebas se observa que # el sensor venia mal calibrado. self.atm = sensor.pressure self.temperatura = sensor.temperature # Recoge el error de lectura del canal SDA except OSError: logging.error('El sensor BMP280 ha dejado de funcionar.') self.atm = -100 self.temperatura = -100
def getSensors(self): sensors = [] # Create library object using our Bus I2C port i2c = busio.I2C(board.SCL, board.SDA) bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c) if "config" in self.sensorData: if "seaLevel" in self.sensorData["config"]: bmp280.seaLevelhPa = self.sensorData["config"]["seaLevel"] if "read" in self.sensorData["config"]: for readConfig in self.sensorData["config"]["read"]: if readConfig == "temperature": sensors.append( self.__createSensor("temperature", bmp280.temperature)) elif readConfig == "pressure": sensors.append( self.__createSensor("pressure", bmp280.pressure)) return sensors
def detect_pressure_bmp280(self): try: import board import busio import adafruit_bmp280 i2c = busio.I2C(board.SCL, board.SDA) #device test self.sensor_bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c) self.sensor_bmp280.mode = adafruit_bmp280.MODE_NORMAL #STANDBY_TC_0_5, STANDBY_TC_10, STANDBY_TC_20, STANDBY_TC_62_5, #STANDBY_TC_125, STANDBY_TC_250, STANDBY_TC_500, STANDBY_TC_1000, self.sensor_bmp280.standby_period = adafruit_bmp280.STANDBY_TC_250 #IIR_FILTER_DISABLE, IIR_FILTER_X2, IIR_FILTER_X4, IIR_FILTER_X8, IIR_FILTER_X16, self.sensor_bmp280.iir_filter = adafruit_bmp280.IIR_FILTER_X2 #OVERSCAN_DISABLE, OVERSCAN_X1, OVERSCAN_X2, OVERSCAN_X4, OVERSCAN_X8, OVERSCAN_X16 self.sensor_bmp280.overscan_pressure = adafruit_bmp280.OVERSCAN_X8 self.sensor_bmp280.overscan_temperature = adafruit_bmp280.OVERSCAN_X1 return True except: return False
def main(): # initialize I2C i2c = board.I2C() # initialize sensors bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c) sht31d = adafruit_sht31d.SHT31D(i2c) # initialize BLE ble = BLERadio() # create custom advertisement object advertisement = IOTGAdvertisement() # set device name ble.name = "IOTG1" # set initial value # will use only first 5 chars of name advertisement.md_field = ble.name[:5] + "0000" # BLRE advertising interval in seconds BLE_ADV_INT = 0.2 # start BLE advertising ble.start_advertising(advertisement, interval=BLE_ADV_INT) # main loop while True: # print values - this will be available on serial print("Temperature: {:.1f} C".format(bmp280.temperature)) print("Humidity: {:.1f} %".format(sht31d.relative_humidity)) # get sensor data T = int(bmp280.temperature) H = int(sht31d.relative_humidity) # stop advertsing ble.stop_advertising() # update advertisement data advertisement.md_field = ble.name[:5] + chr(T) + chr(H) + "00" # start advertising ble.start_advertising(advertisement, interval=BLE_ADV_INT) # sleep for 2 seconds time.sleep(2)
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT """Simpletest Example that shows how to get temperature, pressure, and altitude readings from a BMP280""" 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.D10) # 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 while True: print("\nTemperature: %0.1f C" % bmp280.temperature) print("Pressure: %0.1f hPa" % bmp280.pressure) print("Altitude = %0.2f meters" % bmp280.altitude) time.sleep(2)
def setup(self, log_type): super().setup(log_type) i2c = busio.I2C(board.SCL, board.SDA) self.bridge = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
import decimal import _thread import threading from digitalio import DigitalInOut, Direction, Pull DataQueue = queue.Queue() PacketCount = 0 BackupFile = "/home/pi/BackUpData.txt" BackupDataFile = "" ErrorFile = "/home/pi/ErrorLog.txt" ErrorDataFile = "" try: i2c = busio.I2C(board.SCL, board.SDA) bmpSensor = adafruit_bmp280.Adafruit_BMP280_I2C(i2c) orientationSensor = adafruit_bno055.BNO055_I2C(i2c) CS = DigitalInOut(board.CE1) RESET = DigitalInOut(board.D25) spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, 915.0) rfm9x.tx_power = 23 print('RFM9x: Detected') # Inform UI except RuntimeError as error: print('Sensor error: ' + error) #Inform UI ErrorLog(error) CloseFiles()
from senserv.sensor_wrapper import * from .locatino import Location location = Location() template = "simple_white" print(socket.gethostname()) if socket.gethostname() == "roomba": import board import busio import adafruit_ahtx0 import adafruit_bmp280 sensor = AHT(adafruit_ahtx0.AHTx0(board.I2C())) i2c = busio.I2C(board.SCL, board.SDA) sensor2 = BMP(adafruit_bmp280.Adafruit_BMP280_I2C(i2c)) sl = SensorsSystem([sensor, sensor2], location=location, interval=30) else: test_sensors = SensorWrapper(TestSensor(), ["temperature", "pressure"]), SensorWrapper( TestSensor2(), ["temperature", "humidity"]) sl = SensorsSystem(test_sensors) external_stylesheets = [ dbc.themes.BOOTSTRAP, 'https://codepen.io/chriddyp/pen/bWLwgP.css' ] app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
import digitalio from PIL import Image, ImageDraw, ImageFont import adafruit_bmp280 # from tkinter import * import tkinter as tk import board import busio #initiliaze the i2c connection using the scl and sda pins 3&5 on the pi i2c = busio.I2C(board.SCL,board.SDA) #set the reset pin rest_pin = digitalio.DigitalInOut(board.D4) # init the firmware for the oled oled = adafruit_ssd1306.SSD1306_I2C(128,32,i2c,reset=rest_pin) # create the bmp pressure sensor object pressSen= adafruit_bmp280.Adafruit_BMP280_I2C(i2c) # this sets the sea level pressure for altitude calculation reletive the mean global sea leavel #pressure is 1013.25 using the local value would in crease accuracy pressSen.sea_level_pressure = 1024 counter = -1 running = False displayType = 0 dist=20 start_alt = pressSen.altitude class TimeKeeper: start =0 current =-1 def __init__(self,) -> None: self.start = time.monotonic()
def __init__(self): self._sensor = adafruit_bmp280.Adafruit_BMP280_I2C( i2c=busio.I2C(24, 23), address=0x76)
def run(self): log('info', "Starting " + self.name) global eqLogic, JeedomIP, TempoPinLOW, TempoPinHIGH, exit, Status_pins, swtch, GPIO, SetAllLOW, SetAllHIGH, CounterPinValue, s, BootMode, SetAllSWITCH, SetAllPulseLOW, SetAllPulseHIGH, ProbeDelay, thread_1, thread_2, thread_tries1, bmp180, bmp280, bme280, bme680, bmp280b, bme280b, bme680b, gpioSET, sendPINMODE, busio, CptNextReArm, ReArmDelay s = socket.socket() # Create a socket object s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) #host = socket.gethostname() # Get local machine name try: s.bind(('', port)) # Bind to the port except: s.close() # rate log('erreur', 'Le port est peut-etre utilise. Nouvel essai dans 11s.') SimpleSend('&PORTISUSED=' + str(port)) time.sleep(11) # on attend un peu s = socket.socket() s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) try: s.bind(('', port)) # nouvel essai except: s.close() # rate log( 'erreur', 'Le port est probablement utilise. Nouvel essai en mode auto dans 7s.' ) SimpleSend('&PORTINUSE=' + str(port)) time.sleep(7) # on attend encore un peu s = socket.socket() s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) portnew = 0 try: s.bind(('', 0)) # on essai en auto decouverte addr, portnew = s.getsockname() log('debug', 'Un port libre est disponible : ' + str(portnew)) SimpleSend('&PORTFOUND=' + str(portnew)) except: log( 'erreur', 'Impossible de trouver un port automatiquement. Veuillez en choisir un autre' ) SimpleSend('&NOPORTFOUND=' + str(port)) s.close() exit = 1 raise e s.listen(5) # Now wait for client connection. while exit == 0: thread_1 = 1 c, addr = s.accept() # Establish connection with client. if exit == 1: break m = c.recv(1024) thread_tries1 = 0 query = SimpleParse(m) if query: log('Requete', str(query)) reponse = 'NOK' exit = 0 RepStr = '' GPIOStr = '' if 'BootMode' in query: q = query.index("BootMode") BootMode = int(query[q + 1]) reponse = 'BMOK' if 'ConfigurePins' in query: q = query.index("ConfigurePins") Status_pins = query[q + 1] sendPINMODE = 1 for i in range(0, 40): #j=i+1 j = pin2gpio[i] if Status_pins[i] == 'o' or Status_pins[ i] == 'y' or Status_pins[ i] == 's' or Status_pins[ i] == 'l' or Status_pins[ i] == 'h' or Status_pins[ i] == 'u' or Status_pins[ i] == 'v' or Status_pins[ i] == 'w': GPIO.setup(j, GPIO.OUT) GPIO.remove_event_detect(j) GPIO.output(j, BootMode) swtch[i + 1] = BootMode GPIOStr += '&' + str(i + 1) + '=' + str(BootMode) elif Status_pins[i] == 'p': GPIO.setup(j, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.remove_event_detect(j) GPIO.add_event_detect(j, GPIO.BOTH, callback=toggle_inputs) GPIOStr += '&IN_' + str(i + 1) + '=' + str( GPIO.input(j)) elif Status_pins[i] == 'c': k = i % 4 GPIO.setup(j, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.remove_event_detect(j) if k == 1: GPIO.add_event_detect(j, GPIO.BOTH, callback=toggle_cpts1) elif k == 2: GPIO.add_event_detect(j, GPIO.BOTH, callback=toggle_cpts2) elif k == 3: GPIO.add_event_detect(j, GPIO.BOTH, callback=toggle_cpts3) else: GPIO.add_event_detect(j, GPIO.BOTH, callback=toggle_cpts0) time.sleep(0.1) elif Status_pins[i] == 'G': k = i % 4 GPIO.setup(j, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.remove_event_detect(j) if k == 1: GPIO.add_event_detect(j, GPIO.BOTH, callback=toggle_cpts1) elif k == 2: GPIO.add_event_detect(j, GPIO.BOTH, callback=toggle_cpts2) elif k == 3: GPIO.add_event_detect(j, GPIO.BOTH, callback=toggle_cpts3) else: GPIO.add_event_detect(j, GPIO.BOTH, callback=toggle_cpts0) time.sleep(0.1) elif Status_pins[i] == 'n': GPIO.setup(j, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.remove_event_detect(j) GPIO.add_event_detect(j, GPIO.RISING, callback=toggle_inputs) elif Status_pins[i] == 'q': GPIO.setup(j, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.remove_event_detect(j) GPIO.add_event_detect(j, GPIO.FALLING, callback=toggle_inputs) elif Status_pins[i] == 'i': GPIO.setup(j, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.remove_event_detect(j) GPIO.add_event_detect(j, GPIO.BOTH, callback=toggle_inputs) GPIOStr += '&IN_' + str(i + 1) + '=' + str( GPIO.input(j)) elif Status_pins[i] == 'd' or Status_pins[ i] == 'f': # Sondes DHT(11,22) GPIO.setup(j, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.remove_event_detect(j) elif Status_pins[i] == 'b': # Sondes DS18b20 GPIO.setup(j, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.remove_event_detect(j) sensors[i] = DS.scan(pin2gpio[i]) elif Status_pins[ i] == 't': #HC-SR04 Declencheur (Trigger pin) GPIO.setup(j, GPIO.OUT) GPIO.remove_event_detect(j) GPIO.output(j, False) elif Status_pins[ i] == 'z': #HC-SR04 Distance (Echo pin) GPIO.setup(j, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.remove_event_detect(j) elif Status_pins[i] == 'r': bmp180 = BMP085.BMP085() elif Status_pins[i] == 'A': i2c = busio.I2C(board.SCL, board.SDA) try: bme280 = adafruit_bme280.Adafruit_BME280_I2C( i2c, 118) # hex76 = 118 except: bme280 = adafruit_bme280.Adafruit_BME280_I2C( i2c) #hex77 default bme280.sea_level_pressure = 1013.25 elif Status_pins[i] == 'D': i2c = busio.I2C(board.SCL, board.SDA) try: bme280b = adafruit_bme280.Adafruit_BME280_I2C( i2c) #hex77 default except: bme280b = adafruit_bme280.Adafruit_BME280_I2C( i2c, 118) # hex76 = 118 bme280b.sea_level_pressure = 1013.25 elif Status_pins[i] == 'B': i2c = busio.I2C(board.SCL, board.SDA) try: bme680 = adafruit_bme680.Adafruit_BME680_I2C( i2c, 118, debug=False) except: bme680 = adafruit_bme680.Adafruit_BME680_I2C( i2c, debug=False) bme680.sea_level_pressure = 1013.25 elif Status_pins[i] == 'E': i2c = busio.I2C(board.SCL, board.SDA) try: bme680b = adafruit_bme680.Adafruit_BME680_I2C( i2c, debug=False) except: bme680b = adafruit_bme680.Adafruit_BME680_I2C( i2c, 118, debug=False) bme680b.sea_level_pressure = 1013.25 elif Status_pins[i] == 'C': i2c = busio.I2C(board.SCL, board.SDA) try: bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C( i2c, 118) except: bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C( i2c) bmp280.sea_level_pressure = 1013.25 elif Status_pins[i] == 'F': i2c = busio.I2C(board.SCL, board.SDA) try: bmp280b = adafruit_bmp280.Adafruit_BMP280_I2C( i2c) except: bmp280b = adafruit_bmp280.Adafruit_BMP280_I2C( i2c, 118) bmp280b.sea_level_pressure = 1013.25 reponse = 'C*K' RepStr = '&REP=' + str(reponse) + GPIOStr gpioSET = True if 'eqLogic' in query: q = query.index("eqLogic") eqLogic = query[q + 1] reponse = 'EOK' #SimpleSend('&REP=' + str(reponse)) if 'JeedomIP' in query: q = query.index("JeedomIP") JeedomIP = query[q + 1] reponse = 'IPOK' #SimpleSend('&REP=' + str(reponse)) if 'SetPinLOW' in query: q = query.index("SetPinLOW") u = int(query[q + 1]) reponse = 'SOK' SetPin(u, 0, reponse) if 'SetPinHIGH' in query: q = query.index("SetPinHIGH") u = int(query[q + 1]) reponse = 'SOK' SetPin(u, 1, reponse) if 'SetLOWpulse' in query: q = query.index("SetLOWpulse") u = int(query[q + 1]) q = query.index("tempo") TempoPinLOW[u] = time.time() * 10 + int(query[q + 1]) reponse = 'SOK' SetPin(u, 0, reponse) if 'SetHIGHpulse' in query: q = query.index("SetHIGHpulse") u = int(query[q + 1]) q = query.index("tempo") TempoPinHIGH[u] = time.time() * 10 + int(query[q + 1]) reponse = 'SOK' SetPin(u, 1, reponse) if 'SwitchPin' in query: q = query.index("SwitchPin") u = int(query[q + 1]) v = 1 - swtch[u] reponse = 'SOK' SetPin(u, v, reponse) if 'SetCPT' in query: q = query.index("SetCPT") u = int(query[q + 1]) q = query.index("ValCPT") ValCPT = int(query[q + 1]) CounterPinValue[u] += ValCPT reponse = 'SCOK' RepStr = '&REP=' + str(reponse) if 'RazCPT' in query: q = query.index("RazCPT") u = int(query[q + 1]) q = query.index("ValCPT") ValCPT = int(query[q + 1]) CounterPinValue[u] = ValCPT reponse = 'SCOK' RepStr = '&REP=' + str(reponse) if 'SetAllLOW' in query: SetAllLOW = 1 # deport dans l'autre thread question de vitesse d'execution reponse = 'SOK' if 'SetAllHIGH' in query: SetAllHIGH = 1 # deport dans l'autre thread question de vitesse d'execution reponse = 'SOK' if 'SetAllSWITCH' in query: SetAllSWITCH = 1 # deport dans l'autre thread question de vitesse d'execution reponse = 'SOK' if 'SetAllPulseLOW' in query: RepStr = '&REP=SOK' q = query.index("tempo") for i in range(0, 40): j = i + 1 if Status_pins[i] == 'o' or Status_pins[ i] == 's' or Status_pins[ i] == 'l' or Status_pins[ i] == 'h' or Status_pins[ i] == 'u' or Status_pins[ i] == 'v' or Status_pins[ i] == 'w': swtch[j] = 0 GPIO.output(pin2gpio[i], 0) TempoPinLOW[j] = time.time() * 10 + int( query[q + 1]) RepStr += '&' + str(j) + '=0' reponse = 'SOK' if 'SetAllPulseHIGH' in query: RepStr = '&REP=SOK' q = query.index("tempo") for i in range(0, 40): j = i + 1 if Status_pins[i] == 'o' or Status_pins[ i] == 's' or Status_pins[ i] == 'l' or Status_pins[ i] == 'h' or Status_pins[ i] == 'u' or Status_pins[ i] == 'v' or Status_pins[ i] == 'w': swtch[j] = 1 GPIO.output(pin2gpio[i], 1) TempoPinHIGH[j] = time.time() * 10 + int( query[q + 1]) RepStr += '&' + str(j) + '=1' reponse = 'SOK' if 'Trigger' in query: q = query.index("Trigger") u = int(query[q + 1]) q = query.index("Echo") v = int(query[q + 1]) RepStr = GetDistance(u, v) reponse = 'SOK' if 'SetLOWdoublepulse' in query: q = query.index("SetLOWdoublepulse") u = int(query[q + 1]) r = pin2gpio[u - 1] q = query.index("tempclick") v = float(query[q + 1]) / 10 q = query.index("temppause") w = float(query[q + 1]) / 10 GPIO.output(r, 0) time.sleep(v) GPIO.output(r, 1) time.sleep(w) GPIO.output(r, 0) time.sleep(v) reponse = 'SOK' SetPin(u, 1, reponse) if 'SetHIGHdoublepulse' in query: q = query.index("SetHIGHdoublepulse") u = int(query[q + 1]) r = pin2gpio[u - 1] q = query.index("tempclick") v = float(query[q + 1]) / 10 q = query.index("temppause") w = float(query[q + 1]) / 10 GPIO.output(r, 1) time.sleep(v) GPIO.output(r, 0) time.sleep(w) GPIO.output(r, 1) time.sleep(v) reponse = 'SOK' SetPin(u, 0, reponse) if 'CptDelay' in query: q = query.index("CptDelay") ReArmDelay = int(query[q + 1]) reponse = 'SCOK' if 'ProbeDelay' in query: q = query.index("ProbeDelay") ProbeDelay = int(query[q + 1]) reponse = 'SOK' if 'PING' in query: if thread_2 == 1: reponse = 'PINGOK' else: reponse = 'PINGKO' RepStr = '&REP=' + str(reponse) if 'EXIT' in query: exit = 1 reponse = 'EXITOK' if reponse != '': c.send(reponse.encode('ascii')) log('>> Reponse a la requete', str(reponse)) if RepStr != '': SimpleSend(RepStr) if exit == 1: break c.close() time.sleep(0.1) s.close() if exit == 1: try: GPIO.cleanup() except: pass sys.exit()
import board #Modul, zur Kennzeichnung von Pins. import busio #Modul, zur Kommunikation über das IO. import adafruit_bmp280 #Modul, zum Kommunizieren mit dem BMP280 Sensor. from threading import Thread #Wird dazu verwendet, Funktionen asyncron aufzurufen. from ledController import farbeAnzeigen #Wird für die Ansteuerung der LED gebraucht. benutzeLED = True #Gibt an, ob die LED beim Lesen von Sensorendaten aufbliken soll. i2c = busio.I2C( board.SCL, board.SDA) #Konfiguration des I2C Ports mit den Daten des Raspberry Pis. bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C( i2c) #Verbinden mit dem BMP280 per I2C Port. #Für die Kalibrierung des Sensors wird der Druck auf der Seehöhe des Ortes in hPA benötigt. #Da aber Wien nicht die Seehöhe erreicht, wurde der Wert mit https://rechneronline.de/barometer/ berrechnet. #bmp280.sea_level_pressure = 1013.25 #Auskommentierter vorgeschlagener Wert des Moduls. bmp280.sea_level_pressure = 1005.8 def leseDaten(): [temperatur, druck, seehoehe] = leseBMP280() return [temperatur, druck, seehoehe, None] def leseBMP280(): if benutzeLED: #Die Funktion wird asyncron durch Threading aufgerufen, sodass in der Zwischenzeit gemessen werden kann. Thread(target=farbeAnzeigen, args=("gruen", 0.1)).start( ) #Zeigt mit einem grünen Blinken für eine Sekunde an, dass der BMP280 misst. temperatur = bmp280.temperature #Gibt die Temperatur in Grad Celcius zurück.
def work_BMP280(name, data): def getPaths(value, value2, key, offset, raw): Erg = '' if value2: try: value3 = float(value2) Erg += '{"path": "' + key + '","value":' + str(offset + value3) + '},' except: Erg += '{"path": "' + key + '","value":"' + str(value2) + '"},' else: Erg += '{"path": "' + key + '","value": null},' if raw and value: try: value4 = float(value) Erg += '{"path": "' + key + '.raw","value":' + str( value4) + '},' except: Erg += '{"path": "' + key + '.raw","value":"' + str( value) + '"},' return Erg pressureKey = data['data'][0]['SKkey'] temperatureKey = data['data'][1]['SKkey'] if pressureKey or temperatureKey: import adafruit_bmp280 address = data['address'] i2c = busio.I2C(board.SCL, board.SDA) sensor = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, address=int(address, 16)) if pressureKey: pressureRaw = data['data'][0]['raw'] pressureRate = data['data'][0]['rate'] pressureOffset = data['data'][0]['offset'] if temperatureKey: temperatureRaw = data['data'][1]['raw'] temperatureRate = data['data'][1]['rate'] temperatureOffset = data['data'][1]['offset'] sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) port = data['port'] tick1 = time.time() tick2 = tick1 while True: time.sleep(0.1) try: Erg = '' if pressureKey: tick0 = time.time() if tick0 - tick1 > pressureRate: try: pressureValue = round(sensor.pressure, 2) except: pressureValue = sensor.pressure try: pressureValue2 = float(pressureValue) * 100 except: pressureValue2 = '' Erg += getPaths(pressureValue, pressureValue2, pressureKey, pressureOffset, pressureRaw) tick1 = time.time() if temperatureKey: tick0 = time.time() if tick0 - tick2 > temperatureRate: try: temperatureValue = round(sensor.temperature, 1) except: temperatureValue = sensor.temperature try: temperatureValue2 = float( temperatureValue) + 273.15 except: temperatureValue2 = '' Erg += getPaths(temperatureValue, temperatureValue2, temperatureKey, temperatureOffset, temperatureRaw) tick2 = time.time() if Erg: SignalK = '{"updates":[{"$source":"OpenPlotter.I2C.' + name + '","values":[' SignalK += Erg[0:-1] + ']}]}\n' sock.sendto(SignalK.encode('utf-8'), ('127.0.0.1', port)) except Exception as e: print("BMP280 reading failed: " + str(e))
def __init__(self, addr, scl, sda, i2c_lock, sea_level_pressure): self._i2c_lock = i2c_lock i2c = busio.I2C(scl, sda) self._sensor = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, address=addr) self._sensor.sea_level_pressure = sea_level_pressure
from time import sleep import board import busio import adafruit_bmp280 bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(busio.I2C(board.SCL, board.SDA), 0x76) # change this to match the location's pressure (hPa) at sea level bmp280.sea_level_pressure = 992 while True: print("\nTemperature: %0.1f C" % bmp280.temperature) print("Pressure: %0.1f hPa" % bmp280.pressure) print("Altitude = %0.2f meters" % bmp280.altitude) time.sleep(2) #device.clear()
"""This uses the Feather Sense as a Bluetooth LE sensor node.""" import time import adafruit_ble_broadcastnet import board import adafruit_lsm6ds # accelerometer import adafruit_sht31d # humidity sensor import adafruit_bmp280 # barometric sensor import adafruit_lis3mdl # magnetic sensor i2c = board.I2C() sense_accel = adafruit_lsm6ds.LSM6DS33(i2c) sense_humid = adafruit_sht31d.SHT31D(i2c) sense_barometric = adafruit_bmp280.Adafruit_BMP280_I2C(i2c) sense_magnet = adafruit_lis3mdl.LIS3MDL(i2c) print("This is BroadcastNet Feather Sense sensor:", adafruit_ble_broadcastnet.device_address) while True: measurement = adafruit_ble_broadcastnet.AdafruitSensorMeasurement() measurement.temperature = sense_barometric.temperature measurement.pressure = sense_barometric.pressure measurement.relative_humidity = sense_humid.relative_humidity measurement.acceleration = sense_accel.acceleration measurement.magnetic = sense_magnet.magnetic # print(measurement) adafruit_ble_broadcastnet.broadcast(measurement)
import os import threading import board import busio import adafruit_ccs811 import adafruit_si7021 import adafruit_bmp280 app = Flask(__name__) api = Api(app) i2c = busio.I2C(board.SCL, board.SDA) ccs811 = adafruit_ccs811.CCS811(i2c) si7021 = adafruit_si7021.SI7021(i2c) bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, address=0x76) bmp280.sea_level_pressure = 1017 sensors = {} sensors['si7021'] = {'temperature': [], 'humidity': []} sensors['ccs811'] = {'co2': [], 'voc': []} sensors['bmp280'] = {'temperature': [], 'pressure': [], 'altitude': []} AVERAGE_PERIOD = 10 def update_si7021():
from adafruit_ble_adafruit.adafruit_service import AdafruitServerAdvertisement from adafruit_ble_adafruit.accelerometer_service import AccelerometerService from adafruit_ble_adafruit.addressable_pixel_service import AddressablePixelService from adafruit_ble_adafruit.barometric_pressure_service import BarometricPressureService from adafruit_ble_adafruit.button_service import ButtonService from adafruit_ble_adafruit.humidity_service import HumidityService from adafruit_ble_adafruit.light_sensor_service import LightSensorService from adafruit_ble_adafruit.microphone_service import MicrophoneService from adafruit_ble_adafruit.temperature_service import TemperatureService # Accelerometer lsm6ds33 = adafruit_lsm6ds.lsm6ds33.LSM6DS33(board.I2C()) # Used for pressure and temperature. bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(board.I2C()) # Humidity. sht31d = adafruit_sht31d.SHT31D(board.I2C()) # Used only for light sensor apds9960 = adafruit_apds9960.apds9960.APDS9960(board.I2C()) apds9960.enable_color = True mic = audiobusio.PDMIn( board.MICROPHONE_CLOCK, board.MICROPHONE_DATA, sample_rate=16000, bit_depth=16, ) # Create and initialize the available services.
- Write code to automatically change modes and maintain temperature - Redo display timeout menu - Add option for display timeout to be turned off ''' ##-------------------------------------------------------------------------------------## # Create I2C bus for use by BMP280 sensors & Multiplexer i2c = busio.I2C(board.SCL, board.SDA) # Create the TCA9548A object and give it the I2C bus tca = adafruit_tca9548a.TCA9548A(i2c) #Creating a dictionary to store temperature sensors SensorReaders = { 'tsl0': adafruit_bmp280.Adafruit_BMP280_I2C(tca[0], 0x76), 'tsl1': adafruit_bmp280.Adafruit_BMP280_I2C(tca[1], 0x76), 'tsl2': adafruit_bmp280.Adafruit_BMP280_I2C(tca[2], 0x76), 'tsl3': adafruit_bmp280.Adafruit_BMP280_I2C(tca[3], 0x76), 'tsl4': adafruit_bmp280.Adafruit_BMP280_I2C(tca[4], 0x76), 'tsl5': adafruit_bmp280.Adafruit_BMP280_I2C(tca[5], 0x76) } #Creating Temperature Variables StudioSensors = { 'Sensor0': 0, 'Sensor1': 0, 'Sensor2': 0, 'Sensor3': 0, 'Sensor4': 0, 'Sensor5': 0