Using the Circuit Playground Express (CPX) Library

The temperature may be easily obtained in Celsius via the adafruit_circuitplayground value cpx.temperature.

You can get the value in Fahrenheit as  temperature_f = cpx.temperature * 1.8 + 32

Here is a sample program printing out the temperature every quarter of a second (0.25 seconds)

import time
from import cpx

while True:
    print((cpx.temperature, ))

Try placing your finger over the sensor (you'll see the thermometer icon on the board) and watch the readings change. As the temperature is in Celsius, it will not make a huge change over time unless you have a fever.

Using Lower-Level Library Calls

To read the Circuit Playground Express temperature sensor, Adafruit has a CircuitPython library named adafruit_thermistor. There are some values that need to be passed to the function which characterizes the specific thermistor on the board.

The following short example shows printing out the temperature in both scales.

# 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))


If you put one of the values (temp_c or temp_f) in a tuple like (temp_f, ) then you can use the Mu plotter like was done in the Light Sensor to plot temperature over time.

This guide was first published on Jul 26, 2018. It was last updated on Jul 26, 2018.

This page (CircuitPython) was last updated on Apr 30, 2021.

Text editor powered by tinymce.