Fix for PMS5003 ReadTimeoutError
[EVA-2020-02-2.git] / examples / particulates.py
index 99803ec05a96ff502fc440e115b5c7aa581888a3..e71ca5d96f78782f5237134e1dffd3df51dfcf7e 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 
 import time
-from pms5003 import PMS5003
+from pms5003 import PMS5003, ReadTimeoutError
 
 print("""particulates.py - Print readings from the PMS5003 particulate sensor.
 
@@ -14,8 +14,11 @@ time.sleep(1.0)
 
 try:
     while True:
-        readings = pms5003.read()
-        print(readings)
-        time.sleep(1.0)
+        try:
+            readings = pms5003.read()
+            print(readings)
+            time.sleep(1.0)
+        except ReadTimeoutError:
+            pms5003 = PMS5003()
 except KeyboardInterrupt:
     pass