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:

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!

Last updated on 2018-04-19 at 12.13.32 PM Published on 2017-10-12 at 10.43.39 PM