MojoScale Studio Docs
API Reference

max31855

MAX31855 thermocouple module.

Studio Docs Sensors & I/O

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.

API 16 available

max31855.MAX31855(sclk: int, miso: int, cs: int, frequency: int = None, mode: int = None) -> max31855_thermocouple

Create 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.

Parameters
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.
Returns

max31855_thermocouple max31855_thermocouple object.

max31855.MAX31855().read() -> dict

Read thermocouple temperature, cold-junction temperature, and faults.

max31855.MAX31855().temperature() -> float

Read thermocouple temperature in degrees Celsius.

max31855.MAX31855().internal_temperature() -> float

Read internal cold-junction temperature in degrees Celsius.

max31855.MAX31855().raw() -> int

Read the raw 32-bit MAX31855 word.

max31855.MAX31855().fault() -> dict

Read and decode fault bits.

max31855.MAX31855().info() -> dict

Return SPI pin and configuration values.

max31855.MAX31855().close() -> bool

Release this MAX31855 handle.

max31855.MAX31855().Example

thermocouple = 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

Legacy: initialize the module-level default MAX31855 converter.

Prefer ``thermocouple = max31855.MAX31855(...)`` for new projects. The legacy wrapper keeps older singleton-style scripts working.

Parameters
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.
Returns

bool True when the SPI bus and device are ready.

max31855.read() -> dict

Read thermocouple temperature, cold-junction temperature, and faults.

Returns

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

Read thermocouple temperature in Celsius.

Returns

float Float thermocouple temperature in degrees Celsius. Raises a native error if the MAX31855 fault flag is set.

max31855.internal_temperature() -> float

Read the MAX31855 internal cold-junction temperature.

Returns

float Float cold-junction temperature in degrees Celsius.

max31855.raw() -> int

Read the raw 32-bit MAX31855 word.

Returns

int Integer raw 32-bit value.

max31855.fault() -> dict

Read and decode MAX31855 fault bits.

Returns

dict Dict with ``fault``, ``fault_bits``, ``open_circuit``, ``short_to_gnd``, ``short_to_vcc``, and ``raw``.

max31855.info() -> dict

Return MAX31855 module state.

Returns

dict Dict with initialization state and SPI pin/configuration values.