You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FYI I was facing the same problem as described in #6. I solved it by adding a flush() on the serial port used for printing status BEFORE calling pms.sleep(). (In #6 author recommended adding a flush on pms serial port after calling pms.sleep() which was not helping.)
Adjusted advanced example using SoftwareSerial:
#include <SoftwareSerial.h> // using SoftwareSerial might create problems in activating sleep mode, see additional Serial.flush(); below
#include "PMS.h"
SoftwareSerial serialDust(11, 12); // RX, TX
PMS pms(serialDust);
PMS::DATA data;
void setup()
{
// Serial Port setups
Serial.begin(9600); // used for print output
serialDust.begin(9600); // software serial for dust sensor
pms.passiveMode(); // Switch to passive mode
}
void loop()
{
Serial.println("Waking up, wait 30 seconds for stable readings...");
pms.wakeUp();
delay(30000);
Serial.println("Send read request...");
pms.requestRead();
if (pms.readUntil(data)) {
Serial.print("PM 1.0 (ug/m3): ");
Serial.println(data.PM_AE_UG_1_0);
Serial.print("PM 2.5 (ug/m3): ");
Serial.println(data.PM_AE_UG_2_5);
Serial.print("PM 10.0 (ug/m3): ");
Serial.println(data.PM_AE_UG_10_0);
Serial.println();
} else {
Serial.println("No data.");
}
Serial.println("Going to sleep for 60 seconds.");
Serial.flush(); // IMPORTANT when using software serial
pms.sleep();
delay(60000);
}
Tested on Arduino Nano with PMS7003 sensor.
Otherwise, thanks a lot for setting up this very clean library!
The text was updated successfully, but these errors were encountered:
Just to add to this, like @xtendch I had an issue with commands (in my case pms.wakeUp()) not sending properly over SoftwareSerial unless I ran swserial.flush() just BEFORE the PMS command. (AltSoftSerial and NeoSWSerial libraries were not an option as neither work on the ESP8266).
#include <SoftwareSerial.h>
SoftwareSerial soft(D5, D7); // RX TX
#include "PMS.h"
PMS pms(soft);
void setup() {
soft.begin(9600);
// first pms command does not arrive reliably unless we flush the swserial port first
soft.flush();
// wake up from previous sleep (see below)
pms.wakeUp();
// do stuff
pms.sleep(); // works fine
ESP.sleep(600e6); // send into deep sleep, reset after 10 minutes brings us back to beginning of setup()
}
FYI I was facing the same problem as described in #6. I solved it by adding a flush() on the serial port used for printing status BEFORE calling pms.sleep(). (In #6 author recommended adding a flush on pms serial port after calling pms.sleep() which was not helping.)
Adjusted advanced example using SoftwareSerial:
Tested on Arduino Nano with PMS7003 sensor.
Otherwise, thanks a lot for setting up this very clean library!
The text was updated successfully, but these errors were encountered: