Skip to content

Core Temperature Sensor

Raw ADC Values Mean Nothing

You read the temperature sensor:

>>> adc.read_u16()
29127

This isn't degrees. It isn't millivolts. It's a raw ADC count - a number proportional to voltage, scaled to a 16-bit range.

To get temperature, you need the conversion chain:

Raw ADC (29127) → Voltage (0.706V) → Temperature (27°C)
     ↓                  ↓                   ↓
  × (3.3/65535)    Apply datasheet      Physical value
                   formula               you can use

Every sensor works this way. The ADC measures voltage. You must: 1. Know the reference voltage (3.3V) 2. Know the sensor's voltage-to-measurement relationship (from datasheet) 3. Apply the conversion formula

Without understanding this chain, raw values are meaningless numbers.


How the Core Temperature Sensor Works

The RP2350 microcontroller features an internal temperature sensor that measures temperature by monitoring the base-emitter voltage (\(V_{\text{adc}}\)) of an integrated bipolar junction transistor (BJT) diode. As temperature increases, this voltage decreases, allowing us to estimate the temperature.

The sensor is built into the RP2350 chip and is connected to ADC channel 4, where the voltage can be read for temperature calculations.

How to Get the Temperature Value?

According to the RP2350 datasheet, the internal temperature sensor is connected to ADC channel 4. We can read the sensor value using the ADC and calculate the temperature using the formula provided in the datasheet.

To determine the temperature, follow these steps:

  1. Read the ADC value – This gives a digital value proportional to the full-scale range and the reference voltage.
  2. Convert the ADC value to voltage – Calculate the actual sensor voltage from the raw ADC register reading.
  3. Calculate the temperature – Use the provided formula to convert the voltage into a temperature value.

At 27°C, the \(V_{\text{adc}}\) is typically 0.706V, and it decreases by 1.721 mV per °C. Using this relationship, the temperature (T) in degrees Celsius can be estimated with the formula:

$$ T = 27 - \frac{(V_{\text{adc}} - 0.706)}{0.001721}​ $$ where:

  • \(V_{\text{adc}}\)​ is the measured voltage on the ADC channel 4 input pin calculated from the raw ADC register value
  • 0.706V is the reference voltage at 27°C.
  • 0.001721 V/°C (or 1.721 mV/°C) is the slope.

Calculating the the temperature value defined in the RP2350 datasheet section 12.4.6. Temperature Sensor

How the ADC works?


⚡Hands-on tasks

✅ Task 1 - Reading temperature sensor value

In this step, we will create a simple program to read the raw ADC value from the RP2350's internal temperature sensor. This will help us understand how the sensor works before converting the readings into a temperature value.

from machine import Pin, ADC
import time

# --- Configuration ---

# Internal temperature sensor (ADC channel 4)
internal_temp_Sens = ADC.CORE_TEMP  
coretemp_sensor = ADC(internal_temp_Sens)

while True:
    adc_val = coretemp_sensor.read_u16()  # Read 16-bit ADC value
    print("ADC Value:", adc_val)  # Print raw ADC reading
    time.sleep(0.5)  # Wait 500ms before the next reading

🔍 Try blowing air onto the microcontroller chip and observe how the ADC value changes as the temperature increases or decreases. 🌡️💨

Why read a 16-bit ADC value when the RP2350 has a 12-bit ADC?

Although the RP2350 has a 12-bit ADC (0–4095 range), MicroPython’s read_u16() returns a 16-bit value (0–65535). This happens because: - The 12-bit value is left-shifted (×16) to fit into a 16-bit range for consistency across different microcontrollers - This scaling ensures compatibility and avoids precision loss when working with different ADC resolutions. - If needed, you can convert back to 12-bit by shifting right (adc_val >> 4).

This way, MicroPython keeps ADC handling uniform across various hardware platforms.


✅ Task 2 - Calculating temperature value

Now that we've successfully read the raw ADC value from the internal temperature sensor, the next step is to calculate the voltage level in volts.

from machine import Pin, ADC
import time

# --- Configuration ---
VREF = 3.3  # Referernce voltage 3.3V

# Internal temperature sensor (ADC channel 4)
internal_temp_Sens = ADC.CORE_TEMP  
coretemp_sensor = ADC(internal_temp_Sens)

while True:
    adc_val = coretemp_sensor.read_u16()  # Read raw ADC value
    print("ADC Value:", adc_val)

    adc_voltage = (VREF / 65535) * adc_val  # Convert ADC value to voltage
    print("Core Temp Voltage:", adc_voltage)

    time.sleep(0.5)  # Wait 500ms before the next reading

🛠️ Try blowing air onto the microcontroller chip and observe how the ADC value and voltage change as the temperature increases or decreases. 🌡️💨


✅ Task 3 - Calculating temperature value

Now that we have successfully read the raw ADC value from the internal temperature sensor, the next step is to convert it into a temperature reading in degrees Celsius.

🔍 Try blowing air onto the microcontroller chip and observe how the converted temperature (in Celsius) changes as the sensor responds to variations in heat. 🌡️💨

How to implement the function

The following code snippet provides an example of a function that converts an ADC value to temperature in Celsius. If you need more information on working with functions in Python, refer to Python Basics.

def read_temperature():

    adc_val = coretemp_sensor.read_u16()  # Read raw ADC value
    print("ADC Value:", adc_val)

    adc_voltage = (VREF / 65535) * adc_val  # Convert ADC value to voltage
    print("Core Temp Voltage:", adc_voltage)

    temp = 27 - (adc_voltage - 0.706)/0.001721
    return round(temp, 1)

This function reads the ADC value from the internal temperature sensor, converts it to voltage, and then calculates the temperature in Celsius based on the datasheet formula.

What is round() in Python?

The round() function in Python is used to round a floating-point number to a specified number of decimal places.

x = 3.14159
print(round(x, 1))  # Output: 3.1
print(round(x, 2))  # Output: 3.14
print(round(x, 3))  # Output: 3.142

Measurement Accuracy

The onboard temperature sensor is highly sensitive to variations in the reference voltage. If the reference voltage fluctuates, the calculated temperature can be significantly affected.

For example:

  • At a 3.3V reference, an ADC reading of 891 corresponds to 20.1°C.
  • If the reference voltage is just 1% lower (≈3.267V), the same ADC reading of 891 would indicate 24.3°C, a 4.2°C error.

To improve accuracy, consider using an external reference voltage instead of relying on the default supply voltage.


➡ Next Steps