One of the new packages included in 2.0.0 is microcontroller.cpu.temperature: this gives you the temperature (in Celsius) of the board’s CPU. It isn’t an accurate room temperature sensor like the TMP36 or DHT22, since it’s the temperature of the CPU, not the ambient air, but it’s still a data point and it is very accurate!

Getting the temperature is as simple as can be. In the REPL:

Adafruit CircuitPython 2.0.0 on 2017-09-12; Adafruit Gemma M0 with samd21e18
>>> import microcontroller
>>> microcontroller.cpu.temperature

If you’d like it in Fahrenheit, you can create a function for that.

>>> def fahrenheit(celsius):
...     return (celsius * 9 / 5) + 32
>>> fahrenheit(microcontroller.cpu.temperature)

Once you've got all that working, we can go on to the next step, storage!

This guide was first published on Sep 27, 2017. It was last updated on May 19, 2024.

This page (Getting the temperature) was last updated on Sep 13, 2017.

Text editor powered by tinymce.