Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adafruit module MAX31865 incompatibility with Raspberry Pi 5. #892

Open
domensnuderl opened this issue Sep 6, 2024 · 0 comments
Open

Adafruit module MAX31865 incompatibility with Raspberry Pi 5. #892

domensnuderl opened this issue Sep 6, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@domensnuderl
Copy link

Board Name

Raspberry Pi 5

Steps

When using the Adafruit MAX31865 library with the busio.SPI interface on a Raspberry Pi 5, I am receiving inconsistent and erratic temperature and resistance readings from the RTD sensor. The temperatures alternate between extremely high (988.79°C), extremely low (-242.02°C), and correct values (~19°C). Additionally, the resistance readings sometimes show 0 ohms, suggesting an issue in communication or measurement handling.

Hardware Setup:
Board: Raspberry Pi 5
SPI Communication: Using busio.SPI (with manual Chip Select handling via gpiod)
RTD Sensor: 100-ohm PT100 3-wire RTD
Adafruit MAX31865 Library
Adafruit Blinka

Issue Details:
Erratic Temperature Readings: Temperature readings fluctuate between valid values (~19°C) and extreme values such as -242.02°C and 988.79°C. The extreme values appear in a pattern, and the valid readings are rare.

Zero Resistance Readings: At times, the raw resistance returned by the MAX31865 library is 0 ohms, which is not expected for a PT100 sensor.
Correct Readings Are Sporadic: Occasionally, the sensor returns a correct reading, but this is inconsistent.

Expected Behavior:
The temperature readings should be stable and consistent with the actual environment temperature.
The raw resistance readings from the RTD sensor should be in the expected range (close to 100 ohms at room temperature for a PT100 sensor).
Code Example:
Here is the code I used for interfacing with the MAX31865:

python

import gpiod
import time
import board
import busio
from adafruit_max31865 import MAX31865

chip = gpiod.Chip('gpiochip0')  # Use gpiochip0 for GPIO lines
cs_line = chip.get_line(8)  # GPIO8 (Pin 24) for Chip Select
cs_line.request(consumer='MAX31865_CS', type=gpiod.LINE_REQ_DIR_OUT, default_vals=[1])

spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)

while not spi.try_lock():
    pass
spi.configure(baudrate=100000, phase=1, polarity=0)
spi.unlock()


def select_chip():
    cs_line.set_value(0)  # CS low to start communication

def deselect_chip():
    cs_line.set_value(1)  # CS high to end communication


rtd = MAX31865(spi, cs=None, rtd_nominal=100.0, wires=3)


def read_temperature():
    select_chip()
    temperature = rtd.temperature
    deselect_chip()
    return temperature

def read_raw_resistance():
    select_chip()
    resistance = rtd.resistance
    deselect_chip()
    return resistance

while True:
    temperature = read_temperature()
    resistance = read_raw_resistance()
    print(f"Temperature: {temperature:.2f} °C, Resistance: {resistance:.2f} ohms")
    time.sleep(1)`

Observed Behavior:
Temperature:
988.79 °C
-242.02 °C
Correct value: ~19°C
Resistance:
0.00 ohms (several times)
429.99 ohms (occasional)
Correct value (approx. 100 ohms) observed infrequently

Steps to Reproduce:
Set up the Raspberry Pi with gpiod and busio.SPI.
Connect a PT100 3-wire RTD to the MAX31865 breakout board.
Run the provided code to read temperature and raw resistance values.
Observe erratic readings.

Additional Information:
I suspect there may be issues with how the SPI communication is being handled within the MAX31865 library or potentially timing issues related to busio.SPI.
Lowering the SPI speed (e.g., to 100 kHz) did not resolve the issue.

Request:
Could you please review the SPI and communication handling in the MAX31865 library? There may be issues with handling the RTD sensor correctly under certain conditions, especially when using manual Chip Select control or specific Raspberry Pi models.

Description

No response

Additional information

No response

@domensnuderl domensnuderl added the bug Something isn't working label Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant