Compare commits
2 commits
37b58a1529
...
10cea18d0a
Author | SHA1 | Date | |
---|---|---|---|
|
10cea18d0a | ||
|
115eecde4f |
|
@ -26,25 +26,28 @@ temperature_filtered = -1
|
|||
# Ignore the first 5 seconds
|
||||
last_report = time.ticks_ms() + 5000
|
||||
while True:
|
||||
raw_value = cs1237.read()
|
||||
value = float(raw_value) / (2**24 - 1)
|
||||
try:
|
||||
raw_value = cs1237.read()
|
||||
value = float(raw_value) / (2**24 - 1)
|
||||
|
||||
if value > 0.9999:
|
||||
value = 0
|
||||
else:
|
||||
value = 10e3 * 1 / (1 / value - 1)
|
||||
if value > 0.9999:
|
||||
value = 20e3
|
||||
else:
|
||||
value = 10e3 * 1 / (1 / value - 1)
|
||||
|
||||
temperature = THERMISTOR_BETA / math.log(value / THERMISTOR_RINF) - 273.15
|
||||
temperature = THERMISTOR_BETA / math.log(value / THERMISTOR_RINF) - 273.15
|
||||
|
||||
if temperature_filtered == -1:
|
||||
temperature_filtered = temperature
|
||||
if temperature_filtered == -1:
|
||||
temperature_filtered = temperature
|
||||
|
||||
temperature_filtered = (
|
||||
temperature_filtered * (1 - FILTER_A) + temperature * FILTER_A
|
||||
)
|
||||
temperature_filtered = (
|
||||
temperature_filtered * (1 - FILTER_A) + temperature * FILTER_A
|
||||
)
|
||||
|
||||
now = time.ticks_ms()
|
||||
elapsed = now - last_report
|
||||
if elapsed >= 200 or elapsed < 0:
|
||||
print(f"{temperature:.6f},{temperature_filtered:.6f}")
|
||||
last_report = now
|
||||
now = time.ticks_ms()
|
||||
elapsed = now - last_report
|
||||
if elapsed >= 200 or elapsed < 0:
|
||||
print(f"{temperature:.6f},{temperature_filtered:.6f}")
|
||||
last_report = now
|
||||
except Exception as e:
|
||||
print(f"Error {e}")
|
||||
|
|
Loading…
Reference in a new issue