More descriptions on the hook up.
[heatpump.git] / heatpump.py
1 import piplates.DAQCplate as DAQC
2 import time
3 from decimal import Decimal
4 #DAQC.setDOUTbit(0,0)
5 #thermistor reading function
6 def compressor(state=None):
7 if state==None:
8 return DAQC.getDOUTbyte(0)
9 if state==True:
10 DAQC.setDOUTbit(0,0)
11 if state==False:
12 DAQC.clrDOUTbit(0,0)
13
14 def temp_get(volts,supply_voltage=5):
15 divider_resistor=1500
16 ohms = Decimal(divider_resistor*supply_voltage/volts-divider_resistor) #calculate the ohms of the thermisttor
17 #IVT oem NTC
18 a = Decimal(1.298022762e-3)
19 b = Decimal(2.365068126e-4)
20 c = Decimal(0.9305914923e-7)
21 #Steinhart Hart Equation
22 # T = 1/(a + b[ln(ohm)] + c[ln(ohm)]^3)
23 temp = 1/(a + b*ohms.ln() + c*ohms.ln()**3)
24 tempc = temp - Decimal(273.15) #K to C
25 return tempc
26
27 while(True):
28 vv_retur=temp_get(DAQC.getADC(0,0),DAQC.getADC(0,8))
29 vv_top=temp_get(DAQC.getADC(0,2),DAQC.getADC(0,8))
30 hetgas=temp_get(DAQC.getADC(0,1),DAQC.getADC(0,8))
31 print("VV retur:",vv_retur)
32 print("VV top:",vv_top)
33 print("Hetgas:",hetgas)
34 print("Kompressor:",compressor())
35 if vv_top < 35:
36 compressor(True)
37 print("Toptemp under 35. Startar kompressor")
38 if vv_top > 45:
39 compressor(False)
40 print("Toptemp över 45. Stänger av kompressor")
41 # import pdb;pdb.set_trace()
42 time.sleep(1)
43