From 5047ab0ea8f6b80f18e55ceb06f570afb6038b51 Mon Sep 17 00:00:00 2001 From: Swan Jeng Date: Thu, 23 Oct 2025 18:49:21 +0800 Subject: [PATCH 1/5] Change Serial port usage --- examples/Basic/Basic.ino | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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 +} From 558fe5a5cf9657dd45624d22f86c71c1acb4853b Mon Sep 17 00:00:00 2001 From: Swan Jeng Date: Thu, 23 Oct 2025 18:50:41 +0800 Subject: [PATCH 2/5] Change Serial1 to Serial for correct output behavior --- examples/Advanced/Advanced.ino | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) 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 +} From 861e67592e1f3661a3ba04f4a2d23389de885d79 Mon Sep 17 00:00:00 2001 From: Swan Jeng Date: Thu, 23 Oct 2025 18:53:19 +0800 Subject: [PATCH 3/5] Switch debug output from Serial1 to Serial --- examples/Expert/Expert.ino | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 +} From 2fe20ef76d5bda0872855d35b0bf7d39a0bb3e40 Mon Sep 17 00:00:00 2001 From: Swan Jeng Date: Thu, 23 Oct 2025 18:55:03 +0800 Subject: [PATCH 4/5] Change Serial1 to Serial for output in README --- README.md | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) 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. From dc0867ad6a998642d2f31210512ef0bdf28e5663 Mon Sep 17 00:00:00 2001 From: Swan Jeng Date: Wed, 17 Dec 2025 13:27:46 +0800 Subject: [PATCH 5/5] Update README.md --- README.md | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a61d955..9118ff4 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,11 @@ # PMS Library + Arduino library for Plantower PMS sensors. -Supports PMS x003 sensors (1003, 3003, 5003, 6003, 7003). +Supports PMS x003 sensors (1003, 3003, 5003, 6003, 7003, 9003, A003). + ## Installation -Just use Arduino Library Manager and search "PMS Library" in Sensors category. +Just use Arduino Library Manager and search "PMS Library". + ## Main assumptions - easy as possible, - minimal memory consumption, @@ -11,19 +14,20 @@ Just use Arduino Library Manager and search "PMS Library" in Sensors category. - supporting additional modes e.g.: sleeping, passive, active (depends on the sensor model). As a data source you can use **any object** that implements the **Stream class**, such as Wire, Serial, EthernetClient, e.t.c. + ## Basic example Read in active mode. -> Default mode is active after power up. In this mode sensor would send serial data to the host automatically. The active mode is divided into two sub-modes: stable mode and fast mode. If the concentration change is small the sensor would run at stable mode with the real interval of 2.3s. And if the change is big the sensor would be changed to fast mode automatically with the interval of 200~800ms, the higher of the concentration, the shorter of the interval. +> Default mode is active after power up. In this mode, the sensor would send serial data to the host automatically. The active mode is divided into two sub-modes: stable mode and fast mode. If the concentration change is small, the sensor would run at stable mode with the real interval of 2.3s. And if the change is big the sensor would be changed to fast mode automatically with the interval of 200~800ms, the higher of the concentration, the shorter of the interval. ```cpp #include "PMS.h" -PMS pms(Serial1); +PMS pms(Serial1); // softwareserial is also ok. PMS::DATA data; void setup() { - Serial.begin(9600); // GPIO1, GPIO3 (TX/RX pin on ESP-12E Development Board) - Serial1.begin(9600); // GPIO2 (D4 pin on ESP-12E Development Board) + Serial.begin(9600); + Serial1.begin(9600); } void loop() @@ -67,8 +71,8 @@ PMS::DATA data; void setup() { - Serial.begin(9600); // GPIO1, GPIO3 (TX/RX pin on ESP-12E Development Board) - Serial1.begin(9600); // GPIO2 (D4 pin on ESP-12E Development Board) + Serial.begin(9600); + Serial1.begin(9600); pms.passiveMode(); // Switch to passive mode }