I'm trying to read temperature from a 3-wire PT100 sensor and max31865 chip. The chip has the correct jumpers soldered to define it as 3 wire.

I have tried to follow these instructions as closely as possible.

I am using a Raspberry Pi 4B, with the latest Bookworm default Pi OS installed. I am connected to the Pi over SSH from the terminal via Wifi from a MacBook Pro, not using the GUI in any way.

Becuase Bookworm requires a virtual environment, I have set that first in this way:

mkdir myproject
cd myproject
python -m venv --system-site-packages env
source env/bin/activate

From 'sudo raspi-config' I have done the following:

In interface options - enabled SPI interface
In interface options - disabled "shell messages on the serial connection"
In interface options - enabled "serial port hardware"

Then rebooted and re-enabled the virtual environment.

My sensor hardware is wired the same as shown in the adafruit documentation except that I'm using a different ground pin (physical pin 6 instead of pin 9).

pinout from adafruit for max31865 connections

I have installed the max31865 module in the virtual environment like this without errors:

pip3 install adafruit-circuitpython-max31865

When I run their suggested code, I am using physical pin 29 (GPIO 5) as my Chip Select pin.

I'm also trying to keep pin GPIO27 low, and set as an output.

Here is my code:

import time
import board
import digitalio
import adafruit_max31865
import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
#pin definitions
led_pin37 = 26
# Suppress warnings
# Use "GPIO" pin numbering
# Set GPIO pin 26 or Pin D37 as output
GPIO.setup(led_pin37, GPIO.OUT)
# Create sensor object, communicating over the board's default SPI bus
spi = board.SPI()
cs = digitalio.DigitalInOut(board.D5) # Chip select of the MAX31865 board.
sensor = adafruit_max31865.MAX31865(spi, cs, rtd_nominal=100, ref_resistor=430.0, wires=3)
# Note you can optionally provide the thermocouple RTD nominal, the reference
# resistance, and the number of wires for the sensor (2 the default, 3, or 4)
# with keyword args:
# sensor = adafruit_max31865.MAX31865(spi, cs, rtd_nominal=100, ref_resistor=430.0,wires=2)
# Main loop to print the temperature every second.
while True:
    GPIO.output(led_pin37, GPIO.LOW)  # Turn GPIO 26 or pin 37 low 
    # Read temperature.
    temp = sensor.temperature
    # Print the value.
    print("Temperature: {0:0.3f}C".format(temp))
    # Delay for a second.

When I run this using python mycode.py

I get a continuous incorrect reading from the temperature sensor, (it doesn't change if I warm the sensor with my fingers):

Temperature: -242.020C
Temperature: -242.020C
Temperature: -242.020C
Temperature: -242.020C
Temperature: -242.020C

I've also tried modifying the code so that the Chip Select pin is defined as D29 instead of D5 (my Chip Select pin is wired to physical pin 29):

cs = digitalio.DigitalInOut(board.D29) # Chip select of the MAX31865 board.

Which immediately gives the following error:

AttributeError: module 'board' has no attribute 'D29'. Did you mean: 'D19'?

What am I doing wrong?

Photo of the max31865 chip max31865 chip

Photo of the Pi board pi board

  • CircuitPython is designed to run on microcontroller boards. It is possible to force it to run on a Pi (but few experienced users use it). Have you installed Blinka?
    – Milliways
    Commented Oct 22, 2023 at 22:54
  • On a previous setup I tried installing Blinka. It installed what looked like a lot of uneccessary modules (Chromium? Plex?), and then I had the same issue. Am I approaching this the wrong way? What is the correct way to get this probe to read using a Pi in python?
    – tomh
    Commented Oct 23, 2023 at 5:09
  • I can't really say as I haven't used CircuitPython or a Max31865. You appear to be trying to mix Python & CircuitPython but they are different. If I were doing this I would search for a normal Python module (or write one). I find the Adafruit documentation and instructions very confusing. Adafruit seem to be the only people to use CircuitPython.
    – Milliways
    Commented Oct 23, 2023 at 5:18


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.