Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions examples/hourly.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python

from pms5003 import PMS5003
import time

print("""hourly.py - Run (approximately) hourly.

Press Ctrl+C to exit!

""")

# Configure the PMS5003 for Enviro+
pms5003 = PMS5003(
device='/dev/ttyAMA0',
baudrate=9600,
pin_enable=22,
pin_reset=27
)

last_read_epoch = 0

try:
while True:
# has it been an hour since our last reading?
now = int(time.time())
if (now - last_read_epoch) > 3600:
last_read_epoch = now

print("waking")
pms5003.wake()

# give sensor time to wake up and calibrate
print("sleeping")
time.sleep(60)
print("reading")

# take several readings, good for a median
for _ in range(9):
data = pms5003.read()
print("PM2.5 ug/m3 (combustion particles, organic compounds, metals): {}".format(data.pm_ug_per_m3(2.5)))

# done reading, shut down sensor (and its fan)
print("sleeping")
pms5003.sleep()
else:
time.sleep(10)

except KeyboardInterrupt:
pass

9 changes: 9 additions & 0 deletions library/pms5003/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ def setup(self):

self.reset()

def sleep(self):
'''Turn off enable (SET). This stops the fan, aka sleeping
mode. Note this is different than active/passive.'''
GPIO.output(self._pin_enable, GPIO.LOW)

def wake(self):
'''Enable (SET). This starts the fan and sensor. Wait 30sec for values.'''
GPIO.output(self._pin_enable, GPIO.HIGH)

def reset(self):
time.sleep(0.1)
GPIO.output(self._pin_reset, GPIO.LOW)
Expand Down