def __init__(self, time_step): TempSensor.__init__(self, time_step) self.run_num = 0 if config.max6675: log.info("init MAX6675") self.thermocouple = MAX6675(config.gpio_sensor_cs, config.gpio_sensor_clock, config.gpio_sensor_data, config.temp_scale) if config.max31850: log.info("init MAX31850") if (config.max6675 == 0): self.thermocouple = MAX31850(config.w1_id_pcb) self.thermocouple_bottom = MAX31850(config.w1_id_bottom) self.thermocouple_top = MAX31850(config.w1_id_top) if config.max31855: log.info("init MAX31855") self.thermocouple = MAX31855(config.gpio_sensor_cs, config.gpio_sensor_clock, config.gpio_sensor_data, config.temp_scale) if config.max31855spi: log.info("init MAX31855-spi") self.thermocouple = MAX31855SPI( spi_dev=SPI.SpiDev(port=0, device=config.spi_sensor_chip_id))
def __init__(self): TempSensor.__init__(self) self.sleeptime = self.time_step / float( config.temperature_average_samples) self.bad_count = 0 self.ok_count = 0 self.bad_stamp = 0 if config.max31855: log.info("init MAX31855") from max31855 import MAX31855, MAX31855Error self.thermocouple = MAX31855(config.gpio_sensor_cs, config.gpio_sensor_clock, config.gpio_sensor_data, config.temp_scale) if config.max31856: log.info("init MAX31856") from max31856 import MAX31856 software_spi = { 'cs': config.gpio_sensor_cs, 'clk': config.gpio_sensor_clock, 'do': config.gpio_sensor_data, 'di': config.gpio_sensor_di } self.thermocouple = MAX31856( tc_type=config.thermocouple_type, software_spi=software_spi, units=config.temp_scale, ac_freq_50hz=config.ac_freq_50hz, )
def __init__(self, time_step): TempSensor.__init__(self, time_step) if config.max6675: log.info("init MAX6675") self.thermocouple = MAX6675(config.gpio_sensor_cs, config.gpio_sensor_clock, config.gpio_sensor_data, "c") if config.max31855: log.info("init MAX31855") self.thermocouple = MAX31855(config.gpio_sensor_cs, config.gpio_sensor_clock, config.gpio_sensor_data, "c")
def __init__(self, time_step): TempSensor.__init__(self, time_step) if config.max6675: log.info("init MAX6675") self.thermocouple = MAX6675(config.gpio_sensor_cs, config.gpio_sensor_clock, config.gpio_sensor_data, config.temp_scale) if config.max31855: log.info("init MAX31855") self.thermocouple = MAX31855(config.gpio_sensor_cs, config.gpio_sensor_clock, config.gpio_sensor_data, config.spi_hw_channel, config.temp_scale)
def __init__(self, time_step): TempSensor.__init__(self, time_step) if config.max6675: log.info("init MAX6675") self.thermocouple = MAX6675(config.gpio_sensor_cs, config.gpio_sensor_clock, config.gpio_sensor_data, config.temp_scale) if config.max31855: log.info("init MAX31855") self.thermocouple = MAX31855(config.gpio_sensor_cs, config.gpio_sensor_clock, config.gpio_sensor_data, config.temp_scale) if config.max31855spi: log.info("init MAX31855-spi") self.thermocouple = MAX31855SPI(spi_dev=SPI.SpiDev(port=0, device=config.spi_sensor_chip_id))
def __init__(self): TempSensor.__init__(self) if config.max31855: log.info("init MAX31855") from max31855 import MAX31855, MAX31855Error self.thermocouple = MAX31855(config.gpio_sensor_cs, config.gpio_sensor_clock, config.gpio_sensor_data, config.temp_scale) if config.max31856: log.info("init MAX31856") from max31856 import MAX31856, MAX31856Error software_spi = { 'cs': config.gpio_sensor_cs, 'clk': config.gpio_sensor_clock, 'do': config.gpio_sensor_data } self.thermocouple = MAX31856(tc_type=config.thermocouple_type, software_spi=sofware_spi, units=config.temp_scale)
def __init__(self, config): self.config = config self.sensor = MAX31855(hwspi=self.config['max31855_pins']['hwspi'], cs=self.config['max31855_pins']['cs'], miso=self.config['max31855_pins']['miso'], sck=self.config['max31855_pins']['sck'], offset=self.config['temp_offset']) self.oven = machine.Pin(self.config['oven_pin'], machine.Pin.OUT, value=0) self.temp_cali_scr = lv.obj() self.page = lv.page(self.temp_cali_scr) self.page.set_size(self.temp_cali_scr.get_width(), self.temp_cali_scr.get_height()) self.page.align(None, lv.ALIGN.CENTER, 0, 0) self.label = lv.label(self.page) self.label.set_long_mode(lv.label.LONG.BREAK) self.label.set_width(self.page.get_fit_width()) self.page_text = '' self.tim = machine.Timer(-1) self.start_time = None self.start_temp = None self.last_temp = None self.lag_temp = None self.lag_time = None self.cooling_counter = 0 self.check_temp = 100
def run ( self ): global control_interval global cs_pins global clock_pin global data_pin global units global heater_state global temps global air_temp global log_on global log_off global set_temperature global min_temperature global max_temperature GPIO.setmode(GPIO.BOARD) print "Starting heater thread" for relay_pin in relay_pins: GPIO.setup(relay_pin, GPIO.OUT) GPIO.output(relay_pin, GPIO.LOW) try: while 1: # Control the heater forever while powered thermocouples = [] print "" print "Measuring... %s" % (time.ctime(time.time())) now = datetime.datetime.now().time() set_temperature = temperature_schedule[1]['temp'] # Default to the first timed temperature for count in temperature_schedule: if (now >= temperature_schedule[count]['time']): set_temperature = temperature_schedule[count]['temp'] # Keep selecting a new temperature if the time is later than the start of the time schedule channel = 1 for cs_pin in cs_pins: thermocouples.append(MAX31855(cs_pin, clock_pin, data_pin, units, GPIO.BOARD)) for thermocouple, relay_pin, cal, meas in zip(thermocouples, relay_pins, calibrate, measured): if (channel == 1): air_temp = int(thermocouple.get_rj()) try: tc = int(thermocouple.get()) + cal - meas temps[channel]['temp'] = tc if (tc < min_temperature): min_temperature = tc if (tc > max_temperature): max_temperature = tc except MAX31855Error as e: tc = "Error" temps[channel]['temp'] = "Error: " + e.value channel = channel + 1 print "Temperature: " + str(tc) + ". Set Temperature: " + str(set_temperature) print "Min: " + str(min_temperature) + ", Max: " + str(max_temperature) if tc == "Error": GPIO.output(relay_pin, GPIO.LOW) # Turn off Relay (fault condition - avoid overheating) heater_state = "Error: Off" print "Error: Relay off" else: if tc < set_temperature: GPIO.output(relay_pin, GPIO.HIGH) # Turn on relay heater_state = "On" if (log_status == "On"): log_on = log_on + 1 print "Relay on" else: GPIO.output(relay_pin, GPIO.LOW) # Turn off relay heater_state = "Off" if (log_status == "On"): log_off = log_off + 1 print "Relay off" for thermocouple in thermocouples: thermocouple.cleanup() time.sleep(control_interval) except KeyboardInterrupt: GPIO.cleanup()
#!/usr/bin/python from max31855 import MAX31855, MAX31855Error from time import sleep cs_pin = 18 #15 clock_pin = 16 #29 data_pin = 15 #31 units = "f" thermocouple = MAX31855(cs_pin, clock_pin, data_pin, units) running = True while (running): try: try: tc = thermocouple.get() except MAX31855Error as e: tc = "Error: " + e.value print("Temperature: " + str(tc)) sleep(1.0) except KeyboardInterrupt: running = False thermocouple.cleanup()
import numpy as np from max31855 import MAX31855 # Ce fichier transforme la donnee brute (sortie de capteur) en # mesure un peu filtree. clk_pin = 13 data_pin = 19 cs_pin = 26 th = MAX31855(cs_pin, clk_pin, data_pin) FW = 5 raw = np.ones(FW) * th.get() raw_idx = 0 # filtre = mediane des 5 dernieres valeurs def get(): global raw_idx, FW, th raw[raw_idx] = th.get() raw_idx += 1 raw_idx %= FW return np.median(raw)
interval = 1.0 #Sec #######Input GPIO pins for MAX31855######## from max31855 import MAX31855, MAX31855Error cs_pin = 16 #SPI1 CS0 clock_pin = 21 #SPI1 SCLK data_pin = 19 #SPI1 MISO units = "c" #(optional) unit of measurement to return. ("c" (default) | "k" | "f") properties = { 'name': 'Thermocouple', 'amplifier_model': 'MAX31855', #'captured_at': '', 'units': 'c', } MAX31855_TEMPS = MAX31855(cs_pin, clock_pin, data_pin, units) ####### SUBFUNCTIIONS ######## def get_ambient(): #Varb for class with given GPIO inputs return MAX31855_TEMPS.get() ####### MAIN LOOP ######## try: while True: t = datetime.utcnow() # Get ambient ambient_temperature = get_ambient()
def setUp(self): self.thermocouple = MAX31855(1, 2, 3, 4)
(sensnum, temp)) conn.commit() conn.close() #Sensor 1:[0], Sensor 2:[1] #GPIO.BOARD means use the pin numbers on the pi board (NOT the GPIO Numbers)!!! cs_pins = [16, 38] clock_pins = [22, 36] data_pins = [18, 40] t = [] units = "f" for x in range(0, 2): t.append( MAX31855(cs_pins[x], clock_pins[x], data_pins[x], units, GPIO.BOARD)) for i in range(0, 2): if t[i].get() == -1: log_errors(i + 1, "No Connection") elif t[i].get() == -2: log_errors(i + 1, "Thermocouple short to ground") elif t[i].get() == -3: log_errors(i + 1, "Thermocouple short to VCC") elif t[i].get() == -4: log_errors(i + 1, "Unknown Error") else: log_temperature(i + 1, t[i].get()) t[0].cleanup() t[1].cleanup()
#!/usr/bin/python from max31855 import MAX31855, MAX31855Error units = "c" thermocouples = [] thermocouples.append(MAX31855(24, 25, 18, units)) # ET thermocouples.append(MAX31855(22, 5, 27, units)) # BT data = [] for thermocouple in thermocouples: data.append(thermocouple.get()) print("{},{}".format(data[0], data[1])) for thermocouple in thermocouples: thermocouple.cleanup()
PSK = "******" OVEN_RELAY_PIN = 2 TC_CS_PIN = 16 def do_connect(): import network wlan = network.WLAN(network.STA_IF) wlan.active(True) if not wlan.isconnected(): print('connecting to network...') wlan.connect(SSID, PSK) while not wlan.isconnected(): pass print('network config:', wlan.ifconfig()) return wlan # create oven, turn it off... oven = Pin(OVEN_RELAY_PIN, Pin.OUT) oven.off() #initialize SPI for thermocouple spi = SPI(1, baudrate=5000000, polarity=0, phase=0) cs = Pin(TC_CS_PIN, Pin.OUT) #initalize thermocouple thermocouple = MAX31855(spi, cs) # connect to wifi wlan = do_connect()
def run(self): global sensors global temps global air_temp global cs_pins global clock_pin global data_pin global units thermocouples = [] for cs_pin in cs_pins: thermocouples.append( MAX31855(cs_pin, clock_pin, data_pin, units, GPIO.BOARD)) while True: # TODO: Ideally want to detect when closing to exit the loop channel = 1 now = datetime.datetime.now() #print(now) timeString = now.strftime("%H:%M on %d-%m-%Y") for thermocouple in thermocouples: if (channel == 1): air_temp = int(thermocouple.get_rj()) sensors[0]['temperature'] = air_temp try: tc = str(int(thermocouple.get())) temps[channel]['time'] = now temps[channel]['age'] = '' temps[channel][ 'temperature'] = tc + u'\N{DEGREE SIGN}' + units.upper( ) temps[channel][ 'last'] = tc # Record the last valid measurement sensors[channel]['temperature'] = tc sensors[channel]['age'] = '' except MAX31855Error as e: tc = "Error: " + e.value if (temps[channel]['time'] == 'Never'): age_string = "(Never measured)" temps[channel]['temperature'] = tc else: temps[channel]['temperature'] = temps[channel]['last'] age = now - temps[channel]['time'] if (age.days == 0): if (age.seconds < 60): age_string = "(" + str(age.seconds) + "s)" else: if ((int(age.seconds / 60)) == 1): age_string = "(" + str( int(age.seconds / 60)) + " min)" else: if (age.seconds > (60 * 60)): # > 1 hour if ((int(age.seconds / 60 / 60)) == 1): age_string = "(" + str( int(age.seconds / 60 / 60)) + " hour)" else: age_string = "(" + str( int(age.seconds / 60 / 60)) + " hours)" else: age_string = "(" + str( int(age.seconds / 60)) + " mins)" if (age.seconds > (5 * 60)): # 5 mins temps[channel][ 'temperature'] = tc + ". Last: " + str( temps[channel]['last']) else: if (age.days == 1): age_string = "(" + str(age.days) + " day)" else: age_string = "(" + str(age.days) + " days)" temps[channel]['temperature'] = tc temps[channel]['age'] = age_string sensors[channel]['temperature'] = temps[channel][ 'temperature'] sensors[channel]['age'] = age_string channel = channel + 1 #end = datetime.datetime.now() #print(end-now) time.sleep(measurement_interval) for thermocouple in thermocouples: thermocouple.cleanup()
import gc import utime import _thread from buzzer import Buzzer from gui import GUI from load_profiles import LoadProfiles from max31855 import MAX31855 from oven_control import OvenControl reflow_profiles = LoadProfiles(DEFAULT_ALLOY) gui = GUI(reflow_profiles, config) temp_sensor = MAX31855(hwspi=TEMP_HWSPI, cs=TEMP_CS, miso=TEMP_MISO, sck=TEMP_SCK, offset=TEMP_OFFSET) oven = machine.Pin(OVEN_PIN, machine.Pin.OUT, value=0) buzzer = Buzzer(BUZZER_PIN) timer = machine.Timer(0) def measure_temp(): while True: try: temp_sensor.read_temp() except Exception: print('Error occurs when measuring temperature.')