-
Notifications
You must be signed in to change notification settings - Fork 0
/
sensor_controller.py
62 lines (46 loc) · 1.06 KB
/
sensor_controller.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
62
#!/usr/bin/python
# -*- coding:UTF-8 -*-
import time
import Si1145 as Sensor
import RPi.GPIO as GPIO
import os
import subprocess as sp
from subprocess import call
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
# initialize both sensors to LOW
GPIO.setup(17, GPIO.OUT)
GPIO.setup(22, GPIO.OUT)
GPIO.output(17, GPIO.LOW)
GPIO.output(22, GPIO.LOW)
# pin 17 controls the UV sensor
GPIO.output(17, GPIO.HIGH)
time.sleep(0.1)
Sensor.Si1145_Init()
unplugged = False
uv_avg = []
while True:
try:
if unplugged:
Sensor.Si1145_Init()
UVindex = Sensor.Si1145_readUV()
UVindex /= 100.0
uv_avg.append(UVindex)
print("UV: ", UVindex)
unplugged = False
if (len(uv_avg) > 50):
break # got all our data readings
continue
except:
print('Sensor Unplugged')
unplugged = True
Sensor.Si1145_close()
Sensor.Si1145_close()
GPIO.output(17, GPIO.LOW)
GPIO.output(22, GPIO.HIGH)
p = call(["./bme280", ">>", "data.txt"])
#p = sp.Popen(["./bme280"], shell=False)
GPIO.output(22, GPIO.LOW)
#time.sleep(2.5)
Sensor.Si1145_close()
exit()