def get_device(name='pi'): reset_pin = None # If you have a GPIO, its not a bad idea to connect it to the RESET pin # reset_pin = DigitalInOut(board.G0) # reset_pin.direction = Direction.OUTPUT # reset_pin.value = False # For use with a computer running Windows: # import serial # uart = serial.Serial("COM30", baudrate=9600, timeout=1) # For use with microcontroller board: # (Connect the sensor TX pin to the board/computer RX pin) # uart = busio.UART(board.TX, board.RX, baudrate=9600) # For use with Raspberry Pi/Linux: # import serial # uart = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=0.25) # For use with USB-to-serial cable: # import serial # uart = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=0.25) # Connect to a PM2.5 sensor over UART # from adafruit_pm25.uart import PM25_UART # pm25 = PM25_UART(uart, reset_pin) # Create library object, use 'slow' 100KHz frequency! i2c = busio.I2C(board.SCL, board.SDA, frequency=100000) # Connect to a PM2.5 sensor over I2C pm25 = PM25_I2C(i2c, reset_pin) return name,pm25
def _create_device(self, channel, tca): self.pwr_pin.on() # NOTE: must allow device to be on for initialization time.sleep(2) try: device = PM25_I2C(tca[channel]) except OSError: # Try one more time self.pwr_pin.off() time.sleep(1) self.pwr_pin.on() time.sleep(2) try: device = PM25_I2C(tca[channel]) except Exception: raise OSError( f"Unable to initialize PM25 device. please double check {self.pwr_pin} is correct on/off pin" ) return device
def __init__(self, scl=board.SCL, sda=board.SDA, serial_no=None, channels=None, *args, **kwargs): i2c = busio.I2C(scl, sda, frequency=100000) # Connect to a PM2.5 sensor over I2C self.pm25 = PM25_I2C(i2c, None) self.type = __name__ super().__init__(serial_no, channels, *args, **kwargs)
import obdUtils RESET_PIN = None SENSOR_TYPE = 'AIR' ERROR = 'ERR' INFO = 'INFO' RETRY_INTERVAL = 1 #Delay in seconds when retrying to connect to node server DELAY = 1 #sensor polling interval in seconds. Max polling rate 1s for PMSA003I # Create library object, use 'slow' 100KHz frequency! i2c = busio.I2C(board.SCL, board.SDA, frequency=100000) # Connect to a PM2.5 sensor over I2C pm25 = PM25_I2C(i2c, RESET_PIN) sio = None numTries = 1 def emitAirSensorData(): while True: time.sleep(DELAY) try: aqdata = pm25.read() data = {'pm10': aqdata["pm10 standard"], 'pm25': aqdata["pm25 standard"], 'pm100': aqdata["pm100 standard"],
# For use with Raspberry Pi/Linux: # import serial # uart = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=0.25) # For use with USB-to-serial cable: # import serial # uart = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=0.25) # Connect to a PM2.5 sensor over UART # from adafruit_pm25.uart import PM25_UART # pm25 = PM25_UART(uart, reset_pin) # Create library object, use 'slow' 100KHz frequency! i2c = busio.I2C(board.SCL, board.SDA, frequency=100000) # Connect to a PM2.5 sensor over I2C pm25 = PM25_I2C(i2c, reset_pin) print("Found PM2.5 sensor, reading data...") while True: time.sleep(1) try: aqdata = pm25.read() # print(aqdata) except RuntimeError: print("Unable to read from sensor, retrying...") continue print() print("Concentration Units (standard)")
import board import asyncio import time import functools import json from aioinflux import InfluxDBClient from adafruit_pm25.i2c import PM25_I2C from sys import exit from weather import Weather i2c_bus = busio.I2C(board.SCL, board.SDA, frequency=100000) sgp30 = adafruit_sgp30.Adafruit_SGP30(i2c_bus) bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c_bus) pm25 = PM25_I2C(i2c_bus) weather = Weather() # You will usually have to add an offset to account for the temperature of # the sensor. This is usually around 5 degrees but varies by use. Use a # separate temperature sensor to calibrate this one. bme_temperature_offset = 5 HOST = '192.168.1.148' DB = 'airsensors' def run_in_executor(func): @functools.wraps(func) def inner(*args, **kwargs): loop = asyncio.get_running_loop() return loop.run_in_executor(None, lambda: func(*args, **kwargs)) return inner
ozone = dfrobot_ozone.DFRobot_Ozone(i2c) if ozone is not None: ozone.set_mode(dfrobot_ozone.MEASURE_MODE_AUTOMATIC) if LOAD_WATCHDOG: w.feed() if LOAD_PMSA003I: print("init pm25") display(0, "init pm25") link.log("info", "init pm25") link.sync() pm25 = None pm25 = PM25_I2C(i2c1, None) if LOAD_WATCHDOG: w.feed() display_page = 0 seq = 0 while True: display_page = (display_page + 1) % 6 t = time.monotonic_ns() data = []
# {"abbreviation":"CEST","client_ip":"84.198.207.226","datetime":"2021-04-26T10:38:58.027337+02:00","day_of_week":1,"day_of_year":116,"dst":true,"dst_from":"2021-03-28T01:00:00+00:00","dst_offset":3600,"dst_until":"2021-10-31T01:00:00+00:00","raw_offset":3600,"timezone":"Europe/Brussels","unixtime":1619426338,"utc_datetime":"2021-04-26T08:38:58.027337+00:00","utc_offset":"+02:00","week_number":17} if response.status_code == 200: utc_offset = 3600 if response.json()['utc_offset'] == '+02:00': utc_offset = 7200 r.datetime = time.localtime(response.json()['unixtime'] + utc_offset) # print(f"System Time: {r.datetime}") else: print("Setting time failed") # Setup Adafruit LC709203F LiPoly / LiIon Fuel Gauge and Battery Monitor sensor = LC709203F(board.I2C()) # Setup Adafruit PMSA003I Air Quality Breakout reset_pin = None pm25 = PM25_I2C(board.I2C(), reset_pin) # Setup Adafruit LTR390 UV Sensor #ltr = adafruit_ltr390.LTR390(board.I2C()) # Setup Adafruit Grayscale 1.5" 128x128 OLED Display WIDTH = 128 HEIGHT = 128 BORDER = 8 FONTSCALE = 1 displayio.release_displays() display_bus = displayio.I2CDisplay(board.I2C(), device_address=0x3D) display = adafruit_ssd1327.SSD1327(display_bus, width=128, height=128) splash = displayio.Group(max_size=10) display.show(splash) color_bitmap = displayio.Bitmap(display.width - BORDER * 2,
from gpiozero.pins.native import NativeFactory Device.pin_factory = NativeFactory() # Initialize I2C bus and sensor. i2c = busio.I2C(board.SCL, board.SDA) # mux tca2 = adafruit_tca9548a.TCA9548A(i2c, address=0x72) pwr_pin = DigitalOutputDevice(6) # each sensor pwr_pin.on() time.sleep(1) aq_sensor = PM25_I2C(tca2[2]) # pwr_pin.off() ignore for this example # spec: # https://cdn-shop.adafruit.com/product-files/4632/4505_PMSA003I_series_data_manual_English_V2.6.pdf # other information: # https://forums.adafruit.com/viewtopic.php?f=48&t=136528#p676664 # sampling rate 2.3 seconds def average_dict(v_dicts): # filter values with None for k_d, v_d in v_dicts.items(): if v_d: v_dicts[k_d] = {k: v for k, v in v_d.items() if v is not None}