pastebin - collaborative debugging tool
python.kpaste.net RSS


Thermistor
Posted by Anonymous on Mon 27th Jun 2022 17:11
raw | new post

  1. # TX08F103F3435ER circuit python analog temperature from thermistor 10K.
  2. import time
  3. import board
  4. import analogio
  5.  
  6.  
  7. def steinhart_temperature_C(r, Ro=10000.0, To=25.0, beta=3435.0): # mine 3435 K
  8.     import math
  9.     steinhart = math.log(r / Ro) / beta      # log(R/Ro) / beta
  10.     steinhart += 1.0 / (To + 273.15)         # log(R/Ro) / beta + 1/To
  11.     steinhart = (1.0 / steinhart) - 273.15   # Invert, convert to C
  12.     return steinhart
  13.  
  14. print("adafruit thermistor")
  15.  
  16. thermistor = analogio.AnalogIn(board.GP26)
  17.  
  18. while True:
  19.     print("thermistor.value", thermistor.value)
  20.     R = 10000 / (65535/thermistor.value - 1)
  21.     print('Thermistor resistance: {} ohms'.format(R))
  22.     steinHartC = steinhart_temperature_C(R)
  23.     print("steinHartC",steinHartC)
  24.     print("Temperature F:", steinHartC * 1.8 + 32)
  25.  
  26.     time.sleep(2)

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at