More descriptions on the hook up.
[heatpump.git] / heatpump.py
CommitLineData
ec56fabb
MF
1import piplates.DAQCplate as DAQC
2import time
3from decimal import Decimal
aad4ecbc 4#DAQC.setDOUTbit(0,0)
ec56fabb
MF
5#thermistor reading function
6def 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
14def temp_get(volts,supply_voltage=5):
aad4ecbc 15 divider_resistor=1500
ec56fabb
MF
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
27while(True):
28 vv_retur=temp_get(DAQC.getADC(0,0),DAQC.getADC(0,8))
a45ebe4b 29 vv_top=temp_get(DAQC.getADC(0,2),DAQC.getADC(0,8))
ec56fabb
MF
30 hetgas=temp_get(DAQC.getADC(0,1),DAQC.getADC(0,8))
31 print("VV retur:",vv_retur)
a45ebe4b 32 print("VV top:",vv_top)
ec56fabb
MF
33 print("Hetgas:",hetgas)
34 print("Kompressor:",compressor())
aad4ecbc 35 if vv_top < 35:
ec56fabb 36 compressor(True)
aad4ecbc
MF
37 print("Toptemp under 35. Startar kompressor")
38 if vv_top > 45:
ec56fabb 39 compressor(False)
aad4ecbc 40 print("Toptemp över 45. Stänger av kompressor")
ec56fabb
MF
41# import pdb;pdb.set_trace()
42 time.sleep(1)
43