There is a CPU temperature sensor built into every ATSAMD21, ATSAMD51 and nRF52840 chips. CircuitPython makes it really simple to read the data from this sensor. This works on the Adafruit CircuitPython boards it's built into the microcontroller used for these boards.

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:

import microcontroller
microcontroller.cpu.temperature

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!

Note that the temperature sensor built into the nRF52840 has a resolution of 0.25 degrees Celsius, so any temperature you print out will be in 0.25 degree increments.

This guide was first published on Sep 30, 2020. It was last updated on Mar 16, 2024.

This page (CircuitPython CPU Temp) was last updated on Mar 08, 2024.

Text editor powered by tinymce.