-
Notifications
You must be signed in to change notification settings - Fork 20
/
testDust.py
54 lines (34 loc) · 1.26 KB
/
testDust.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
#SwithchDoc Labs September 2018
# Public Domain
import sys
sys.path.append('./SDL_Pi_DustSensor')
import pigpio
# tests SDL_Pi_DustSensor Driver
import time
import pigpio
import SDL_Pi_DustSensor
SENSORPIN = 19
while True:
pi = pigpio.pi() # Connect to Pi.
dustSensor = SDL_Pi_DustSensor.SDL_Pi_DustSensor(pi, SENSORPIN) # set the GPIO pin number
# Use 30s for a properly calibrated reading.
time.sleep(30)
# get the gpio, ratio and concentration in particles / 0.01 ft3
g, r, c = dustSensor.read()
# concentration above 1,080,000 considered error
if (c>=1080000.00):
print("Concentration Error\n")
continue
print("Air Quality Measurements for PM2.5:")
print(" " + str(int(c)) + " particles/0.01ft^3")
# convert to SI units
concentration_ugm3=dustSensor.pcs_to_ugm3(c)
print(" " + str(int(concentration_ugm3)) + " ugm^3")
# convert SI units to US AQI
# input should be 24 hour average of ugm3, not instantaneous reading
aqi=dustSensor.ugm3_to_aqi(concentration_ugm3)
print(" Current AQI (not 24 hour avg): " + str(int(aqi)))
print("")
pi.stop() # Disconnect from Pi.
time.sleep(5)