k8ik-stm/Misc/Temp-Monitor/firmware.py

21 lines
403 B
Python

import time
from cs1237 import CS1237
from machine import Pin
clock = Pin(2)
data = Pin(4)
cs1237 = CS1237(clock, data)
cs1237.config(gain=1)
while True:
raw_value = cs1237.read()
value = float(raw_value) / (2**23 - 1)
if value > 0.9999:
value = 0
else:
value = 1 / (1 / value - 1)
temperature = 25 - value
if abs(temperature) < 50:
print(temperature)