Skip to content

Commit

Permalink
Update MAX31865_Single.ino
Browse files Browse the repository at this point in the history
  • Loading branch information
budulinek committed Oct 6, 2023
1 parent b2e0a8c commit 8a4bf64
Showing 1 changed file with 50 additions and 43 deletions.
93 changes: 50 additions & 43 deletions examples/MAX31865_Single/MAX31865_Single.ino
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,13 @@ void setup() {
}

void loop() {
// Read and print temperature and faults (non-blocking)
readRtd();
// non-blocking state machine, read and print temperature and faults
stateMachine();

// Place your other functions here...

}

void readRtd() {
void stateMachine() {
if (rtdTimer.isOver() == false) {
return;
}
Expand All @@ -89,45 +88,8 @@ void readRtd() {
break;
case 2:
{
uint16_t rtdVal = rtd.getRTD();

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

// Check and print any faults
uint8_t fault = rtd.getFault();
if (fault) {
Serial.print("Fault 0x");
Serial.println(fault, HEX);
if (fault & MAX31865::FAULT_HIGHTHRESH_BIT) {
Serial.println("RTD High Threshold");
}
if (fault & MAX31865::FAULT_LOWTHRESH_BIT) {
Serial.println("RTD Low Threshold");
}
if (fault & MAX31865::FAULT_REFINLOW_BIT) {
Serial.println("REFIN- > 0.85 x Bias");
}
if (fault & MAX31865::FAULT_REFINHIGH_BIT) {
Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
}
if (fault & MAX31865::FAULT_RTDINLOW_BIT) {
Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
}
if (fault & MAX31865::FAULT_OVUV_BIT) {
Serial.println("Under/Over voltage");
}
rtd.clearFault();
}
Serial.println();
printTemp();
printFault();

rtd.enableBias(false); // disable bias voltage
rtdTimer.sleep(1000);
Expand All @@ -138,3 +100,48 @@ void readRtd() {
break;
}
}

void printTemp() {
uint16_t rtdVal = rtd.getRTD();

Serial.print("RTD value: ");
Serial.println(rtdVal);
float ratio = rtdVal;
ratio /= 32768;
Serial.print("Ratio = ");
Serial.println(ratio, 8);
Serial.print("Resistance = ");
Serial.println(RREF * ratio, 8);
Serial.print("Temperature = ");
Serial.println(rtd.getTemp(RNOMINAL, RREF));
}

// Check and print any faults
void printFault() {
uint8_t fault = rtd.getFault();

if (fault) {
Serial.print("Fault 0x");
Serial.println(fault, HEX);
if (fault & MAX31865::FAULT_HIGHTHRESH_BIT) {
Serial.println("RTD High Threshold");
}
if (fault & MAX31865::FAULT_LOWTHRESH_BIT) {
Serial.println("RTD Low Threshold");
}
if (fault & MAX31865::FAULT_REFINLOW_BIT) {
Serial.println("REFIN- > 0.85 x Bias");
}
if (fault & MAX31865::FAULT_REFINHIGH_BIT) {
Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
}
if (fault & MAX31865::FAULT_RTDINLOW_BIT) {
Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
}
if (fault & MAX31865::FAULT_OVUV_BIT) {
Serial.println("Under/Over voltage");
}
rtd.clearFault();
}
Serial.println();
}

0 comments on commit 8a4bf64

Please sign in to comment.