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, 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 main(): #------INICIALIZAMOS TERMOMETRO------ cs_pin = 13 #chip select clock_pin = 11 data_pin = 15 units = "c" thermocouple = MAX6675(cs_pin, clock_pin, data_pin, units, GPIO.BOARD) while True: try: tc = thermocouple.get() file = open("temp_term", "w+") file.write(str(tc)) file.close() #print(str(tc)) except Exception: pass time.sleep(0.5) thermocouple.cleanup()
from utime import sleep_ms from umqtt_simple import MQTTClient from machine import Pin, unique_id from micropython import schedule, alloc_emergency_exception_buf from esp_init import ESP_init import uheapq from max6675 import MAX6675 from sht30 import SHT30 from ds3231_time import cl_id import gc alloc_emergency_exception_buf(100) sensor_k = MAX6675() sensor3 = SHT30() button = Pin(0, Pin.IN) SERVER = "192.168.100.101" CLIENT_ID = cl_id() TOPIC = b"esp001log" DATA_TP = b"data_" + CLIENT_ID sub_flag = 100 i_pum = 0 i_snd = 0 i_data = [] uheapq.heapify(i_data) class Foo(): def __init__(self): self.push_ref = self.push p2 = Pin(2, Pin.IN) p2.irq(trigger=Pin.IRQ_RISING, handler=self.cb)
from horno_controller import Horno import utime # Timer ringOn = 0 timerFinish = 0 # ms # Digital Outputs buzzer = 2 dOuts = DigitalOutputs595(2, 0, 13, 3) # Sensor so = Pin(12, Pin.IN) sck = Pin(14, Pin.OUT) cs = Pin(16, Pin.OUT) tempSensor = MAX6675(sck, cs, so) # Oven controler controller = Horno(tempSensor, dOuts) # Display display = Display() values = { "temperature": controller.temperature, "regulator": controller.pidParams.output, "error": (controller.pidParams.setpoint - controller.pidParams.input), "inAuto": controller.pid.inAuto, "ready": controller.ready, "timer": (timerFinish - utime.ticks_ms()), "on": controller.on,
from max6675 import MAX6675 from machine import Pin import time so = Pin(12, Pin.IN) sck = Pin(14, Pin.OUT) cs = Pin(16, Pin.OUT) max = MAX6675(sck, cs, so) for _ in range(10): print(max.read()) time.sleep(1)
from max6675 import MAX6675 from machine import Pin import time import urequests import config from machine import Timer from PID import PID import machine import sys sck = Pin(14, Pin.OUT) cs = Pin(12, Pin.OUT) so = Pin(13, Pin.IN) led = Pin(2, Pin.OUT) sens_pipe = MAX6675(sck, cs, so) def store(data): try: led.off() # print("HTTP posting to {}".format(config.db)) resp = urequests.post(config.db, data=data, headers={'Content-Type': 'text/plain'}) if resp.status_code != 204: print('HTTP response "{}", text: {} '.format( resp.reason, resp.text)) print("DB ERROR")
TC-MOD test script - MAX6675 Type-K thermocouple amplifier ========================================================== This library supports the use of the TC-MOD (exposing UEXT connector) for thermocouple reading under MicroPython. For wiring, see the: * Pyboard-Uno-R3 adapter : https://github.com/mchobby/pyboard-driver/tree/master/UNO-R3 * Pyboard UEXT connector : https://github.com/mchobby/pyboard-driver/tree/master/UEXT Author(s): * Meurisse D for MC Hobby sprl """ from max6675 import MAX6675 from time import sleep print( "MAX6675 - thermocouple reading") # PYBOARD-UEXT adapter -> cs_pin = "Y5" # sensor = MAX6675( data_pin = "Y7", clk_pin = "Y6" , cs_pin="Y5" ) # PYBOARD-UNO-R3 adapter -> cs_pin = "X8" sensor = MAX6675( data_pin = "Y7", clk_pin = "Y6" , cs_pin="X8" ) # Wait the MAX6675 to stabilize sleep( 0.500 ) while True: print( "C = %s" % sensor.temperature ) sleep(1)
def ESP_init(cl_s=b'esp001data'): f_log = StringIO() f_log.write('{"ESP_init":{\n') atemp = '"DATA_topic":"%s",\n' % (cl_s.decode()) print(atemp) f_log.write(atemp) try: if ds_tm.lost_time(): atemp = '"DS3231":"lost_time",\n' print(atemp) f_log.write(atemp) raise else: ds_tm.settime() atemp = '"DS3231 SetTime":"OK",\n' print(atemp) f_log.write(atemp) try: ntptime_cn.time() utime.sleep_ms(200) ntptime_cn.settime() ds_tm.sync_rtc2ntp() ds_tm.settime() atemp = '"NTP & RTC SyncTime":"OK",\n' print(atemp) f_log.write(atemp) except: pass except: ntptime_cn.time() utime.sleep(3) ntptime_cn.settime() atemp = '"NTP SetTime":"OK",\n' print(atemp) f_log.write(atemp) try: ds_tm.sync_rtc2ntp() ds_tm.settime() atemp = '"NTP & RTC SyncTime":"OK",\n' print(atemp) f_log.write(atemp) except: pass finally: atemp = '"Time":"%d-%02d-%02d %02d:%02d:%02d GMT",\n"Day_W":%d,"Day_Y":%d,\n' % ( utime.localtime()) print(atemp) f_log.write(atemp) try: atemp = '"DS3231 SQW":"1Hz Out Start%d",\n' % (ds_tm.sqw_1hz()) print(atemp) f_log.write(atemp) except: atemp = '"DS3231 SQW":"1Hz Out ERROR",\n' print(atemp) f_log.write(atemp) try: sensor3 = SHT30() temperature, humidity = sensor3.measure() del sensor3 atemp = '"ambient Temperature":"%f ºC","ambient Humidity":"%f %%",\n' % ( temperature, humidity) print(atemp) f_log.write(atemp) atemp = '"Sensor SHT30":"OK",\n' print(atemp) f_log.write(atemp) except: pass try: sensor_k = MAX6675() atemp = '"K Thermocouple":"%f ºC",\n"Sensor MAX6675":"OK"}}..' % ( sensor_k.measure()) del sensor_k print(atemp) f_log.write(atemp) except: pass f_str = f_log.getvalue() f_log.close() return f_str
from time import sleep_ms, sleep_us, ticks_ms from math import sqrt from PID import PID from max6675 import MAX6675 from lib.esp8266_i2c_lcd import I2cLcd # I2C scl = Pin(16, Pin.OPEN_DRAIN, Pin.PULL_UP) sda = Pin(2, Pin.OPEN_DRAIN, Pin.PULL_UP) # Thermo K MAX6675 so = Pin(26, Pin.IN) sck = Pin(32, Pin.OUT) cs = Pin(33, Pin.OUT) maxK = MAX6675(sck, cs, so) i2c = I2C(1, scl=scl, sda=sda, freq=100000) i2c_exp_addr = 34 i2c_lcd_addr = 39 lcd = I2cLcd(i2c, i2c_lcd_addr, 4, 16) # addr, rows, col # ADC pin temp_adc = ADC(Pin(35)) # Set ADC pin settemp_adc = ADC(Pin(34)) # Range 50+ C temp_adc.atten(ADC.ATTN_6DB)
def __init__(self, config_dict, OLED_Status=True): self.cfg = config_dict # 配置文件信息 self.pwm_out = PWM(Pin(2), freq=5, duty=1023) self.max6675 = MAX6675(None, None, None, Pin(16, Pin.OUT)) # max6675使用的是硬件SPI,会设置GPIO13引脚,若使用GPIO13(蜂鸣器)请后初始化 self.beep = Pin(13, Pin.OUT) # 蜂鸣器引脚 self.beep.value(1) # 关闭蜂鸣器 self.beep_flag1 = True self.beep_flag2 = False # 只当编码器值改变时才置为True # 安全温度阈值,当 实际温度-与设定温度>self.max_error_temperature 触发报警 self.max_error_temperature = 30 self.buf_len = 3 self.buf_index = 0 self.temperature_err_flag = True self.temperature_buf = [20] * self.buf_len self.buf_sum = 20 * self.buf_len self.temp_now = self.max6675.read_temperature() self.temp_target = 50 # 进行PID控制的阈值(以致于前期可以持续快速升温) self.temp_DValue = 20 self.pid_enable = False self.pid_dt = 300 # PID的调整时间ms gc.collect() # 创建OLED显示器 # construct an I2C bus,软件i2c所有接口都适用 self.interface = Interface(self, Pin(1), Pin(3), OLED_Status) self.interface.temperature_now = self.temp_now self.interface.temperature_target = self.temp_target self.interface.opt_deal() # 创建编码器控制对象 self.knobs = EC11(4, 5, 0) # 创建pid控制对象 # self.pid_contorller = PID(6.0, 18.0, 6.0, self.pid_dt/1000) # self.pid_contorller = PID(6.0, 3.0, 10.0, self.pid_dt/1000) self.pid_contorller = PID(1.0, 0.3, 6.0, self.pid_dt/1000) # 创建蜂鸣器的定时器 self.beep_start_timer = Timer(-1) # periodic with 100ms period # mode: Timer.ONE_SHOT / Timer.PERIODIC self.beep_start_timer.init(period=1000, mode=Timer.PERIODIC, callback=self.start_beep) # 创建温度读取的定时器 self.temperature_timer = Timer(-1) # periodic with 100ms period # mode: Timer.ONE_SHOT / Timer.PERIODIC self.temperature_timer.init( period=200, mode=Timer.PERIODIC, callback=self.get_temperature) # 创建按键检测的定时器 self.knobs_timer = Timer(-1) # periodic with 100ms period # mode: Timer.ONE_SHOT / Timer.PERIODIC self.knobs_timer.init( period=200, mode=Timer.PERIODIC, callback=self.check_knobs) # 创建pid调节的定时器 self.adjust_timer = Timer(-1) # mode: Timer.ONE_SHOT / Timer.PERIODIC self.adjust_timer.init( period=self.pid_dt, mode=Timer.PERIODIC, callback=self.adjust_temperature) gc.collect()
# Modify below section as required CONFIG = { # Configuration details of the MQTT broker "MQTT_BROKER": "192.168.0.107", "USER": "", "PASSWORD": "", "PORT": 1883, # unique identifier of the chip "CLIENT_ID": b"esp8266_04" } Topic1 = b"esp4/sensor" Topic2 = b"esp4/time" t = 10 esp.sleep_type(esp.SLEEP_LIGHT) K = MAX6675(3, 0, 2) def sub_cb(topic, msg): global t msg = json.loads(msg) t = msg['time'] def connect_wifi(): sta_if = network.WLAN(network.STA_IF) if not sta_if.isconnected(): sta_if.active(True) sta_if.connect('Tenda_1F7DA0', 'aidpoy1505') while not sta_if.isconnected(): pass
#!/usr/bin/python from max6675 import MAX6675, MAX6675Error import time cs_pin = 8 clock_pin = 11 data_pin = 9 units = "c" thermocouple = MAX6675(cs_pin, clock_pin, data_pin) thermocouple.cleanup() time.sleep(1) thermocouple = MAX6675(cs_pin, clock_pin, data_pin) t_end = time.time() + 30 while time.time() < t_end: print(thermocouple.get()) time.sleep(1) thermocouple.cleanup()
from max6675 import MAX6675 from machine import Pin from time import sleep from board import A6, A14, A15 #When configured as open drain, a pin is pulled low (tied to GND) when set to 0, and open when set to 1. #sck -> low #cs -> high #so -> low so = Pin(A14, mode=Pin.IN) cs = Pin(A15, mode=Pin.OUT) sck = Pin(A6, mode=Pin.OUT) thermo = MAX6675(sck, cs, so) for _ in range(10): print(thermo.read()) sleep(1)
def __init__(self, sck=None, cs=None, so=None): sck = sck or Pin(18, Pin.OUT) cs = cs or Pin(4, Pin.OUT) so = so or Pin(19, Pin.IN) self.sensor = MAX6675(sck=sck, cs=cs, so=so) self.values = []