temp: Slow down reports
Only send a new report every 200ms to hopefully mitigate the serial port glitches.
This commit is contained in:
parent
f46e58b4e8
commit
12753d93fb
|
@ -1,4 +1,5 @@
|
|||
import math
|
||||
import time
|
||||
from cs1237 import CS1237
|
||||
from machine import Pin
|
||||
|
||||
|
@ -10,7 +11,7 @@ ADC_RATE = 40
|
|||
cs1237 = CS1237(clock, data)
|
||||
cs1237.config(gain=1, rate=ADC_RATE)
|
||||
|
||||
print(repr(cs1237.get_config()))
|
||||
cs1237.get_config()
|
||||
|
||||
THERMISTOR_BETA = 3950.0
|
||||
THERMISTOR_R25 = 10e3
|
||||
|
@ -22,6 +23,7 @@ FILTER_RC = 1
|
|||
FILTER_A = 1 / ADC_RATE / (FILTER_RC / 1 / ADC_RATE)
|
||||
|
||||
temperature_filtered = 25
|
||||
last_report = time.ticks_ms()
|
||||
while True:
|
||||
raw_value = cs1237.read()
|
||||
value = float(raw_value) / (2**24 - 1)
|
||||
|
@ -37,4 +39,8 @@ while True:
|
|||
temperature_filtered * (1 - FILTER_A) + temperature * FILTER_A
|
||||
)
|
||||
|
||||
print(temperature_filtered)
|
||||
now = time.ticks_ms()
|
||||
elapsed = now - last_report
|
||||
if elapsed >= 200 or elapsed < 0:
|
||||
print(f"{temperature_filtered:.6f}")
|
||||
last_report = now
|
||||
|
|
Loading…
Reference in a new issue