diff --git a/README.md b/README.md index 9956032..a61d955 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Read in active mode. ```cpp #include "PMS.h" -PMS pms(Serial); +PMS pms(Serial1); PMS::DATA data; void setup() @@ -30,16 +30,16 @@ void loop() { if (pms.read(data)) { - Serial1.print("PM 1.0 (ug/m3): "); - Serial1.println(data.PM_AE_UG_1_0); + Serial.print("PM 1.0 (ug/m3): "); + Serial.println(data.PM_AE_UG_1_0); - Serial1.print("PM 2.5 (ug/m3): "); - Serial1.println(data.PM_AE_UG_2_5); + Serial.print("PM 2.5 (ug/m3): "); + Serial.println(data.PM_AE_UG_2_5); - Serial1.print("PM 10.0 (ug/m3): "); - Serial1.println(data.PM_AE_UG_10_0); + Serial.print("PM 10.0 (ug/m3): "); + Serial.println(data.PM_AE_UG_10_0); - Serial1.println(); + Serial.println(); } // Do other stuff... @@ -62,7 +62,7 @@ Read in passive mode but not the best way (see additional remarks). ```cpp #include "PMS.h" -PMS pms(Serial); +PMS pms(Serial1); PMS::DATA data; void setup() @@ -74,31 +74,31 @@ void setup() void loop() { - Serial1.println("Waking up, wait 30 seconds for stable readings..."); + Serial.println("Waking up, wait 30 seconds for stable readings..."); pms.wakeUp(); delay(30000); - Serial1.println("Send read request..."); + Serial.println("Send read request..."); pms.requestRead(); - Serial1.println("Reading data..."); + Serial.println("Reading data..."); if (pms.readUntil(data)) { - Serial1.print("PM 1.0 (ug/m3): "); - Serial1.println(data.PM_AE_UG_1_0); + Serial.print("PM 1.0 (ug/m3): "); + Serial.println(data.PM_AE_UG_1_0); - Serial1.print("PM 2.5 (ug/m3): "); - Serial1.println(data.PM_AE_UG_2_5); + Serial.print("PM 2.5 (ug/m3): "); + Serial.println(data.PM_AE_UG_2_5); - Serial1.print("PM 10.0 (ug/m3): "); - Serial1.println(data.PM_AE_UG_10_0); + Serial.print("PM 10.0 (ug/m3): "); + Serial.println(data.PM_AE_UG_10_0); } else { - Serial1.println("No data."); + Serial.println("No data."); } - Serial1.println("Going to sleep for 60 seconds."); + Serial.println("Going to sleep for 60 seconds."); pms.sleep(); delay(60000); } @@ -130,4 +130,4 @@ Please consider, that delay() function in examples is a blocking function. Try to avoid such a solution if your project requires it (see Expert.ino example in examples directory). For more accurate measurements, you can read several samples (in passive or active mode) and calculate the average. -> Stable data should be got at least 30 seconds after the sensor wakeup from the sleep mode because of the fan's performance. \ No newline at end of file +> Stable data should be got at least 30 seconds after the sensor wakeup from the sleep mode because of the fan's performance. diff --git a/examples/Advanced/Advanced.ino b/examples/Advanced/Advanced.ino index 6034a8f..79c96bf 100644 --- a/examples/Advanced/Advanced.ino +++ b/examples/Advanced/Advanced.ino @@ -1,6 +1,6 @@ #include "PMS.h" -PMS pms(Serial); +PMS pms(Serial1); PMS::DATA data; void setup() @@ -12,31 +12,31 @@ void setup() void loop() { - Serial1.println("Waking up, wait 30 seconds for stable readings..."); + Serial.println("Waking up, wait 30 seconds for stable readings..."); pms.wakeUp(); delay(30000); - Serial1.println("Send read request..."); + Serial.println("Send read request..."); pms.requestRead(); - Serial1.println("Wait max. 1 second for read..."); + Serial.println("Wait max. 1 second for read..."); if (pms.readUntil(data)) { - Serial1.print("PM 1.0 (ug/m3): "); - Serial1.println(data.PM_AE_UG_1_0); + Serial.print("PM 1.0 (ug/m3): "); + Serial.println(data.PM_AE_UG_1_0); - Serial1.print("PM 2.5 (ug/m3): "); - Serial1.println(data.PM_AE_UG_2_5); + Serial.print("PM 2.5 (ug/m3): "); + Serial.println(data.PM_AE_UG_2_5); - Serial1.print("PM 10.0 (ug/m3): "); - Serial1.println(data.PM_AE_UG_10_0); + Serial.print("PM 10.0 (ug/m3): "); + Serial.println(data.PM_AE_UG_10_0); } else { - Serial1.println("No data."); + Serial.println("No data."); } - Serial1.println("Going to sleep for 60 seconds."); + Serial.println("Going to sleep for 60 seconds."); pms.sleep(); delay(60000); -} \ No newline at end of file +} diff --git a/examples/Basic/Basic.ino b/examples/Basic/Basic.ino index b60f109..38ed898 100644 --- a/examples/Basic/Basic.ino +++ b/examples/Basic/Basic.ino @@ -1,6 +1,6 @@ #include "PMS.h" -PMS pms(Serial); +PMS pms(Serial1); PMS::DATA data; void setup() @@ -13,17 +13,17 @@ void loop() { if (pms.read(data)) { - Serial1.print("PM 1.0 (ug/m3): "); - Serial1.println(data.PM_AE_UG_1_0); + Serial.print("PM 1.0 (ug/m3): "); + Serial.println(data.PM_AE_UG_1_0); - Serial1.print("PM 2.5 (ug/m3): "); - Serial1.println(data.PM_AE_UG_2_5); + Serial.print("PM 2.5 (ug/m3): "); + Serial.println(data.PM_AE_UG_2_5); - Serial1.print("PM 10.0 (ug/m3): "); - Serial1.println(data.PM_AE_UG_10_0); + Serial.print("PM 10.0 (ug/m3): "); + Serial.println(data.PM_AE_UG_10_0); - Serial1.println(); + Serial.println(); } // Do other stuff... -} \ No newline at end of file +} diff --git a/examples/Expert/Expert.ino b/examples/Expert/Expert.ino index 6179419..fee2cda 100644 --- a/examples/Expert/Expert.ino +++ b/examples/Expert/Expert.ino @@ -4,7 +4,7 @@ // #define DEEP_SLEEP // GPIO2 (D4 pin on ESP-12E Development Board). -#define DEBUG_OUT Serial1 +#define DEBUG_OUT Serial // PMS_READ_INTERVAL (4:30 min) and PMS_READ_DELAY (30 sec) CAN'T BE EQUAL! Values are also used to detect sensor state. static const uint32_t PMS_READ_INTERVAL = 270000; @@ -13,12 +13,12 @@ static const uint32_t PMS_READ_DELAY = 30000; // Default sensor state. uint32_t timerInterval = PMS_READ_DELAY; -PMS pms(Serial); +PMS pms(Serial1); void setup() { // GPIO1, GPIO3 (TX/RX pin on ESP-12E Development Board) - Serial.begin(PMS::BAUD_RATE); + Serial1.begin(PMS::BAUD_RATE); DEBUG_OUT.begin(9600); // Switch to passive mode. @@ -73,7 +73,7 @@ void readData() PMS::DATA data; // Clear buffer (removes potentially old data) before read. Some data could have been also sent before switching to passive mode. - while (Serial.available()) { Serial.read(); } + while (Serial1.available()) { Serial.read(); } DEBUG_OUT.println("Send read request..."); pms.requestRead(); @@ -98,4 +98,4 @@ void readData() { DEBUG_OUT.println("No data."); } -} \ No newline at end of file +}