CircuitPython CPU Temp

There is a CPU temperature sensor built into every ATSAMD21 chip. CircuitPython makes it really simple to read the data from this sensor. This works on the M0, M0 Express and Circuit Playground Express boards, because it's built into the microcontroller used for these boards. It does not work on the ESP8266 as this uses a different chip.

The data is read using two simple commands. We're going to enter them in the REPL. Plug in your board, connect to the serial console, and enter the REPL. Then, enter the following commands into the REPL:

Download: file
import microcontroller

That's it! You've printed the temperature in Celsius to the REPL. Note that it's not exactly the ambient temperature and it's not super precise. But it's close!

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

This guide was first published on Aug 23, 2017. It was last updated on Aug 23, 2017. This page (CircuitPython CPU Temp) was last updated on Aug 25, 2019.