-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththerm_test.py
87 lines (68 loc) · 1.85 KB
/
therm_test.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#Thermostat test script This tests all functionality
import wiringpi as io
import time
import Adafruit_CharLCD as LCD
import sht31
sht31 = sht31.SHT31(0)
LOW = 0
HIGH = 1
OUTPUT = 1
RELAY = 7
io.wiringPiSetup()
io.pinMode(RELAY,OUTPUT)
lcd = LCD.Adafruit_CharLCDPlate()
# Test Relay
io.digitalWrite(RELAY,HIGH)
time.sleep(1)
io.digitalWrite(RELAY,LOW)
time.sleep(1)
# activate screen
lcd.set_color(1,1,1)
lcd.clear()
time.sleep(1)
lcd.message('Hello!')
time.sleep(1)
# initialize temp
temperature, humidity = sht31.get_temp_and_humidity()
f = temperature * 9 / 5 + 32
h = humidity
print "Temperature: %s in celcius" % temperature
print "Humidity: %s" % h
print "Temperature %s in F" % f
buttons = ( (LCD.SELECT, 'Select'),
(LCD.LEFT, 'Left'),
(LCD.UP, 'Up'),
(LCD.DOWN, 'Down'),
(LCD.RIGHT, 'Right') )
counter = 25;
ideal_temp = 70.0
last_message = "Hello!"
lcd.clear()
while True:
counter += 1
time.sleep(.25)
if counter % 20 == 0:
temperature, humidity = sht31.get_temp_and_humidity()
f = round((temperature * 9 / 5 + 32),1)
h = round(humidity, 1)
if counter > 40:
counter = 0
lcd.clear()
lcd.message("Temp " + str(f) + " %rh\nSet " + str(ideal_temp) + " " + str(h))
for button in buttons:
if lcd.is_pressed(button[0]):
if button[1] == 'Select':
if sht31.check_heater_status():
sht31.turn_heater_off()
print "sht31 Heater Off"
else:
sht31.turn_heater_on()
print "sht31 Heater On"
if button[1] == 'Up':
ideal_temp += 1
if button[1] == 'Down':
ideal_temp -= 1
if f < ideal_temp:
io.digitalWrite(RELAY,HIGH)
else:
io.digitalWrite(RELAY,LOW)