herosdevices.hardware.raspberrypi.max318xx.max31855¶
Uses Superclass MAX318xx for communication methods and implements MAX31855 specific functions.
Module Contents¶
- herosdevices.hardware.raspberrypi.max318xx.max31855.temperature_NIST(t_remote: float, t_ambient: float) float ¶
Correct temperature for ambient effects according to the Adafruit library.
https://github.com/adafruit/Adafruit_CircuitPython_MAX31855/blob/main/adafruit_max31855.py This function applies a correction to the remote thermocouple temperature reading based on the ambient temperature, using the polynomial approximations from the Adafruit MAX31855 library.
- Parameters:
t_remote (float) – The remote thermocouple junction temperature in Celsius.
t_ambient (float) – The ambient (cold junction) temperature in Celsius.
- Returns:
Corrected temperature in Celsius.
- Return type:
float
- Raises:
RuntimeError – If the total thermoelectric voltage is out of the expected range.
- class herosdevices.hardware.raspberrypi.max318xx.max31855.MAX31855(cs_pins: dict, miso_pin: int = 5, clk_pin: int = 7, invert_sign: bool = False)¶
Bases:
herosdevices.hardware.raspberrypi.max318xx.max318xx.MAX318xx
Class to interface with MAX31855 thermocouple-to-digital converter.
- Parameters:
cs_pin (int) – Chip select GPIO pin. Default is 24.
miso_pin (int) – MISO GPIO pin. Default is 5.
clk_pin (int) – CLK GPIO pin. Default is 7.
invert_sign (bool) – Whether to invert the sign of the temperature reading (default: False).
- read_temperature()¶
Returns the temperature in Celsius.
- invert_sign = False¶
- static convert_bits(data: list) tuple[int, int] ¶
Convert raw bits from sensor to temperature readings.
- Parameters:
data (list) – List of integers representing raw bits.
- Returns:
- (t_tc, t_ref) where:
t_tc (float): Thermocouple temperature. t_ref (float): Cold junction (reference) temperature.
- Return type:
tuple
- transform_bytes(data: list) tuple[int, int] ¶
Extract temperature data from raw byte list.
- Parameters:
data (list) – List of bytes received from sensor.
- Returns:
- (t_tc, t_ref)
t_tc (float): Thermocouple temperature. t_ref (float): Cold junction (reference) temperature.
- Return type:
tuple
- read_temp(cs_pin: int, num_registers: int, convert: collections.abc.Callable[[float, float], float]) float ¶
Read temperature on port cs_pin.
- cs_pins¶
- miso_pin = 9¶
- mosi_pin = 10¶
- clk_pin = 11¶
- write_register(reg_num: int, data_byte: int) None ¶
Write a byte to a specified register.
- Parameters:
regNum (int) – Register number to write to.
dataByte (int) – Data byte to write.
- read_register(cs_pin: int, num_registers: int, reg_num_start: int | None = None) list[int] ¶
Read one or more bytes starting from a specified register.
- Parameters:
cs_pin (int) – Chip select GPIO pin number.
numRegisters (int) – Number of bytes to read.
regNumStart (int, optional) – Starting register number for the read operation.
- Returns:
List of bytes read from the device.
- Return type:
list
- send_byte(byte: int) None ¶
Send a byte via SPI by bit-banging.
- Parameters:
byte (int) – Byte value to send.
- recv_byte() int ¶
Receive a byte via SPI by bit-banging.
- Returns:
Byte received.
- Return type:
int
- create_dict(values: list[float], observable: str, unit: str) dict ¶
Build dictionary of observables to be returned by the sensor.