Okay, getting there...
This is the code I have done so far.. I suppose it's probably worth asking if I'm heading in the right direction... I don't want to head off down the wrong route..
#include <LiquidCrystal_I2C.h>
#include <Adafruit_MAX31865.h>
// Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31865 thermo = Adafruit_MAX31865(10, 11, 12, 13);
// use hardware SPI, just pass in the CS pin
//Adafruit_MAX31865 thermo = Adafruit_MAX31865(10);
// The value of the Rref resistor. Use 430.0 for PT100 and 4300.0 for PT1000
#define RREF 4300.0
// The 'nominal' 0-degrees-C resistance of the sensor
// 100.0 for PT100, 1000.0 for PT1000
#define RNOMINAL 1000.0
//#define buzzer 7 //buzzer pin
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x3F for a 16 chars and 2 line display
float TOO_COLD = -1.0f;
float TOO_HOT = +10000.0f;
const float pressure[] = {
0.000, 0.038, 0.075, 0.114, 0.155, 0.196, 0.238, 0.282, 0.327, 0.373, // 100 ... 109
0.421, 0.469, 0.520, 0.571, 0.624, 0.679, 0.734, 0.792, 0.851, 0.911, // 110 ... 119
0.973, 1.037, 1.103, 1.170, 1.238, 1.309, 1.381, 1.456, 1.532, 1.609, // 120 ... 129
1.689, 1.771, 1.855, 1.941, 2.029, 2.119, 2.211, 2.305, 2.402, 2.501, // 130 ... 139
2.602, 2.705, 2.811, 2.919, 3.030, 3.143, 3.259, 3.377, 3.498, 3.622, // 140 ... 149
3.748, 3.877, 4.009, 4.143, 4.281, 4.421, 4.564, 4.711, 4.860, 5.013, // 150 ... 159
5.168 // 160
};
float pressureFromTemperature(long temp) {
if (temp < 100) return TOO_COLD;
if (temp > 160) return TOO_HOT;
return pressure[temp-100];
}
void printPressureFor(long temp) {
float p = pressureFromTemperature(thermo.temperature(RNOMINAL, RREF)); //pressureFromTemperature(temp);
Serial.print(F("T° = ")); Serial.print(temp);
if (p <= TOO_COLD) Serial.println(F(" \t➜ Too Cold"));
else if (p >= TOO_HOT) Serial.println(F(" \t➜ Too Hot"));
else {
Serial.print(F("\t➜ P = "));
Serial.println(p, 3);
}
}
void setup() {
Serial.begin(115200);
Serial.println("Adafruit MAX31865 PT100 Sensor Test!");
lcd.init();
lcd.clear();
lcd.backlight(); // Make sure backlight is on
thermo.begin(MAX31865_3WIRE); // set to 2WIRE or 4WIRE as necessary
void loop() {
uint16_t rtd = thermo.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("Temperature = "); Serial.println(); printPressureFor(thermo.temperature(RNOMINAL, RREF));
lcd.clear();
lcd.setCursor(0,0); //Set cursor to character 0 on line 0
lcd.clear();
lcd.setCursor(0,0); //Set cursor to character 2 on line 0
lcd.print("Temp= ");
lcd.print(thermo.temperature(RNOMINAL, RREF));
lcd.print((char)223); //set Degrees symbol
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("Press= ");
//lcd.print(???????); //display reading of corrosponding pressure
lcd.print("Bar");
// Check and print any faults
uint8_t fault = thermo.readFault();
if (fault) {
Serial.print("Fault 0x"); Serial.println(fault, HEX);
if (fault & MAX31865_FAULT_HIGHTHRESH) {
Serial.println("RTD High Threshold");
lcd.clear();
lcd.setCursor(0,0); //Move cursor to character 2 on line 1
lcd.print("RTD High Threshold");
}
if (fault & MAX31865_FAULT_LOWTHRESH) {
Serial.println("RTD Low Threshold");
lcd.clear();
lcd.setCursor(0,0); //Move cursor to character 2 on line 1
lcd.print("RTD Low Threshold");
}
if (fault & MAX31865_FAULT_REFINLOW) {
Serial.println("REFIN- > 0.85 x Bias");
lcd.clear();
lcd.setCursor(0,0); //Move cursor to character 2 on line 1
lcd.print("RTD Low Threshold");
}
if (fault & MAX31865_FAULT_REFINHIGH) {
Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
lcd.clear();
lcd.setCursor(0,0); //Move cursor to character 2 on line 1
lcd.print("REFIN- < 0.85 x Bias - FORCE- open");
}
if (fault & MAX31865_FAULT_RTDINLOW) {
Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
lcd.clear();
lcd.setCursor(0,0); //Move cursor to character 2 on line 1
lcd.print("RTDIN- < 0.85 x Bias - FORCE- open");
}
if (fault & MAX31865_FAULT_OVUV) {
Serial.println("Under/Over voltage");
lcd.clear();
lcd.setCursor(0,0); //Move cursor to character 2 on line 1
lcd.print("Under/Over voltage");
}
thermo.clearFault();
}
Serial.println();
delay(2000);
}