add config for PMSA003I, conditional imports
@@ -6,16 +6,17 @@ import neopixel
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
from adafruit_io.adafruit_io import IO_HTTP
from simpleio import map_range
-
import adafruit_pm25
-import adafruit_bme280
### Configure Sensor ###
-# Return BME280 environmental sensor readings in degrees Celsius
+# Return environmental sensor readings in degrees Celsius
USE_CELSIUS = False
# Interval the sensor publishes to Adafruit IO, in minutes
PUBLISH_INTERVAL = 10
+# Set this to True if you are using a PMSA003I breakout, False otherwise
+USE_PMSA003I = False
+
### WiFi ###
# Get wifi details and more from a secrets.py file
@@ -35,13 +36,23 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
+
+# Create i2c object, use 'slow' 100KHz frequency!
+i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)
+reset_pin = None
+if USE_PMSA003I:
+ import adafruit_bme680
+ # Connect to a PM2.5 sensor over I2C
+ pm25 = adafruit_pm25.PM25_I2C(i2c, reset_pin)
+ # Connect to a BME680 sensor over I2C
+ bme_sensor = adafruit_bme680.Adafruit_BME680_I2C(i2c)
+else:
+ import adafruit_bme280
# Connect to a PM2.5 sensor over UART
uart = busio.UART(board.TX, board.RX, baudrate=9600)
-pm25 = adafruit_pm25.PM25_UART(uart)
-
+ pm25 = adafruit_pm25.PM25_UART(uart, reset_pin)
# Connect to a BME280 sensor over I2C
-i2c = busio.I2C(board.SCL, board.SDA)
-bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
+ bme_sensor = adafruit_bme280.Adafruit_BME280_I2C(i2c)
### Sensor Functions ###
def calculate_aqi(pm_sensor_reading):
@@ -118,11 +129,11 @@ def read_bme280(is_celsius=False):
:param bool is_celsius: Returns temperature in degrees celsius
if True, otherwise fahrenheit.
"""
- humid = bme280.humidity
- temp = bme280.temperature
+ humid = bme_sensor.humidity
+ temp = bme_sensor.temperature
if not is_celsius:
temp = temp * 1.8 + 32
- return temperature, humid
+ return temp, humid
# Create an instance of the Adafruit IO HTTP client
