KevsRobots Learning Platform
By Kevin McAleer, 1 Minute
In this lesson, you’ll write your first script to interact with the Raspberry Pi Pico’s temperature sensor. You’ll read raw ADC values and display them in the Thonny console.
The Pico’s ADC provides a digital representation of the temperature sensor’s reading. In Python, you can use the machine module to access the ADC.
Type the following code:
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()
print("Raw ADC Value:", raw_value)
time.sleep(1)
The raw ADC value will change depending on the temperature of the Pico’s chip. In the next lesson, you’ll learn to convert these values into meaningful temperature readings.
You can use the arrows ← → on your keyboard to navigate between lessons.
Comments