-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_iseries_temp_controller_rev1.0.py
81 lines (70 loc) · 2.66 KB
/
main_iseries_temp_controller_rev1.0.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
# main.py -- put your code here!
from pyb import Pin, ExtInt, UART, delay
from time import sleep
import pyb
start_pin = Pin('Y3', Pin.IN, Pin.PULL_UP) # PB8 monitors start button push event.
stop_pin = Pin('X2', Pin.IN, Pin.PULL_UP) # PA1 monitors stop button push event.
led_pin = Pin('X5', Pin.OUT_PP) # PA4 drives LED indicator.
led_pin.low()
uart = UART(2, 9600) # UART2 communcates to CSi8.
uart.init(9600, bits=7, parity=1, stop=1)
start_pressed = 0
# stop_pressed = 0
t1_set = 200
t1_last = 30
t2_set = 600
t1_t2_step = 1
t1_t2_last = 480
t2_last = 120
off_last = 390
cmd_prefix = '*P012' # Write to RAM of point 1 with positive sign and decimal point 2
cmd_standby = '*D03' # Standby mode with output off
cmd_dis_standby = '*E03'# Disable standby
start_value = 0
stop_value = 0
print("stop_pin.value="+str(stop_pin.value()))
print("start_pin.value="+str(start_pin.value()))
def start_callback(line):
global start_pressed, start_int, pyb, start_pin, stop_pin
#print("%d"%start_pin.value())
if ((start_pin.value() == 0) and (stop_pin.value() == 1)): # 1 = not pressed
start_int.disable()
start_pressed = 1
print("start_pressed=========")
#pyb.hard_reset()
else:
#start_pressed = 0
print("should not get here=========")
start_int = pyb.ExtInt(start_pin, pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_UP, start_callback)
def stop_callback(line):
global start_pressed, stop_int, stop_value, start_pin, stop_pin, pyb, led_pin
#print("stop pressed = "+str(stop_value))
if stop_pin.value() == 0: # 1 = not pressed
stop_int.disable()
led_pin.low()
pyb.hard_reset() #reset and reboot
print("stop pressed")
start_pressed = 0
stop_int = pyb.ExtInt(stop_pin, pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_UP, stop_callback)
while (1):
#global pyb
print("one loop passed-----"+str(start_pressed))
sleep(1)
if start_pressed == 1:
uart.write(cmd_dis_standby+'\r') # Disable standby from last heating cycle
led_pin.high()
#sleep(10) #for test
uart.write(cmd_prefix+'%05X'%t1_set+'\r') # Set temperature point 1, i.e. 20C
sleep(t1_last*60) #Keep t1_set for t1_last minutes
#sleep(2) #for test
for i in range (t1_set, t2_set+1, t1_t2_step): #Increase 1C per loop
uart.write(cmd_prefix+'%05X'%i+'\r') # Increase temperature point 1 until t2_set
sleep((t1_t2_last*60/((t2_set-t1_set)/t1_t2_step)))
#sleep(1) #for test
sleep(t2_last*60) #Keep t2_set for t2_last minutes
#sleep(300) #for test
uart.write(cmd_standby+'\r') # Shut off heater
sleep(off_last*60) #Keep off state for off_last minutes
#sleep(2) #for test
led_pin.low()
pyb.hard_reset() # Mission accomplished then reset and reboot