MojoScale Studio Docs
API Reference

max31865

MAX31865 RTD temperature module.

Studio Docs Sensors & I/O

import max31865

The max31865 module reads MAX31865-compatible platinum RTD converter boards over SPI. It supports PT100 and PT1000-style setups by letting you set the nominal RTD resistance, reference resistor, 2/3/4-wire mode, mains filter, bias, and fault thresholds.

Quick example

import max31865

probe = max31865.MAX31865(
    mosi=23,
    miso=19,
    sclk=18,
    cs=5,
    rtd_nominal=100.0,
    ref_resistor=430.0,
    wires=3,
)

reading = probe.read()
print(reading["temperature_c"], reading["resistance_ohms"])

if reading["fault"]:
    print(probe.fault())
    probe.clear_fault()

importmax31865

MAX31865 RTD temperature module.

The max31865 module reads MAX31865-compatible platinum RTD converter boards over SPI. It supports PT100 and PT1000-style setups by letting you set the nominal RTD resistance, reference resistor, 2/3/4-wire mode, mains filter, bias, and fault thresholds.

API 28 available

max31865.MAX31865(mosi: int, miso: int, sclk: int, cs: int, rtd_nominal: float = None, ref_resistor: float = None, wires: int = None, frequency: int = None, mode: int = None) -> max31865_rtd

Create and initialize an independent MAX31865 RTD converter.

Use one MAX31865 object for each physical RTD converter. Each object owns its chip-select pin, wiring mode, calibration values, thresholds, and SPI device handle.

Parameters
Name Type Pass as Required Description
mosi int positional or keyword Yes GPIO pin used for SPI MOSI / SDI.
miso int positional or keyword Yes GPIO pin used for SPI MISO / SDO.
sclk int positional or keyword Yes GPIO pin used for SPI clock.
cs int positional or keyword Yes GPIO pin used for chip select.
rtd_nominal float positional or keyword No Optional RTD resistance at 0°C in ohms. Use 100.0 for PT100 or 1000.0 for PT1000. Defaults to 100.0.
ref_resistor float positional or keyword No Optional reference resistor value in ohms. Defaults to 430.0.
wires int positional or keyword No Optional RTD wiring count. Use 2, 3, or 4. Defaults to 3.
frequency int positional or keyword No Optional SPI clock speed in hertz. Defaults to 1000000.
mode int positional or keyword No Optional SPI mode. Defaults to 1.
Returns

max31865_rtd max31865_rtd object.

max31865.MAX31865().configure(wires=None, filter_hz=None, auto_convert=None, bias=None, rtd_nominal=None, ref_resistor=None) -> bool

Configure wiring, filter, conversion mode, bias, and calibration.

Parameters
Name Type Pass as Required Description
wires int positional or keyword No Optional value. Defaults to None.
filter_hz int positional or keyword No Optional value. Defaults to None.
auto_convert any positional or keyword No Optional value. Defaults to None.
bias bool positional or keyword No Optional value. Defaults to None.
rtd_nominal float positional or keyword No Optional value. Defaults to None.
ref_resistor float positional or keyword No Optional value. Defaults to None.

max31865.MAX31865().read() -> dict

Read RTD raw value, resistance, temperature, and fault state.

max31865.MAX31865().raw() -> int

Read the 15-bit RTD ADC value.

max31865.MAX31865().resistance() -> float

Read RTD resistance in ohms.

max31865.MAX31865().temperature() -> float

Read RTD temperature in Celsius.

max31865.MAX31865().fault() -> dict

Read and decode fault status.

max31865.MAX31865().clear_fault() -> bool

Clear the fault status register.

max31865.MAX31865().bias(enabled=None) -> bool

Enable or disable VBIAS output.

Parameters
Name Type Pass as Required Description
enabled bool positional or keyword No Optional value. Defaults to None.

max31865.MAX31865().auto_convert(enabled=None) -> bool

Enable or disable continuous conversion mode.

Parameters
Name Type Pass as Required Description
enabled bool positional or keyword No Optional value. Defaults to None.

max31865.MAX31865().set_thresholds(low_raw, high_raw) -> bool

Set raw RTD fault thresholds.

Parameters
Name Type Pass as Required Description
low_raw int positional or keyword Yes Required value.
high_raw int positional or keyword Yes Required value.

max31865.MAX31865().thresholds() -> dict

Read raw RTD fault thresholds.

max31865.MAX31865().info() -> dict

Return SPI, wiring, filter, conversion, and calibration state.

max31865.MAX31865().close() -> bool

Release this MAX31865 handle.

max31865.MAX31865().Example

probe = max31865.MAX31865(mosi=23, miso=19, sclk=18, cs=5, wires=3) print(probe.temperature())

max31865.begin(mosi: int, miso: int, sclk: int, cs: int, rtd_nominal: float = None, ref_resistor: float = None, wires: int = None, frequency: int = None, mode: int = None) -> bool

