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.
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
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_rtdCreate 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.
| 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. |
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
max31865.MAX31865().configure(wires=None, filter_hz=None, auto_convert=None, bias=None, rtd_nominal=None, ref_resistor=None) -> boolConfigure wiring, filter, conversion mode, bias, and calibration.
| 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
max31865.MAX31865().read() -> dictRead RTD raw value, resistance, temperature, and fault state.
max31865.MAX31865().raw() -> int
max31865.MAX31865().raw() -> intRead the 15-bit RTD ADC value.
max31865.MAX31865().resistance() -> float
max31865.MAX31865().resistance() -> floatRead RTD resistance in ohms.
max31865.MAX31865().temperature() -> float
max31865.MAX31865().temperature() -> floatRead RTD temperature in Celsius.
max31865.MAX31865().fault() -> dict
max31865.MAX31865().fault() -> dictRead and decode fault status.
max31865.MAX31865().clear_fault() -> bool
max31865.MAX31865().clear_fault() -> boolClear the fault status register.
max31865.MAX31865().bias(enabled=None) -> bool
max31865.MAX31865().bias(enabled=None) -> boolEnable or disable VBIAS output.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
enabled |
bool |
positional or keyword | No | Optional value. Defaults to None. |
max31865.MAX31865().auto_convert(enabled=None) -> bool
max31865.MAX31865().auto_convert(enabled=None) -> boolEnable or disable continuous conversion mode.
| 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
max31865.MAX31865().set_thresholds(low_raw, high_raw) -> boolSet raw RTD fault thresholds.
| 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
max31865.MAX31865().thresholds() -> dictRead raw RTD fault thresholds.
max31865.MAX31865().info() -> dict
max31865.MAX31865().info() -> dictReturn SPI, wiring, filter, conversion, and calibration state.
max31865.MAX31865().close() -> bool
max31865.MAX31865().close() -> boolRelease this MAX31865 handle.
max31865.MAX31865().Example
max31865.MAX31865().Exampleprobe = 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
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) -> boolLegacy: initialize the module-level default MAX31865 converter.
Prefer ``probe = max31865.MAX31865(...)`` for new projects. The legacy wrapper keeps older singleton-style scripts working.
| 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. |
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
max31865.configure(wires: int = None, filter_hz: int = None, auto_convert: bool = None, bias: bool = None, rtd_nominal: float = None, ref_resistor: float = None) -> boolConfigure RTD wiring, filter, conversion mode, bias, and calibration.
| 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. |
bool True when the configuration register is updated.
max31865.read() -> dict
max31865.read() -> dictRead 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.
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
max31865.raw() -> intRead the 15-bit RTD ADC value.
int Integer raw RTD value after removing the fault bit.
max31865.resistance() -> float
max31865.resistance() -> floatRead RTD resistance in ohms.
float Float RTD resistance in ohms.
max31865.temperature() -> float
max31865.temperature() -> floatRead RTD temperature in Celsius.
float Float temperature in degrees Celsius using the stored RTD nominal and reference resistor values.
max31865.fault() -> dict
max31865.fault() -> dictRead and decode MAX31865 fault status.
dict Dict with ``fault``, ``fault_status``, ``high_threshold``, ``low_threshold``, ``refin_low``, ``refin_high``, ``rtdin_low``, and ``overvoltage_undervoltage``.
max31865.clear_fault() -> bool
max31865.clear_fault() -> boolClear the MAX31865 fault status register.
bool True when the clear-fault bit is written.
max31865.bias(enabled: bool = None) -> bool
max31865.bias(enabled: bool = None) -> boolEnable or disable the MAX31865 VBIAS output.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
enabled |
bool |
positional or keyword | No | Optional bias state. True enables VBIAS, False disables it. Defaults to True. |
bool True when the configuration register is updated.
max31865.auto_convert(enabled: bool = None) -> bool
max31865.auto_convert(enabled: bool = None) -> boolEnable or disable continuous conversion mode.
| 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. |
bool True when the configuration register is updated.
max31865.set_thresholds(low_raw: int, high_raw: int) -> bool
max31865.set_thresholds(low_raw: int, high_raw: int) -> boolSet low and high raw RTD fault thresholds.
| 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. |
bool True when both threshold registers are written.
max31865.thresholds() -> dict
max31865.thresholds() -> dictRead raw RTD fault thresholds.
dict Dict with ``low_raw``, ``high_raw``, and the raw 16-bit threshold register values.
max31865.info() -> dict
max31865.info() -> dictReturn MAX31865 module state.
dict Dict with initialization state, SPI pins, frequency, mode, wire count, filter, conversion mode, bias, RTD nominal value, and reference resistor value.