fu-hsi / PMS

Arduino library for Plantower PMS x003 family sensors.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get it working with delays?

Paul760 opened this issue · comments

When I change the basic.ino script at line 28 with a simple delay(3000); I do not get any values.

Probably there is no complete packet to analyse? So the value pms.read(data) is 0?

How can that be solved? I want to run the PMS script in a larger script where a lot of sensors are read. So it takes time to get back to if (pms.read(data))

I solved it already with a for loop. But is there a smarter way?

for (int i = 0; i <= 200; i++) {
Serial.print(i);
if (pms.read(data))
  { 
    Serial.print("\nPM 1.0: ");Serial.print(data.PM_AE_UG_1_0);    Serial.print(", ");
    Serial.print("PM 2.5: ");Serial.print(data.PM_AE_UG_2_5);    Serial.print(", "); 
    Serial.print("PM 10: ");Serial.print(data.PM_AE_UG_10_0); 
     i = 200;
  }
}

Use another example (advanced or expert):
Advanced.ino
Expert.ino

You must use passive mode, requestRead() and after readUntil().