/************************************************************************************************* PROGRAMMINFO ************************************************************************************************** Funktion: Feinstaubmessung mit Nova PM sensor SDS011 und OLED Display 1,3" A168 https://www.umweltbundesamt.de/daten/luft/feinstaub-belastung#feinstaubkonzentrationen-in-deutschland 60sek Smiley am Display während der Sensor Initialisierung ************************************************************************************************** PM2.5 steht beispielsweise für Partikel mit einem aerodynamischen Durchmesser von 2,5 Mikrometer oder weniger, PM10 für 10 Mikrometern SDS011 (Laser Dust/Air Quality Sensor Module) Specification: Measured values: PM2.5, PM10 Range: 0 – 999.9 μg /m³ Supply voltage: 5V (4.7 – 5.3V) Power consumption (work): 70mA±10mA Power consumption (sleep mode laser & fan): < 4mA Storage temperature: -20 to +60C Work temperature: -10 to +50C Humidity (storage): Max. 90% Humidity (work): Max. 70% (condensation of water vapor falsify readings) Accuracy: 70% for 0.3μm 98% for 0.5μm Size: 71x70x23 mm Certification: CE, FCC, RoHS Pinout: Pin 1 – not connected Pin 2 – PM2.5: 0-999μg/m³; PWM output Pin 3 – 5V Pin 4 – PM10: 0-999 μg/m³; PWM output Pin 5 – GND Pin 6 – RX UART (TTL) 3.3V Pin 7 – TX UART (TTL) 3.3V ************************************************************************************************** Version: 13.06.2022 ************************************************************************************************** Board: LOLIN(WEMOS)D1 R2 & mini V2.2.0 ************************************************************************************************** Libraries: https://github.com/espressif/arduino-esp32/tree/master/libraries C:\Users\User\Documents\Arduino D:\gittemp\Arduino II\A156_Wetterdaten_V3 https://github.com/lewapek/sds-dust-sensors-arduino-library V1.5.1 Pawel Kolodziejczyk V1.5.1 vom 14.2.2022 https://github.com/olikraus/u8g2/blob/master/tools/font/build/single_font_files/u8g2_font_courR10_tf.c ************************************************************************************************** C++ Arduino IDE V1.8.19 I2C Display SCL = D1 SDA = D2 ************************************************************************************************** Einstellungen: https://dl.espressif.com/dl/package_esp32_index.json http://dan.drown.org/stm32duino/package_STM32duino_index.json http://arduino.esp8266.com/stable/package_esp8266com_index.json **************************************************************************************************/ #include #include //Nova Fitnes SDS Dust Senssor //***********OLED******************** #include #ifdef U8X8_HAVE_HW_SPI #include #endif #ifdef U8X8_HAVE_HW_I2C #include #endif U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); unsigned long delayTime; //******************************* /* SDS011 Dust Sensor -> ESP8266 */ const int SDS_RX_PIN = D3; // D3 -> SDS011 RX pin const int SDS_TX_PIN = D4; // D4 -> SDS011 TX pin SoftwareSerial softwareSerial(SDS_RX_PIN, SDS_TX_PIN); SdsDustSensor sds(softwareSerial); // zusätzliche Parameter: retryDelayMs und maxRetriesNotAvailable const int MINUTE = 60000; // 60 Sekunden const int WAKEUP_WORKING_TIME = 30000; // 30 Sekunden const int MEASUREMENT_INTERVAL = 5 * MINUTE; void setup() { Serial.begin(115200); //***********OLED******************** u8g2.begin(); //*********************************** Serial.println("SDS011 Feinstaubsensor"); delay(500); /* SDS011 Dust Sensor */ sds.begin(); // SDS011 Firmware Version: Serial.print("SDS011 "); Serial.println(sds.queryFirmwareVersion().toString()); // Stellt sicher, dass sich SDS011 im Abfrageberichtsmodus befindet: Serial.println(sds.setQueryReportingMode().toString()); int BildschirmBreite = u8g2.getDisplayWidth(); int BildschirmHoehe = u8g2.getDisplayHeight(); //Smiley XBM erstellt mit GIMP #define smiley_width 64 #define smiley_height 64 static unsigned char smiley[] = { 0x00, 0x00, 0x00, 0xd0, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x5f, 0xfd, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x80, 0x7f, 0x00, 0x00, 0x00, 0x80, 0x1f, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xf0, 0x01, 0x00, 0x00, 0xc0, 0x0f, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x1f, 0x00, 0x03, 0x80, 0x01, 0xf8, 0x00, 0x80, 0x07, 0x80, 0x03, 0xc0, 0x03, 0xf0, 0x00, 0xc0, 0x07, 0x80, 0x07, 0xc0, 0x03, 0xe0, 0x01, 0xc0, 0x03, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x03, 0xe0, 0x01, 0xc0, 0x07, 0xe0, 0x07, 0x80, 0x07, 0xe0, 0x00, 0xc0, 0x0f, 0xe0, 0x07, 0x80, 0x07, 0xf0, 0x00, 0xc0, 0x0f, 0xe0, 0x07, 0x00, 0x0f, 0x70, 0x00, 0xc0, 0x0f, 0xe0, 0x07, 0x00, 0x0e, 0x78, 0x00, 0xc0, 0x0f, 0xe0, 0x07, 0x00, 0x1e, 0x38, 0x00, 0xe0, 0x0f, 0xe0, 0x07, 0x00, 0x1e, 0x3c, 0x00, 0xc0, 0x0f, 0xe0, 0x07, 0x00, 0x1c, 0x1c, 0x00, 0xc0, 0x07, 0xe0, 0x07, 0x00, 0x3c, 0x1c, 0x00, 0xc0, 0x07, 0xe0, 0x07, 0x00, 0x38, 0x1c, 0x00, 0xc0, 0x07, 0xc0, 0x03, 0x00, 0x38, 0x1e, 0x00, 0x80, 0x07, 0xc0, 0x03, 0x00, 0x38, 0x1e, 0x00, 0x80, 0x03, 0x80, 0x01, 0x00, 0x38, 0x0e, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x78, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x78, 0x0e, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x70, 0x0e, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x18, 0x38, 0x1e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x18, 0x78, 0x1e, 0x30, 0x00, 0x00, 0x00, 0x00, 0x08, 0x38, 0x1e, 0x30, 0x00, 0x00, 0x00, 0x00, 0x08, 0x38, 0x1c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x38, 0x1c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x04, 0x38, 0x1c, 0x60, 0x00, 0x00, 0x00, 0x00, 0x06, 0x3c, 0x3c, 0x40, 0x00, 0x00, 0x00, 0x00, 0x06, 0x1c, 0x38, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1c, 0x78, 0x80, 0x01, 0x00, 0x00, 0x00, 0x01, 0x1e, 0x78, 0x00, 0x01, 0x00, 0x00, 0x80, 0x01, 0x0e, 0xf0, 0x00, 0x07, 0x00, 0x00, 0xc0, 0x00, 0x0f, 0xf0, 0x00, 0x04, 0x00, 0x00, 0x60, 0x00, 0x07, 0xe0, 0x01, 0x1c, 0x00, 0x00, 0x38, 0x80, 0x07, 0xc0, 0x03, 0x70, 0x00, 0x00, 0x0c, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x01, 0x00, 0x07, 0xe0, 0x03, 0x80, 0x07, 0x80, 0x17, 0xf0, 0x01, 0xe0, 0x01, 0x00, 0x0f, 0x00, 0xfc, 0x3f, 0x00, 0xf0, 0x00, 0x00, 0x1f, 0x00, 0x40, 0x01, 0x00, 0x78, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0xf8, 0x01, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xc0, 0x1f, 0x00, 0x00, 0xf8, 0x03, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x2f, 0xf4, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfa, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; do { u8g2.clearBuffer(); u8g2.drawXBM(32, 1, smiley_width, smiley_height, smiley); } while ( u8g2.nextPage() ); delay(3000); } void loop() { // Wake up SDS011 sds.wakeup(); delay(WAKEUP_WORKING_TIME); // Get data from SDS011 PmResult pm = sds.queryPm(); if (pm.isOk()) { Serial.print("PM2.5 = "); Serial.print(pm.pm25); // float, μg/m3 Serial.print(", PM10 = "); Serial.println(pm.pm10); //***********OLED******************** Serial.println("================================="); Serial.println("Sensordaten"); u8g2.setFont(u8g2_font_courR10_tf); u8g2.firstPage(); do { u8g2.setCursor(25, 10); u8g2.print("Partikel-"); u8g2.setCursor(31, 24); u8g2.print("messung:"); u8g2.setFont(u8g2_font_courR08_tf); u8g2.setCursor(3, 45); u8g2.print("PM 2.5""\xB5""m:"); u8g2.setCursor(63, 45); u8g2.print(pm.pm25); u8g2.print("\xB5""gr/m3"); u8g2.setCursor(3, 59); u8g2.print("PM 10""\xB5""m:"); u8g2.setCursor(63, 59); u8g2.print(pm.pm10); u8g2.print("\xB5""gr/m3"); } while ( u8g2.nextPage() ); delay(delayTime); } else { Serial.print("Werte vom Sensor konnten nicht gelesen werden, Grund: "); Serial.println(pm.statusToString()); } // SDS011 wieder in den Ruhezustand versetzen WorkingStateResult state = sds.sleep(); if (state.isWorking()) { Serial.println("Problem mit dem Einschlafen des SDS011-Sensors."); } else { Serial.println("SDS011-Sensor schläft"); delay(MEASUREMENT_INTERVAL); } }