Merge branch 'master' of github.com:pimoroni/enviroplus-python
[EVA-2020-02-2.git] / examples / particulates.py
CommitLineData
0cf10e5b
PH
1#!/usr/bin/env python
2
3import time
85439fb1 4from pms5003 import PMS5003, ReadTimeoutError
10b73e18 5import logging
0cf10e5b 6
10b73e18
CM
7logging.basicConfig(
8 format='%(asctime)s.%(msecs)03d %(levelname)-8s %(message)s',
9 level=logging.INFO,
10 datefmt='%Y-%m-%d %H:%M:%S')
11
12logging.info("""particulates.py - Print readings from the PMS5003 particulate sensor.
0cf10e5b
PH
13
14Press Ctrl+C to exit!
8ab4cd2d 15
0cf10e5b
PH
16""")
17
18pms5003 = PMS5003()
19time.sleep(1.0)
20
0cf10e5b
PH
21try:
22 while True:
85439fb1
SM
23 try:
24 readings = pms5003.read()
10b73e18 25 logging.info(readings)
85439fb1
SM
26 time.sleep(1.0)
27 except ReadTimeoutError:
28 pms5003 = PMS5003()
0cf10e5b
PH
29except KeyboardInterrupt:
30 pass