def read(self, SIO): if self.pm25 is None: i2c = busio.I2C(board.SCL, board.SDA, frequency=100000) reset_pin = None self.pm25 = adafruit_pm25.PM25_I2C(i2c, reset_pin) self.t = time.time() try: self.aqdata = self.pm25.read() print("\nPMSA300I particulate matter readings:") for k in self.aqdata: print(" *", k, "\t", self.aqdata[k]) except: traceback.print_exc() self.aqdata = self.pm25 = None return SIO.log_readout(self.PM003_id, self.aqdata["particles 03um"], self.t) SIO.log_readout(self.PM005_id, self.aqdata["particles 05um"], self.t) SIO.log_readout(self.PM010_id, self.aqdata["particles 10um"], self.t) SIO.log_readout(self.PM025_id, self.aqdata["particles 25um"], self.t) SIO.log_readout(self.PM050_id, self.aqdata["particles 50um"], self.t) SIO.log_readout(self.PM100_id, self.aqdata["particles 100um"], self.t) # report mass densities exclusive of lower categories n1 = self.aqdata["pm10 env"] n2 = self.aqdata["pm25 env"] n3 = self.aqdata["pm100 env"] SIO.log_readout(self.PME10_id, n1, self.t) SIO.log_readout(self.PME25_id, n2 - n1, self.t) SIO.log_readout(self.PME100_id, n3 - n2, self.t)
def PM25() -> tuple: """ Gets the air quality for 1.0um, 2.5um, and 10.0um Arguments: None Returns: - pm 1.0, pm 2.5, pm 10.0 """ reset_pin = None try: # 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 = adafruit_pm25.PM25_I2C(i2c, reset_pin) aqdata = pm25.read() except RuntimeError: sys.exit(1) return aqdata["pm10 standard"], aqdata["pm25 standard"], aqdata[ "pm100 standard"]
# reset_pin.direction = Direction.OUTPUT # reset_pin.value = False clue_data = clue.simple_text_display(title="CLUE Sensor Data!", title_scale=2) # Create library object, use 'slow' 100KHz frequency! # ERROR: P19 IN USE, which is what board.SCL and board.SDA are referencing. Already set up in clue # library, so need to find the reference or move the example code into clue library so it can # reference the opened port within the scope of the library. # # That would make the lines here unneeded and instead just a clue_data[i] set of indexed data # populated by the library code that is connecting to the I2C bus and returning the parsed data. i2c = busio.I2C(board.SCL, board.SDA, frequency=100000) # Connect to a PM2.5 sensor over I2C pm25 = adafruit_pm25.PM25_I2C(i2c, reset_pin) print("Found PM2.5 sensor, reading data...") while True: clue_data[0].text = "Acceleration: {:.2f} {:.2f} {:.2f}".format( *clue.acceleration) clue_data[1].text = "Gyro: {:.2f} {:.2f} {:.2f}".format(*clue.gyro) clue_data[2].text = "Magnetic: {:.3f} {:.3f} {:.3f}".format(*clue.magnetic) clue_data[3].text = "Pressure: {:.3f}hPa".format(clue.pressure) clue_data[4].text = "Altitude: {:.1f}m".format(clue.altitude) clue_data[5].text = "Temperature: {:.1f}C".format(clue.temperature) clue_data[6].text = "Humidity: {:.1f}%".format(clue.humidity) clue_data[7].text = "Proximity: {}".format(clue.proximity) clue_data[8].text = "Gesture: {}".format(clue.gesture) clue_data[9].text = "Color: R: {} G: {} B: {} C: {}".format(*clue.color)
import board import busio from digitalio import DigitalInOut, Direction, Pull import adafruit_pm25 from datetime import datetime import os import logging from logging.handlers import TimedRotatingFileHandler import asyncio from typing import Tuple from collections import defaultdict reset_pin = None i2c = busio.I2C(board.SCL, board.SDA, frequency=100000) pm25Sensor = adafruit_pm25.PM25_I2C(i2c, reset_pin) index_breakpoints = [[0, 50], [51, 100], [101, 150], [201, 300], [301, 500]] pm25_breakpoints = [ [0.0, 12.0], [12.1, 35.4], [35.5, 55.4], [55.5, 150.4], [150.5, 250.4], [250.5, 350.4], [350.5, 500.4], ] pm10_breakpoints = [ [0, 54], [55, 154], [155, 254], [255, 354],