diff --git a/README.md b/README.md index 1fee105..2b1667d 100644 --- a/README.md +++ b/README.md @@ -58,8 +58,8 @@ cd esp32-weatherstation virtualenv . source bin/activate pip install -U platformio -platformio run -t upload && platformio device monitor -b 115200 pio run +platformio run -t upload && platformio device monitor -b 115200 ``` ## Authors @@ -74,4 +74,5 @@ This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md * [PlatformIO](https://platformio.org) - Cross-platform IDE * [GxEPD2](https://github.com/ZinggJM/GxEPD2) - E-Paper display library -* [Adafruit BME680](https://github.com/adafruit/Adafruit_BME680) - BME680 Sensor Library +* [Adafruit BME680](https://github.com/adafruit/Adafruit_BME680) - BME680 sensor library +* [Nova Fitness SDS dust sensors arduino library](https://github.com/lewapek/sds-dust-sensors-arduino-library.git) - SDS011 Laser dust sensor library diff --git a/platformio.ini b/platformio.ini index 4bcd854..bd64aa5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -27,6 +27,7 @@ build_flags = -DMQTT_BROKER_URI="\"${sysenv.MQTT_BROKER_URI}\"" -DMQTT_USERNAME="\"${sysenv.MQTT_USERNAME}\"" -DMQTT_PASSWORD="\"${sysenv.MQTT_PASSWORD}\"" + -DARDUINO_SAMD_VARIANT_COMPLIANCE lib_deps = GxEPD2 @@ -34,7 +35,9 @@ lib_deps = Adafruit GFX Library Adafruit BME280 Library Adafruit Unified Sensor - SDS011 sensor Library +; SDS011 sensor Library +; Nova Fitness Sds dust sensors library + https://github.com/lewapek/sds-dust-sensors-arduino-library.git ; ArduinoJSON monitor_speed = 115200 diff --git a/src/main.cpp b/src/main.cpp index 218a5a0..53c7972 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,7 +19,8 @@ #include #include "Adafruit_BME280.h" -#include +#define ARDUINO_SAMD_VARIANT_COMPLIANCE +#include "SdsDustSensor.h" #include "XD0OTA.h" #include "XD0MQTT.h" @@ -29,8 +30,8 @@ static const char* TAG = "MAIN"; WiFiMulti wifiMulti; GxEPD2_BW display(GxEPD2_213_B72(/*CS=SS*/ TFT_CS, /*DC=*/ TFT_DC, /*RST=*/ TFT_RST, /*BUSY=*/ -1)); // GDEH0213B72 Adafruit_BME280 bme; // I2C (also available: hardware SPI -SDS011 my_sds; -HardwareSerial serialport(2); +//HardwareSerial Serial2(2); +SdsDustSensor sds(Serial2); XD0MQTT mqtt; @@ -118,7 +119,7 @@ void setup() bme.setGasHeater(320, 150); // 320*C for 150 ms */ - my_sds.begin(&serialport); + sds.begin(); wifiMulti.addAP(WIFI_SSID, WIFI_PASSWD); wifiMulti.addAP(WIFI_SSID2, WIFI_PASSWD2); @@ -161,13 +162,18 @@ void loop() display.print("Gas: "); display.print(bme.gas_resistance / 1000.0); display.println(" KOhms"); */ - float p10, p25; - int error; - - error = my_sds.read(&p25, &p10); - if (!error) { - Serial.println("P.2.5: " + String(p25)); - Serial.println("P10: " + String(p10)); + PmResult pm = sds.readPm(); + if (pm.isOk()) { + Serial.print("PM2.5 = "); + Serial.print(pm.pm25); + Serial.print(", PM10 = "); + Serial.println(pm.pm10); + + // if you want to just print the measured values, you can use toString() method as well + Serial.println(pm.toString()); + } else { + Serial.print("Could not read values from sensor, reason: "); + Serial.println(pm.statusToString()); }