forked from switchdoclabs/SDL_Pi_SkyWeather2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestDustHM3301.py
61 lines (46 loc) · 1.18 KB
/
testDustHM3301.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
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
# test HM3301 Laser Dust Sensor
# must run "sudo pigpiod" before starting
import sys
sys.path.append('./SDL_Pi_HM3301')
import subprocess
import SDL_Pi_HM3301
import time
import traceback
import pigpio
import config
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(config.DustSensorPowerPin, GPIO.OUT)
GPIO.output(config.DustSensorPowerPin, True)
#
if (config.SWDEBUG):
print("Starting pigpio daemon")
# kill all pigpio instances
try:
cmd = [ 'killall', 'pigpiod' ]
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
print(output)
time.sleep(5)
except:
#print(traceback.format_exc())
pass
cmd = [ '/usr/bin/pigpiod' ]
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
print(output)
import DustSensor
time.sleep(0.01)
try:
while 1:
DustSensor.powerOnDustSensor()
time.sleep(3)
myData = DustSensor.get_data()
print ("data=",myData)
myAQI = DustSensor.get_aqi()
DustSensor.print_data()
print ("AQI=", myAQI)
DustSensor.powerOffDustSensor()
time.sleep(3)
except:
#DustSensor.powerOffDustSensor()
print(traceback.format_exc())