Works with MAX31856

This commit is contained in:
Chip Garner 2023-01-02 20:33:15 -08:00
parent 2df86242f3
commit 5b1c516260
4 changed files with 13 additions and 13 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ thumbs.db
#config.py #config.py
.idea/* .idea/*
state.json state.json
venv/*

View File

@ -60,10 +60,11 @@ except NotImplementedError:
### Thermocouple Adapter selection: ### Thermocouple Adapter selection:
# max31855 - bitbang SPI interface # max31855 - bitbang SPI interface
# max31856 - bitbang SPI interface. must specify thermocouple_type. # max31856 - bitbang SPI interface. must specify thermocouple_type.
max31855 = 1 max31855 = 0
max31856 = 0 max31856 = 1
# uncomment this if using MAX-31856 # uncomment these two lines if using MAX-31856
#thermocouple_type = ThermocoupleType.S import adafruit_max31856
thermocouple_type = adafruit_max31856.ThermocoupleType.K
# here are the possible max-31856 thermocouple types # here are the possible max-31856 thermocouple types
# ThermocoupleType.B # ThermocoupleType.B
@ -115,7 +116,7 @@ stop_integral_windup = True
######################################################################## ########################################################################
# #
# Simulation parameters # Simulation parameters
simulate = True simulate = False
sim_t_env = 255 # deg C sim_t_env = 255 # deg C
sim_c_heat = 500.0 # J/K heat capacity of heat element sim_c_heat = 500.0 # J/K heat capacity of heat element
sim_c_oven = 5000.0 # J/K heat capacity of oven sim_c_oven = 5000.0 # J/K heat capacity of oven

View File

@ -14,9 +14,7 @@ from geventwebsocket.handler import WebSocketHandler
from geventwebsocket import WebSocketError from geventwebsocket import WebSocketError
try: try:
sys.dont_write_bytecode = True
import config import config
sys.dont_write_bytecode = False
except: except:
print ("Could not import config file.") print ("Could not import config file.")
print ("Copy config.py.EXAMPLE to config.py and adapt it for your setup.") print ("Copy config.py.EXAMPLE to config.py and adapt it for your setup.")

View File

@ -289,12 +289,12 @@ class Max31856(TempSensorReal):
TempSensorReal.__init__(self) TempSensorReal.__init__(self)
log.info("thermocouple MAX31856") log.info("thermocouple MAX31856")
import adafruit_max31856 import adafruit_max31856
adafruit_max31856.ThermocoupleType(config.thermocouple_type) self.thermocouple = adafruit_max31856.MAX31856(self.spi,self.cs,
self.thermocouple = adafruit_max31856.MAX31856(self.spi,self.cs) thermocouple_type=config.thermocouple_type)
if (config.ac_freq_50hz == True): if (config.ac_freq_50hz == True):
self.thermocouple.noise_rejection(50) self.thermocouple.noise_rejection = 50
else: else:
self.thermocouple.noise_rejection(60) self.thermocouple.noise_rejection = 60
def raw_temp(self): def raw_temp(self):
# The underlying adafruit library does not throw exceptions # The underlying adafruit library does not throw exceptions
@ -303,7 +303,7 @@ class Max31856(TempSensorReal):
# dict for errors and raise an exception. # dict for errors and raise an exception.
# and raise Max31856_Error(message) # and raise Max31856_Error(message)
temp = self.thermocouple.temperature temp = self.thermocouple.temperature
for k,v in self.thermocouple.fault: for k,v in self.thermocouple.fault.items():
if v: if v:
raise Max31856_Error(k) raise Max31856_Error(k)
return temp return temp
@ -641,7 +641,7 @@ class RealOven(Oven):
def heat_then_cool(self): def heat_then_cool(self):
pid = self.pid.compute(self.target, pid = self.pid.compute(self.target,
self.board.temp_sensor.temperature + self.board.temp_sensor.temperature() +
config.thermocouple_offset, datetime.datetime.now()) config.thermocouple_offset, datetime.datetime.now())
heat_on = float(self.time_step * pid) heat_on = float(self.time_step * pid)