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-max31856
To install system-wide (this may be required in some cases):
sudo pip3 install adafruit-circuitpython-max31856
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-max31856
Usage Example¶
import board
import digitalio
import adafruit_max31856
# Create sensor object, communicating over the board's default SPI bus
spi = board.SPI()
# allocate a CS pin and set the direction
cs = digitalio.DigitalInOut(board.D5)
cs.direction = digitalio.Direction.OUTPUT
# create a thermocouple object with the above
thermocouple = adafruit_max31856.MAX31856(spi, cs)
# print the temperature!
print(thermocouple.temperature)
Contributing¶
Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.
Documentation¶
For information on building library documentation, please check out this guide.
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 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
import board
import digitalio
import adafruit_max31856
# Create sensor object, communicating over the board's default SPI bus
spi = board.SPI()
# allocate a CS pin and set the direction
cs = digitalio.DigitalInOut(board.D5)
cs.direction = digitalio.Direction.OUTPUT
# create a thermocouple object with the above
thermocouple = adafruit_max31856.MAX31856(spi, cs)
# print the temperature!
print(thermocouple.temperature)
|
Thresholds and Fault example¶
Example showing how to use thresholds
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
import time
import board
import digitalio
import adafruit_max31856
# Create sensor object, communicating over the board's default SPI bus
spi = board.SPI()
# allocate a CS pin and set the direction
cs = digitalio.DigitalInOut(board.D0)
cs.direction = digitalio.Direction.OUTPUT
# create a thermocouple object with the above
thermocouple = adafruit_max31856.MAX31856(spi, cs)
# set the temperature thresholds for the thermocouple and cold junction
thermocouple.temperature_thresholds = (-1.5, 30.8)
thermocouple.reference_temperature_thresholds = (-1.0, 30.5)
current_faults = {}
current_cj_thresholds = (0, 0)
current_temp_thresholds = (0, 0)
print(thermocouple.reference_temperature_thresholds)
while True:
current_temp_thresholds = thermocouple.temperature_thresholds
current_cj_thresholds = thermocouple.reference_temperature_thresholds
current_faults = thermocouple.fault
print(
"Temps: %.2f :: cj: %.2f"
% (thermocouple.temperature, thermocouple.reference_temperature)
)
print("Thresholds:")
print("Temp low: %.2f high: %.2f" % current_temp_thresholds)
print("CJ low: %.2f high: %.2f" % current_cj_thresholds)
print("")
print("Faults:")
print(
"Temp Hi: %s | CJ Hi: %s"
% (current_faults["tc_high"], current_faults["cj_high"])
)
print(
"Temp Low: %s | CJ Low: %s"
% (current_faults["tc_low"], current_faults["cj_low"])
)
print(
"Temp Range: %s | CJ Range: %s"
% (current_faults["tc_range"], current_faults["cj_range"])
)
print("")
print(
"Open Circuit: %s Voltage Over/Under: %s"
% (current_faults["open_tc"], current_faults["voltage"])
)
print("")
time.sleep(1.0)
|
MAX31856
¶
CircuitPython module for the MAX31856 Universal Thermocouple Amplifier. See examples/simpletest.py for an example of the usage.
- Author(s): Bryan Siepert
Implementation Notes¶
Hardware:
- Adafruit Universal Thermocouple Amplifier MAX31856 Breakout (Product ID: 3263)
Software and Dependencies:
- Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
- Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
-
class
adafruit_max31856.
MAX31856
(spi, cs, thermocouple_type=3)¶ Driver for the MAX31856 Universal Thermocouple Amplifier
Parameters: - spi (SPI) – The SPI bus the MAX31856 is connected to.
- cs (Pin) – The pin used for the CS signal.
- thermocouple_type (ThermocoupleType) – The type of thermocouple. Default is Type K.
Quickstart: Importing and using the MAX31856
Here is an example of using the
MAX31856
class. First you will need to import the libraries to use the sensorimport board from digitalio import DigitalInOut, Direction import adafruit_max31856
Once this is done you can define your
board.SPI
object and define your sensor objectspi = board.SPI() cs = digitalio.DigitalInOut(board.D5) # Chip select of the MAX31856 board. sensor = adafruit_max31856.MAX31856(spi, cs)
Now you have access to the
temperature
attributetemperature = sensor.temperature
-
fault
¶ A dictionary with the status of each fault type where the key is the fault type and the value is a bool if the fault is currently active
Key Fault type “cj_range” Cold junction range fault “tc_range” Thermocouple range fault “cj_high” Cold junction high threshold fault “cj_low” Cold junction low threshold fault “tc_high” Thermocouple high threshold fault “tc_low” Thermocouple low threshold fault “voltage” Over/under voltage fault “open_tc” Thermocouple open circuit fault
-
reference_temperature
¶ The temperature of the cold junction in degrees Celsius. (read-only)
-
reference_temperature_thresholds
¶ The cold junction’s low and high temperature thresholds as a
(low_temp, high_temp)
tuple
-
temperature
¶ The temperature of the sensor and return its value in degrees Celsius. (read-only)
-
temperature_thresholds
¶ The thermocouple’s low and high temperature thresholds as a
(low_temp, high_temp)
tuple
-
class
adafruit_max31856.
ThermocoupleType
¶ An enum-like class representing the different types of thermocouples that the MAX31856 can use. The values can be referenced like
ThermocoupleType.K
orThermocoupleType.S
Possible values areThermocoupleType.B
ThermocoupleType.E
ThermocoupleType.J
ThermocoupleType.K
ThermocoupleType.N
ThermocoupleType.R
ThermocoupleType.S
ThermocoupleType.T