Though the following example uses the Circuit Playground Express to demonstrate, the code works exactly the same way with the Circuit Playground Bluefruit. Simply copy the code and follow along with your Circuit Playground Bluefruit!

But wait! There's more -- the Circuit Playground Express can also tell the temperature!

How, you ask? With a build in thermistor. This little sensor is a thermally sensitive resistor, meaning it's resistance changes based on temperature.

We can access its readings in CircuitPython by importing the adafruit_thermistor library, and then using the board.TEMPERATURE pin to read the thermistor value.

In the example below, click the Download Project Bundle button below to download the necessary libraries and the file in a zip file. Extract the contents of the zip file, open the directory Introducing_CircuitPlaygroundExpress/CircuitPlaygroundExpress_Temperature/ and then click on the directory that matches the version of CircuitPython you're using and copy the contents of that directory to your CIRCUITPY drive.

Your CIRCUITPY drive should now look similar to the following image:

# SPDX-FileCopyrightText: 2017 John Edgar Park for Adafruit Industries
# SPDX-License-Identifier: MIT

# Circuit Playground Temperature
# Reads the on-board temperature sensor and prints the value

import time

import adafruit_thermistor
import board

thermistor = adafruit_thermistor.Thermistor(
    board.TEMPERATURE, 10000, 10000, 25, 3950)

while True:
    temp_c = thermistor.temperature
    temp_f = thermistor.temperature * 9 / 5 + 32
    print("Temperature is: %f C and %f F" % (temp_c, temp_f))


Then, open up a REPL session and you'll see the temperature readings in both Celsius and Fahrenheit. 

Try placing your finger over the sensor (you'll see a thermometer icon on the board) and watch the readings change.

This guide was first published on Sep 12, 2019. It was last updated on Apr 23, 2024.

This page (Playground Temperature) was last updated on Apr 23, 2024.

Text editor powered by tinymce.