Add support for second thermocouple

This commit is contained in:
huskee 2023-12-12 19:05:53 +02:00
parent 9736c39939
commit 980c96cb40

View file

@ -1,40 +1,50 @@
#include <Arduino.h>
#include <pinout.h>
#include <SPI.h>
#include <Adafruit_MAX31855.h> #include <Adafruit_MAX31855.h>
#include <Arduino.h>
#include <SPI.h>
#include <pinout.h>
#define CS D8 #define CS_A D2
Adafruit_MAX31855 thermocouple(CS); #define CS_B D3
Adafruit_MAX31855 thermocoupleA(CS_A);
Adafruit_MAX31855 thermocoupleB(CS_B);
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
while(!Serial) delay(1); while (!Serial) delay(1);
SPI.begin(); SPI.begin();
Serial.println("MAX31855 test"); Serial.println("MAX31855 test");
delay(500); delay(500);
Serial.println("sensor init"); Serial.println("sensor init");
if (!thermocouple.begin()) { if (!thermocoupleA.begin() | !thermocoupleB.begin()) {
Serial.println("sensor init error"); Serial.println("sensor init error");
while(true) delay(10); while (true) delay(10);
} }
Serial.println("init done");
Serial.println("init done");
} }
void loop() { void loop() {
Serial.print(">internal:"); Serial.print(">internalA:");
Serial.println(thermocouple.readInternal()); Serial.println(thermocoupleA.readInternal());
Serial.print(">internalB:");
Serial.println(thermocoupleB.readInternal());
double c = thermocouple.readCelsius(); double cA = thermocoupleA.readCelsius();
if (isnan(c)) { double cB = thermocoupleB.readCelsius();
uint8_t e = thermocouple.readError(); if (isnan(cA) | isnan(cB)) {
if (e & MAX31855_FAULT_OPEN) Serial.println("FAULT: thermocouple open"); uint8_t eA = thermocoupleA.readError();
if (e & MAX31855_FAULT_SHORT_GND) Serial.println("FAULT: thermocouple short to GND"); uint8_t eB = thermocoupleB.readError();
if (e & MAX31855_FAULT_SHORT_VCC) Serial.println("FAULT: thermocouple short to VCC"); if (eA & MAX31855_FAULT_OPEN) Serial.println("FAULT: thermocouple A open");
} else { if (eA & MAX31855_FAULT_SHORT_GND) Serial.println("FAULT: thermocouple A short to GND");
Serial.print(">tempc:"); if (eA & MAX31855_FAULT_SHORT_VCC) Serial.println("FAULT: thermocouple A short to VCC");
Serial.println(c); if (eB & MAX31855_FAULT_OPEN) Serial.println("FAULT: thermocouple B open");
} if (eB & MAX31855_FAULT_SHORT_GND) Serial.println("FAULT: thermocouple B short to GND");
delay(1000); if (eB & MAX31855_FAULT_SHORT_VCC) Serial.println("FAULT: thermocouple B short to VCC");
} else {
Serial.print(">tempcA:");
Serial.println(cA);
Serial.print(">tempcB:");
Serial.println(cB);
}
delay(1000);
} }