PT100 MAX31865 Temperature Sensor

Hi all,

I’ve been working with my Particle Photon and a PT1000 breakout board (https://www.adafruit.com/product/3328) and an RTD air probe (https://www.mcmaster.com/#1237n11/=1a5mxwd), trying to get an accurate temperature reading. I’m also using this library - https://github.com/adafruit/Adafruit_MAX31865 - and the following code:

#include "application.h"
#include "Adafruit_MAX31865.h"

// Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31865 sensor = Adafruit_MAX31865(A2, A5, A4, A3);
// use hardware SPI, just pass in the CS pin
//Adafruit_MAX31865 sensor = Adafruit_MAX31865(A2);

// The value of the Rref resistor. Use 430.0!
#define RREF 430.0

void setup() {
  Serial.begin(115200);
  Serial.println("Adafruit MAX31865 PT100 Sensor Test!");
  SPI.begin();
  sensor.begin(MAX31865_3WIRE);  // currently using 3WIRE RTD
}

void loop() {
  uint16_t rtd = sensor.readRTD();

  Serial.print("RTD value: "); Serial.println(rtd);
  float ratio = rtd;
  ratio /= 32768;
  Serial.print("Ratio = "); Serial.println(ratio,8);
  Serial.print("Resistance = "); Serial.println(RREF*ratio,8);
  //Serial.print("RREF = "); Serial.println(RREF);
  Serial.print("Temperature = ");
  Serial.println(sensor.temperature(100, RREF));

  // Check and print any faults
  uint8_t fault = sensor.readFault();
  if (fault) {
    Serial.print("Fault 0x"); Serial.println(fault, HEX);
    if (fault & MAX31865_FAULT_HIGHTHRESH) {
      Serial.println("RTD High Threshold");
    }
    if (fault & MAX31865_FAULT_LOWTHRESH) {
      Serial.println("RTD Low Threshold");
    }
    if (fault & MAX31865_FAULT_REFINLOW) {
      Serial.println("REFIN- > 0.85 x Bias");
    }
    if (fault & MAX31865_FAULT_REFINHIGH) {
      Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
    }
    if (fault & MAX31865_FAULT_RTDINLOW) {
      Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
    }
    if (fault & MAX31865_FAULT_OVUV) {
      Serial.println("Under/Over voltage");
    }
    sensor.clearFault();
  }
  Serial.println();
  delay(10000);
}

However, when I print my output to Serial, I get some absurd answers - like the temperature is almost 1000 degrees Celsius. These are my serial print outs:

I don’t fully understand what the faults mean but I know the issue is that my RTD value is way too high, at 32767 which is the max, but I’m not sure why it’s giving me this. I checked the wiring and I believe that I had wired the thing correctly on the Photon. Might anyone know what’s wrong?

First I’d use hardware SPI Adafruit_MAX31865 sensor(A2);
And as you see, I don’t instatiate the object with an assignment, but direct.
So if you want to stick wich software SPI, I’d do (providing the parameter order is correct)

Adafruit_MAX31865 sensor(A2, A5, A4, A3);

BTW, if you want to calcualte the ratio of the reading 0 … 32767 as 0 … 100% you’d rather divide by 32767 so that 32767 = 100% = 1.00.

And stating the wiring is correct is one thing, if you show how you’ve wired the sensor really, we might even believe it :wink:

Hi @ScruffR, thanks for the reply! I tried implementing the changes you suggested, although now I get an RTD of 0 (when I was debugging it yesterday, I’d always get that it’d either be 0 or the max value.)

My current code for reference:

#include "application.h"
#include "Adafruit_MAX31865.h"

// Use software SPI: CS, DI, DO, CLK
//Adafruit_MAX31865 sensor = Adafruit_MAX31865(A2, A5, A4, A3);
// use hardware SPI, just pass in the CS pin
//Adafruit_MAX31865 sensor = Adafruit_MAX31865(A2);

Adafruit_MAX31865 sensor(A2, A5, A4, A3);

// The value of the Rref resistor. Use 430.0!
#define RREF 430.0

void setup() {
  Serial.begin(115200);
  Serial.println("Adafruit MAX31865 PT100 Sensor Test!");
  SPI.begin();
  sensor.begin(MAX31865_3WIRE);  // currently using 3WIRE RTD
}

void loop() {
  uint16_t rtd = sensor.readRTD();

  Serial.print("RTD value: "); Serial.println(rtd);
  float ratio = rtd;
  ratio /= 32767;
  Serial.print("Ratio = "); Serial.println(ratio,8);
  Serial.print("Resistance = "); Serial.println(RREF*ratio,8);
  Serial.print("RREF = "); Serial.println(RREF);
  Serial.print("Temperature = ");
  Serial.println(sensor.temperature(100, RREF));

  // Check and print any faults
  uint8_t fault = sensor.readFault();
  if (fault) {
    Serial.print("Fault 0x"); Serial.println(fault, HEX);
    if (fault & MAX31865_FAULT_HIGHTHRESH) {
      Serial.println("RTD High Threshold");
    }
    if (fault & MAX31865_FAULT_LOWTHRESH) {
      Serial.println("RTD Low Threshold");
    }
    if (fault & MAX31865_FAULT_REFINLOW) {
      Serial.println("REFIN- > 0.85 x Bias");
    }
    if (fault & MAX31865_FAULT_REFINHIGH) {
      Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
    }
    if (fault & MAX31865_FAULT_RTDINLOW) {
      Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
    }
    if (fault & MAX31865_FAULT_OVUV) {
      Serial.println("Under/Over voltage");
    }
    sensor.clearFault();
  }
  Serial.println();
  delay(10000);
}

And here’s a picture of my setup:

Isn’t the 3v3 pin on the sensor meant as output and shouldn’t the sensor by powered via Vin (from 3v3 or Vin on the Photon)?

Also your jumpers are soldered for 3-wire but I can’t tell whether the 2/4 bridge has been correctly cut (doesn’t really look like it to me).

1 Like

You’re right actually; I did have it wired to Vin earlier but I wasn’t sure if it had something to do with how much was going in (5V vs. 3v3) so I changed it while forgetting that it’s supposed to be an output. Fixed that though!

I also cut the 2/4 bridge more thoroughly this time, although my method of doing so was just getting an exo knife and carving into it. I measured the resistance between the two beforehand and it was very small, about 0.1 Ohms. Afterwards, it’s about 246 Ohms although this is still considered connected and I’m not sure how else to disconnect them.

EDIT: Actually I just measured them again when they’re not being powered and it’s several million Ohms so they are disconnected. However I am still getting RTD = 0.

Have you tried 3v3 on the Photon to VIN on the shield? The SPI logic level corresponds to the VIN supply.

I asked a similar question last week - PT100 MAX31865 Temperature Sensor (this veriy thread, after moving it back here) - although now I have narrowed down the problem to a more specific topic. Still using this library - https://github.com/adafruit/Adafruit_MAX31865

Last week, I was trying to get an RTD temperature sensor to work with a Particle Photon’s SPI spins - I used both the device itself and also with a Shield that is supposed to let it have an Arduino’s same outputs. Both of which didn’t work; I would still get an RTD value of 0.

However, today I borrowed an Arduino to test it on. Same set-up, did not change the RTD breakout board or anything. When I ran the code in Arduino, it worked! --So that means the problem seems to be the Particle Photon or possibly its SPI channels. Why wouldn’t this work with the Shield (I used 10 - 13 there.)

Are A2 - A5 the incorrect pins to use for SPI? When I checked the chart, they seemed to be correct:

Or should I be using some other pins?

Thanks to @ScruffR for moving these together. Looking at your photo above, I think you have wiring errors.

Can you please redo the wiring and show it clearly in a photo if it doesn’t work?

  • It is not clear where the teal colored wire connects.
  • It looks like the teal wire and the yellow are both on SDI on the sensor
  • It doesn’t look like SDO is connected on the sensor side (column 23 on the breadboard)

Sorry about the double topic - I thought since it was more specific about something else it warranted another one.

This is my current wiring setup for the Particle:

Sorry about the lighting, I kept trying to angle it but the light from the board itself made it hard. The black wire is going to GND, the red wire is going to 3v3, and the white, yellow, green, and blue wire are going to 10 - 13 respectively.

@ScruffR’s question about trying 3v3 on the Photon to VIN on the shield - where would the red wire go from the Shield to the RTD board then? Would I take the 3v3 pin on the shield to the VIN on the RTD?

@bko The teal and blue wires were in the right places, it was just a very bad camera angle, sorry! I did upload an updated picture though.

My comment about 3v3 <-> VIN was posted before you added the Shield Shield to the setup. So when I used “shield” I was refering to the sensor breakout board.

@ScruffR

Yes, I have tried using the 3v3 pin too, and I still get an error of RTD = 0. Here’s the wiring I have right now:

I also noticed that this is what the readRTD code does in the cpp file:

Is this actually compatible with the Photon?

EDIT: Nevermind, I finally got it working! I had to use the hardware specialization instead. I went back and forth between them because I wasn’t sure which one would actually work better.

Hey, I have the same issue but I couldnt understand what did you change ?

I changed my initialization from

Adafruit_MAX31865 sensor = Adafruit_MAX31865(A2);

to

Adafruit_MAX31865 sensor(A2, A5, A4, A3);
1 Like

I have the same error on Arduino. Could you fix it afterwards?

I am tried to solve my problem as same as yours, i was changed my pin for CS, DI, DO , CLK to A2,A5,A4,A3 and my Vin to 3.3V. but my result always like this

`

RTD value: 32767
Ratio = 0.99996948
Resistance = 429.98687744
Temperature = 988.79
Fault 0xFF
RTD High Threshold
RTD Low Threshold
REFIN- > 0.85 x Bias
REFIN- < 0.85 x Bias - FORCE- open
RTDIN- < 0.85 x Bias - FORCE- open
Under/Over voltage
`