Introduction

Documentation Status Discord Build Status

Thermistors are resistors that predictably change resistance with temperature. This driver uses an analog reading and math to determine the temperature. They are commonly used as a low cost way to measure temperature.

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.

Usage Example

The hardest part of using the driver is its initialization. Here is an example for the thermistor on the Circuit Playground and Circuit Playground Express. Its a 10k series resistor, 10k nominal resistance, 25 celsius nominal temperature and 3950 B coefficient.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

Building locally

To build this library locally you’ll need to install the circuitpython-build-tools package.

python3 -m venv .env
source .env/bin/activate
pip install circuitpython-build-tools

Once installed, make sure you are in the virtual environment:

source .env/bin/activate

Then run the build:

circuitpython-build-bundles --filename_prefix adafruit-circuitpython-thermistor --library_location .

Sphinx documentation

Sphinx is used to build the documentation based on rST files and comments in the code. First, install dependencies (feel free to reuse the virtual environment from above):

python3 -m venv .env
source .env/bin/activate
pip install Sphinx sphinx-rtd-theme

Now, once you have the virtual environment activated:

cd docs
sphinx-build -E -W -b html . _build/html

This will output the documentation to docs/_build/html. Open the index.html in your browser to view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to locally verify it will pass.

Table of Contents

Simple test

Ensure your device works with this simple test.

examples/thermistor_simpletest.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import time
import adafruit_thermistor
import board

# these values work with the Adafruit CircuitPlayground Express.
# they may work with other thermistors as well, as they're fairly standard,
# though the pin will likely need to change (ie board.A1)
pin = board.TEMPERATURE
resistor = 10000
resistance = 10000
nominal_temp = 25
b_coefficient = 3950

thermistor = adafruit_thermistor.Thermistor(pin, resistor, resistance, nominal_temp, b_coefficient)

# print the temperature in C and F to the serial console every second
while True:
    celsius = thermistor.temperature
    fahrenheit = (celsius * 9 / 5) + 32
    print('== Temperature ==\n{} *C\n{} *F\n'.format(celsius, fahrenheit))
    time.sleep(1)

adafruit_thermistor - Read temperature with a thermistor

A thermistor is a resistor that varies with temperature. This driver takes the parameters of that resistor and its series resistor to determine the current temperature. To hook one up, connect an analog input pin to the connection between the resistor and the thermistor. Be careful to note if the thermistor is connected on the high side (from analog input up to high logic level/3.3 or 5 volts) or low side (from analog input down to ground). The initializer takes an optional high_side boolean that defaults to True and indicates if that the thermistor is connected on the high side vs. low side.

  • Author(s): Scott Shawcroft

Implementation Notes

Hardware:

Software and Dependencies:

Notes:

  1. Check the datasheet of your thermistor for the values.
class adafruit_thermistor.Thermistor(pin, series_resistor, nominal_resistance, nominal_temperature, b_coefficient, *, high_side=True)[source]

Thermistor driver

temperature

The temperature of the thermistor in celsius

Indices and tables