Introduction¶
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.
Installing from PyPI¶
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:
pip3 install adafruit-circuitpython-thermistor
To install system-wide (this may be required in some cases):
sudo pip3 install adafruit-circuitpython-thermistor
To install in a virtual environment in your current project:
mkdir project-name && cd project-name
python3 -m venv .env
source .env/bin/activate
pip3 install adafruit-circuitpython-thermistor
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import time
import board
import adafruit_thermistor
# 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)
# pylint: disable=no-member
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
¶
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:
- Adafruit 10K Precision Epoxy Thermistor - 3950 NTC (Product ID: 372)
- Adafruit Circuit Playground Express (Product ID: 3333)
Software and Dependencies:
- Adafruit CircuitPython firmware: https://github.com/adafruit/circuitpython/releases
Notes:
- Check the datasheet of your thermistor for the values.
\ Sort by:\ best rated\ newest\ oldest\
\\
Add a comment\ (markup):
\``code``
, \ code blocks:::
and an indented block after blank line