To get you started with how to program your Pico in CircuitPython, especially for those who may have started out with the official MicroPython setup, we've 'ported' the Getting Started with MicroPython on Pico book examples to CircuitPython. The book is awesome, please download/purchase it to support Raspberry Pi Press!

The Raspberry Pi Pico's CPU has a temperature sensor built into it. CircuitPython makes it super simple to read this data from the sensor using the microcontroller module.

Plug in your Pico board, open Mu, click into the serial console, and press CTRL+C followed by ENTER to enter the REPL. At the REPL prompt (>>>), type the following:

import microcontroller
microcontroller.cpu.temperature

This returns the temperature of the sensor in Celsius. Note that it's not exactly the ambient temperature and it's not super precise. But it's close!

Try holding your finger over the CPU, the large black square in the middle of your Pico board. Then, check the temperature again. The returned temperature has likely increased because you warmed the chip slightly!

If you'd like to print it out in Fahrenheit, use this simple formula: Fahrenheit = Celsius * (9/5) + 32. It's super easy to do math using CircuitPython. Check it out!

microcontroller.cpu.temperature * (9 / 5) + 32

That's all there is to reading the temperature data from the temperature sensor built into the CPU on your Raspberry Pi Pico using CircuitPython!

This guide was first published on Jan 21, 2021. It was last updated on 2021-03-03 12:34:49 -0500.

This page (Temperature Gauge) was last updated on Apr 14, 2021.

Text editor powered by tinymce.