]> vault307.fbx.one Git - mu_code.git/blob - thermistorTest.py
early learning in mu editor
[mu_code.git] / thermistorTest.py
1 #!/usr/bin/env python3
2 import time
3 import board
4 import math
5 import datetime
6
7 import adafruit_pcf8591.pcf8591 as PCF
8 from adafruit_pcf8591.analog_in import AnalogIn
9
10 i2c=board.I2C()
11 pcf=PCF.PCF8591(i2c)
12
13 thermistor=AnalogIn(pcf,PCF.A0)
14 R=10000/(65535/thermistor.value - 1)
15 def steinhart_temperature_C(r,Ro=10000.0,To=25.0,beta=3950.0):
16 steinhart=math.log(r/Ro)/beta
17 steinhart+=1.0/(To + 273.15)
18 steinhart=(1.0/steinhart) - 273.15
19 return steinhart
20 while True:
21 print(steinhart_temperature_C(R),(datetime.datetime.now()))
22 time.sleep(60)