from machine import Pin, ADC
import utime
import math
# Set the constant for the ADC limit value
MAX_INPUT = math.pow(2, 16) - 1
# Set the ratio of the Pico input voltage to the
# maximum possible ADC voltage reading from the
# temperature sensor
VOLT_FACTOR = 3.3 / MAX_INPUT
# Read the voltage from the 'temperature sensor. On a real Pico
# this signal will come from the internal SOC temperature sensor
# on channel 4. For this simulation we are using a potentiometer
# on channel 2.
temp_adc = ADC(2)
# Read the voltage from the ADC, convert to
# a temperature in degrees Celsius, print that
# temperature to the console, and repeat
# every second
while True:
adc_voltage = temp_adc.read_u16()
temp_voltage = adc_voltage * VOLT_FACTOR
chip_temp = 27 - ((temp_voltage - 0.706) / 0.001721)
print(f"ADC Voltage: {adc_voltage}")
print(f"ADC Temp: {temp_voltage}")
print(f"Current Chip Temperature: {chip_temp}")
print("")
utime.sleep(1)