# Basic_TC ONLY.py - A Basic temperature sampling script, via the onboard sensor found on a Pico
#
# Phil J, Mar 24
from machine import Pin, ADC
import time
sensor_temp = machine.ADC(4) # Assigns the ADC(4) - intitiates the variable
conversion_factor = 3.3 / (65535) # creates the conversion factor - to be used with the A-D conversion
def Temp_Sensor():
reading = sensor_temp.read_u16() * conversion_factor # reads the onboard sensor, and then quantizes it via the cf
temperature = 27 - (reading - 0.706)/0.001721 # correctly scales to a meanfull value.
return temperature # passes back the sensors value as ℃.
while True:
temperature = int(Temp_Sensor()) # a call to get the temperature - will result in an integer value
print("Pv = " + str(temperature) + "\u2103")
time.sleep_ms(1000) # cause's the Temperature reading to be update at 1 second intervals