-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
executable file
·86 lines (64 loc) · 1.83 KB
/
test.py
File metadata and controls
executable file
·86 lines (64 loc) · 1.83 KB
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
#!/usr/bin/python3
# coding: utf8
import time
import max6675
import ssr
import RPi.GPIO as GPIO
from threading import Timer
from simple_pid import PID
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
sample_time = 4
setpoint = 28
cs1 = 4
cs2 = 5
sck = 24
so = 25
max6675.set_pin(cs1, sck, so, 1)
max6675.set_pin(cs2, sck, so, 1)
ssr.set_pin(17)
ssr.set_pin(21)
pidA = PID(5, 0.01, 0.1, setpoint = setpoint)
pidB = PID(5, 0.01, 0.1, setpoint = setpoint)
pidA.output_limits = (0, 100)
pidB.output_limits = (0, 100)
# power percentage: a+b should be 100%
percentageA = 50
percentageB = 50
# Timer references for cancellation
timerA = None
timerB = None
try:
while True:
tempA = max6675.read_temp(cs1)
tempB = max6675.read_temp(cs2)
controlA = pidA(tempA) * percentageA/100
controlB = pidB(tempB) * percentageB/100
print('Thermocouple A Temperature: {0:0.1F}°C, control: {1:0.0F}%'.format(tempA, controlA))
print('Thermocouple B Temperature: {0:0.1F}°C, control: {1:0.0F}%'.format(tempB, controlB))
# Cancel previous timers if they exist
if timerA is not None and timerA.is_alive():
timerA.cancel()
if timerB is not None and timerB.is_alive():
timerB.cancel()
#SSR A
if controlA > 0:
ssr.on(17)
if controlA < 100:
timerA = Timer(sample_time*controlA/100, lambda: ssr.off(17))
timerA.start()
else:
ssr.off(17)
# SSR B
if controlB > 0:
ssr.on(21)
if controlB < 100:
timerB = Timer(sample_time*controlB/100, lambda: ssr.off(21))
timerB.start()
else:
ssr.off(21)
# wait till next sample
time.sleep(sample_time)
except KeyboardInterrupt:
pass
GPIO.cleanup()