|
|
@@ -6,9 +6,8 @@ import micropython
|
|
|
import gc
|
|
|
import uasyncio
|
|
|
from machine import Pin,PWM,ADC
|
|
|
-from web_server import WebSrv
|
|
|
+# from web_server import WebSrv
|
|
|
from MicroWebSrv.upload_dat import upload
|
|
|
-from my_timer import MyTimer as Timer
|
|
|
|
|
|
def average(series, new_value):
|
|
|
series.append(new_value)
|
|
|
@@ -25,11 +24,8 @@ class Ntc():
|
|
|
self.VCC = 3344
|
|
|
self.temp = 0
|
|
|
self.temp_list = []
|
|
|
- self.tim = Timer(-1)
|
|
|
- self.tim.init(period=200, mode=Timer.PERIODIC,
|
|
|
- callback=self.cal_temperature)
|
|
|
|
|
|
- def cal_temperature(self, tim):
|
|
|
+ def cal_temperature(self):
|
|
|
val_uv = self.adc.read_uv()/1000
|
|
|
Rt = val_uv / ((self.VCC - val_uv)/10000)
|
|
|
T1 = 1/(log(Rt/10000)/3950 + 1/(273.15+25)) - 273.15
|
|
|
@@ -58,9 +54,9 @@ class HeatPower():
|
|
|
self.sw_pin.freq(1000)
|
|
|
# self.sw_pin.duty(180)
|
|
|
self.duty = 0.0
|
|
|
- self.duty_percent(0.7)
|
|
|
self.status = 0
|
|
|
self.dat = {'status':0, 'pwr_percent':0}
|
|
|
+ self.duty_percent(0.7)
|
|
|
|
|
|
def duty_percent(self, percent):
|
|
|
if percent > 1:
|
|
|
@@ -104,40 +100,43 @@ class HeatPower():
|
|
|
self.ajust_duty(step)
|
|
|
print('wt:', wt, "step:", step)
|
|
|
else:
|
|
|
- step = (40-ct)/100
|
|
|
+ step = (42-ct)/100
|
|
|
print('ct:', ct, "step:", step)
|
|
|
self.ajust_duty(step)
|
|
|
|
|
|
+wire_ntc = Ntc(34)
|
|
|
+center_ntc = Ntc(36)
|
|
|
+async def cal_ntc():
|
|
|
+ while True:
|
|
|
+ wire_ntc.cal_temperature()
|
|
|
+ center_ntc.cal_temperature()
|
|
|
+ await uasyncio.sleep_ms(200)
|
|
|
|
|
|
-def sensor():
|
|
|
- wire_ntc = Ntc(34)
|
|
|
- center_ntc = Ntc(36)
|
|
|
+async def sensor():
|
|
|
+ uasyncio.create_task(cal_ntc())
|
|
|
heat = HeatPower()
|
|
|
- def heat_status_print():
|
|
|
- # nonlocal wire_ntc,center_ntc,heat
|
|
|
+ heat.on()
|
|
|
+ while True:
|
|
|
wire_temp = wire_ntc.get_temperature()
|
|
|
- # center_temp = 0
|
|
|
center_temp = center_ntc.get_temperature()
|
|
|
print("wire_temp:", wire_temp, "\tcenter_temp:", center_temp, '\tduty:', heat.duty)
|
|
|
heat.ajust_power(wire_temp, center_temp)
|
|
|
- # heat.ajust_duty(1)
|
|
|
upload.set_data('heat', heat.dat)
|
|
|
upload.set_data('ntc', {"wire_temp": wire_temp, 'center_temp':center_temp})
|
|
|
# 主动垃圾回收是个好习惯,如果没有经常开辟内存,可不用
|
|
|
gc.collect()
|
|
|
+ await uasyncio.sleep_ms(1000)
|
|
|
|
|
|
- tim = Timer()
|
|
|
- tim.init(1, 1200, heat_status_print)
|
|
|
|
|
|
-
|
|
|
+
|
|
|
def test():
|
|
|
- wire_ntc = Ntc(34,2)
|
|
|
- center_ntc = Ntc(36,3)
|
|
|
+ wire_ntc = Ntc(34)
|
|
|
+ center_ntc = Ntc(36)
|
|
|
print("class Ntc:", wire_ntc, center_ntc)
|
|
|
print("class adc:", wire_ntc.adc, center_ntc.adc)
|
|
|
print("tim:", wire_ntc.tim, center_ntc.tim)
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
- sensor()
|
|
|
+ uasyncio.run(sensor())
|
|
|
# test()
|