KevsRobots Learning Platform
72% Percent Complete
By Kevin McAleer, 2 Minutes
The Raspberry Pi Picoβs ADC provides raw digital values that correspond to the temperature of the RP2040 chip. To make these readings meaningful, we need to convert them into temperature values in degrees Celsius. In this lesson, youβll learn how to use a mathematical formula for this conversion.
The built-in temperature sensor measures the voltage output of the chipβs temperature sensing circuit. This voltage is then converted to an ADC value, which can be transformed into a temperature in degrees Celsius using the formula:
temperature = 27 - (voltage - 0.706) / 0.001721
27 is the nominal room temperature in degrees Celsius.0.706 is the reference voltage at room temperature.0.001721 is the voltage change per degree Celsius.Update your script to include the conversion formula:
import machine
import time
# Initialize the ADC for the temperature sensor
sensor_adc = machine.ADC(4)
while True:
# Read the raw ADC value
raw_value = sensor_adc.read_u16()
# Convert the ADC value to voltage
voltage = raw_value * 3.3 / 65535
# Convert voltage to temperature
temperature = 27 - (voltage - 0.706) / 0.001721
# Print the temperature
print(f"Temperature: {temperature:.2f}Β°C")
time.sleep(1)
convert_adc_to_temp.py.To ensure the readings are accurate:
Temperature: 26.84Β°C
Temperature: 26.85Β°C
Temperature: 26.87Β°C
You can use the arrows β β on your keyboard to navigate between lessons.
Comments