#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
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);
}
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.
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:
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.
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.
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
`