Legacy: initialize the module-level default MAX31865 converter.

Prefer ``probe = max31865.MAX31865(...)`` for new projects. The legacy wrapper keeps older singleton-style scripts working.

Parameters
Name Type Pass as Required Description
mosi int positional or keyword Yes GPIO pin used for SPI MOSI / SDI.
miso int positional or keyword Yes GPIO pin used for SPI MISO / SDO.
sclk int positional or keyword Yes GPIO pin used for SPI clock.
cs int positional or keyword Yes GPIO pin used for chip select.
rtd_nominal float positional or keyword No Optional RTD resistance at 0°C in ohms. Use 100.0 for PT100 or 1000.0 for PT1000. Defaults to 100.0.
ref_resistor float positional or keyword No Optional reference resistor value in ohms. Common boards use 430.0 for PT100 or 4300.0 for PT1000. Defaults to 430.0.
wires int positional or keyword No Optional RTD wiring count. Use 2, 3, or 4. Defaults to 3.
frequency int positional or keyword No Optional SPI clock speed in hertz. Defaults to 1000000.
mode int positional or keyword No Optional SPI mode. Defaults to 1.
Returns

bool True when SPI is initialized and the default MAX31865 configuration is written.

max31865.configure(wires: int = None, filter_hz: int = None, auto_convert: bool = None, bias: bool = None, rtd_nominal: float = None, ref_resistor: float = None) -> bool

Configure RTD wiring, filter, conversion mode, bias, and calibration.

Parameters
Name Type Pass as Required Description
wires int positional or keyword No Optional RTD wiring count. Use 2, 3, or 4.
filter_hz int positional or keyword No Optional mains rejection filter. Use 50 or 60.
auto_convert bool positional or keyword No Optional continuous-conversion mode. Defaults to False.
bias bool positional or keyword No Optional VBIAS state. Defaults to False unless auto conversion is enabled.
rtd_nominal float positional or keyword No Optional RTD resistance at 0°C in ohms.
ref_resistor float positional or keyword No Optional reference resistor value in ohms.
Returns

bool True when the configuration register is updated.

max31865.read() -> dict

Read RTD raw value, resistance, temperature, and fault state.

In normal one-shot mode the module briefly enables bias, triggers one conversion, waits for it, reads the RTD register, then turns bias back off unless you configured bias to stay on.

Returns

dict Dict with ``ok``, ``raw``, ``rtd_raw``, ``resistance_ohms``, ``temperature_c``, ``fault``, decoded fault bits, ``rtd_nominal``, ``ref_resistor``, ``wires``, ``filter_hz``, ``auto_convert``, and ``bias``.

max31865.raw() -> int

Read the 15-bit RTD ADC value.

Returns

int Integer raw RTD value after removing the fault bit.

max31865.resistance() -> float

Read RTD resistance in ohms.

Returns

float Float RTD resistance in ohms.

max31865.temperature() -> float

Read RTD temperature in Celsius.

Returns

float Float temperature in degrees Celsius using the stored RTD nominal and reference resistor values.

max31865.fault() -> dict

Read and decode MAX31865 fault status.

Returns

dict Dict with ``fault``, ``fault_status``, ``high_threshold``, ``low_threshold``, ``refin_low``, ``refin_high``, ``rtdin_low``, and ``overvoltage_undervoltage``.

max31865.clear_fault() -> bool

Clear the MAX31865 fault status register.

Returns

bool True when the clear-fault bit is written.

max31865.bias(enabled: bool = None) -> bool

Enable or disable the MAX31865 VBIAS output.

Parameters
Name Type Pass as Required Description
enabled bool positional or keyword No Optional bias state. True enables VBIAS, False disables it. Defaults to True.
Returns

bool True when the configuration register is updated.

max31865.auto_convert(enabled: bool = None) -> bool

Enable or disable continuous conversion mode.

Parameters
Name Type Pass as Required Description
enabled bool positional or keyword No Optional auto-conversion state. True enables continuous conversions and keeps bias on. False returns to one-shot operation. Defaults to True.
Returns

bool True when the configuration register is updated.

max31865.set_thresholds(low_raw: int, high_raw: int) -> bool

Set low and high raw RTD fault thresholds.

Parameters
Name Type Pass as Required Description
low_raw int positional or keyword Yes Low threshold as a 15-bit raw RTD value.
high_raw int positional or keyword Yes High threshold as a 15-bit raw RTD value.
Returns

bool True when both threshold registers are written.

max31865.thresholds() -> dict

Read raw RTD fault thresholds.

Returns

dict Dict with ``low_raw``, ``high_raw``, and the raw 16-bit threshold register values.

max31865.info() -> dict

Return MAX31865 module state.

Returns

dict Dict with initialization state, SPI pins, frequency, mode, wire count, filter, conversion mode, bias, RTD nominal value, and reference resistor value.