How to Read internal temperature sensor of Raspberry Pi Pico using Thonny IDE

Posted

in

by

The internal temperature sensor of RP2040 is read using micropython. The Thonny IDE is used in Windows environment.

The temperature sensor is connected to Channel number 4 of the ADC.

But since this is a rather small implementation using Thonny IDE, it does most of the interfacing related code in the background.

Code

import machine
import time

"""
Function Name: Read internal temperature sensor
Description: This function reads the internal temperature sensor of RP2040 chip.
             The temperature sensor measures the Vbe voltage of a biased bipolar diode,
             connected to the fifth ADC channel (AINSEL=4).
"""
def read_internal_temperature_sensor():
    tsi = machine.ADC(machine.ADC.CORE_TEMP)
    temp = tsi.read_u16() * (3.3 / (65535))
    temp = 27 - (temp - 0.706)/0.001721
    return temp

while True:
    #reads the temprature and prints it
    print("Temperature: ", read_internal_temperature_sensor())
    #Create a dealy of 1 second
    time.sleep(1)

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *