Simple test

Ensure your device works with this simple test.

examples/max31856_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import board
 5import digitalio
 6import adafruit_max31856
 7
 8# Create sensor object, communicating over the board's default SPI bus
 9spi = board.SPI()
10
11# allocate a CS pin and set the direction
12cs = digitalio.DigitalInOut(board.D5)
13cs.direction = digitalio.Direction.OUTPUT
14
15# create a thermocouple object with the above
16thermocouple = adafruit_max31856.MAX31856(spi, cs)
17
18# print the temperature!
19print(thermocouple.temperature)

Thresholds and Fault example

Example showing how to use thresholds

examples/max31856_thresholds_and_faults.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import time
 5import board
 6import digitalio
 7import adafruit_max31856
 8
 9# Create sensor object, communicating over the board's default SPI bus
10spi = board.SPI()
11
12# allocate a CS pin and set the direction
13cs = digitalio.DigitalInOut(board.D0)
14cs.direction = digitalio.Direction.OUTPUT
15
16# create a thermocouple object with the above
17thermocouple = adafruit_max31856.MAX31856(spi, cs)
18
19# set the temperature thresholds for the thermocouple and cold junction
20thermocouple.temperature_thresholds = (-1.5, 30.8)
21thermocouple.reference_temperature_thresholds = (-1.0, 30.5)
22current_faults = {}
23current_cj_thresholds = (0, 0)
24current_temp_thresholds = (0, 0)
25print(thermocouple.reference_temperature_thresholds)
26while True:
27    current_temp_thresholds = thermocouple.temperature_thresholds
28    current_cj_thresholds = thermocouple.reference_temperature_thresholds
29    current_faults = thermocouple.fault
30    print(
31        "Temps:    %.2f :: cj: %.2f"
32        % (thermocouple.temperature, thermocouple.reference_temperature)
33    )
34    print("Thresholds:")
35    print("Temp low: %.2f high: %.2f" % current_temp_thresholds)
36    print("CJ low:   %.2f high: %.2f" % current_cj_thresholds)
37    print("")
38    print("Faults:")
39    print(
40        "Temp Hi:    %s | CJ Hi:    %s"
41        % (current_faults["tc_high"], current_faults["cj_high"])
42    )
43    print(
44        "Temp Low:   %s | CJ Low:   %s"
45        % (current_faults["tc_low"], current_faults["cj_low"])
46    )
47    print(
48        "Temp Range: %s | CJ Range: %s"
49        % (current_faults["tc_range"], current_faults["cj_range"])
50    )
51    print("")
52    print(
53        "Open Circuit: %s Voltage Over/Under: %s"
54        % (current_faults["open_tc"], current_faults["voltage"])
55    )
56    print("")
57
58    time.sleep(1.0)