Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,17 @@
# There are only two breakoutboards supported.
# max31855 - only supports type K thermocouples
# max31856 - supports many thermocouples
max31855 = 1
max31855 = 0
max31856 = 0
modbus = 1

modbus_port_name = "/dev/ttyUSB0"
modbus_slave_address = 1
modbus_baudrate = 38400
modbus_registernumber = 12
modbus_decimal = 1


# uncomment these two lines if using MAX-31856
import adafruit_max31856
thermocouple_type = adafruit_max31856.ThermocoupleType.K
Expand Down
37 changes: 37 additions & 0 deletions lib/oven.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def choose_tempsensor(self):
return Max31855()
if config.max31856:
return Max31856()
if config.modbus:
return Modbus()


class SimulatedBoard(Board):
'''Simulated board used during simulations.
Expand Down Expand Up @@ -323,6 +326,40 @@ def raw_temp(self):
raise Max31856_Error(k)
return temp

class Modbus(TempSensorReal):
'''each subclass expected to handle errors and get temperature'''
def __init__(self):
TempSensorReal.__init__(self)
log.info("thermocouple modbus")
import minimalmodbus

port = config.modbus_port_name
slave = config.modbus_slave_address
baudrate = config.modbus_baudrate
self.register = config.modbus_registernumber
self.decimal = config.modbus_decimal

self.instrument = minimalmodbus.Instrument(port, slave)
self.instrument.serial.baudrate = baudrate

"""
if (config.ac_freq_50hz == True):
self.thermocouple.noise_rejection = 50
else:
self.thermocouple.noise_rejection = 60
"""

def raw_temp(self):
# The underlying adafruit library does not throw exceptions
# for thermocouple errors. Instead, they are stored in
# dict named self.thermocouple.fault. Here we check that
# dict for errors and raise an exception.
# and raise Max31856_Error(message)

temp = self.instrument.read_register(self.register, self.decimal)

return temp

class Oven(threading.Thread):
'''parent oven class. this has all the common code
for either a real or simulated oven'''
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ adafruit-circuitpython-max31856
# for folks using sw spi (bit banging)
adafruit-circuitpython-bitbangio

# for folks using modbud input modules
minimalmodbus
# untested - for PT100 platinum thermocouples
#adafruit-circuitpython-max31865

Expand Down
19 changes: 18 additions & 1 deletion test-thermocouple.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,30 @@
print("thermocouple: adafruit max31856")
sensor = adafruit_max31856.MAX31856(spi, cs)



print("Degrees displayed in %s\n" % (config.temp_scale))

temp = 0
while(True):
time.sleep(1)
try:
temp = sensor.temperature
if(config.modbus):
import minimalmodbus

port = config.modbus_port_name
slave = config.modbus_slave_address
baudrate = config.modbus_baudrate
register = config.modbus_registernumber
decimal = config.modbus_decimal

instrument = minimalmodbus.Instrument(port, slave)
instrument.serial.baudrate = baudrate

temp = instrument.read_register(register, decimal)
else:

temp = sensor.temperature
scale = "C"
if config.temp_scale == "f":
temp = temp * (9/5) + 32
Expand Down