import max31855
The max31855 module reads MAX31855-compatible cold-junction compensated thermocouple converter boards over read-only SPI. The chip variant determines the thermocouple type, such as K, J, N, T, S, R, or E; this module reads the digital result and decodes fault bits.
Quick example
import max31855
thermocouple = max31855.MAX31855(sclk=18, miso=19, cs=5)
reading = thermocouple.read()
if reading["ok"]:
print(reading["temperature_c"])
else:
print(reading["fault_bits"])
importmax31855
MAX31855 thermocouple module.
The max31855 module reads MAX31855-compatible cold-junction compensated thermocouple converter boards over read-only SPI. The chip variant determines the thermocouple type, such as K, J, N, T, S, R, or E; this module reads the digital result and decodes fault bits.
max31855.MAX31855(sclk: int, miso: int, cs: int, frequency: int = None, mode: int = None) -> max31855_thermocouple
max31855.MAX31855(sclk: int, miso: int, cs: int, frequency: int = None, mode: int = None) -> max31855_thermocoupleCreate and initialize an independent MAX31855 thermocouple converter.
Use one MAX31855 object for each physical converter. Each object owns its chip-select pin and SPI device handle.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
sclk |
int |
positional or keyword | Yes | GPIO pin used for SPI clock. |
miso |
int |
positional or keyword | Yes | GPIO pin used for SPI MISO / SO. |
cs |
int |
positional or keyword | Yes | GPIO pin used for chip select. |
frequency |
int |
positional or keyword | No | Optional SPI clock speed in hertz. Defaults to 4000000. |
mode |
int |
positional or keyword | No | Optional SPI mode. Defaults to 0. |
max31855_thermocouple max31855_thermocouple object.
max31855.MAX31855().read() -> dict
max31855.MAX31855().read() -> dictRead thermocouple temperature, cold-junction temperature, and faults.
max31855.MAX31855().temperature() -> float
max31855.MAX31855().temperature() -> floatRead thermocouple temperature in degrees Celsius.
max31855.MAX31855().internal_temperature() -> float
max31855.MAX31855().internal_temperature() -> floatRead internal cold-junction temperature in degrees Celsius.
max31855.MAX31855().raw() -> int
max31855.MAX31855().raw() -> intRead the raw 32-bit MAX31855 word.
max31855.MAX31855().fault() -> dict
max31855.MAX31855().fault() -> dictRead and decode fault bits.
max31855.MAX31855().info() -> dict
max31855.MAX31855().info() -> dictReturn SPI pin and configuration values.
max31855.MAX31855().close() -> bool
max31855.MAX31855().close() -> boolRelease this MAX31855 handle.
max31855.MAX31855().Example
max31855.MAX31855().Examplethermocouple = max31855.MAX31855(sclk=18, miso=19, cs=5) print(thermocouple.temperature())
max31855.begin(sclk: int, miso: int, cs: int, frequency: int = None, mode: int = None) -> bool
max31855.begin(sclk: int, miso: int, cs: int, frequency: int = None, mode: int = None) -> boolLegacy: initialize the module-level default MAX31855 converter.
Prefer ``thermocouple = max31855.MAX31855(...)`` for new projects. The legacy wrapper keeps older singleton-style scripts working.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
sclk |
int |
positional or keyword | Yes | GPIO pin used for SPI clock. |
miso |
int |
positional or keyword | Yes | GPIO pin used for SPI MISO / SO. |
cs |
int |
positional or keyword | Yes | GPIO pin used for chip select. |
frequency |
int |
positional or keyword | No | Optional SPI clock speed in hertz. Defaults to 4000000. |
mode |
int |
positional or keyword | No | Optional SPI mode. Defaults to 0. |
bool True when the SPI bus and device are ready.
max31855.read() -> dict
max31855.read() -> dictRead thermocouple temperature, cold-junction temperature, and faults.
dict Dict with ``ok``, ``temperature_c``, ``thermocouple_c``, ``internal_temperature_c``, ``cold_junction_c``, ``temperature_f``, ``fault``, ``fault_bits``, ``open_circuit``, ``short_to_gnd``, ``short_to_vcc``, and ``raw``.
max31855.temperature() -> float
max31855.temperature() -> floatRead thermocouple temperature in Celsius.
float Float thermocouple temperature in degrees Celsius. Raises a native error if the MAX31855 fault flag is set.
max31855.internal_temperature() -> float
max31855.internal_temperature() -> floatRead the MAX31855 internal cold-junction temperature.
float Float cold-junction temperature in degrees Celsius.
max31855.raw() -> int
max31855.raw() -> intRead the raw 32-bit MAX31855 word.
int Integer raw 32-bit value.
max31855.fault() -> dict
max31855.fault() -> dictRead and decode MAX31855 fault bits.
dict Dict with ``fault``, ``fault_bits``, ``open_circuit``, ``short_to_gnd``, ``short_to_vcc``, and ``raw``.
max31855.info() -> dict
max31855.info() -> dictReturn MAX31855 module state.
dict Dict with initialization state and SPI pin/configuration values.