From 980c96cb4085157603098214acac226dd0b4efb9 Mon Sep 17 00:00:00 2001 From: huskee Date: Tue, 12 Dec 2023 19:05:53 +0200 Subject: [PATCH] Add support for second thermocouple --- src/main.cpp | 70 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index aca552a..fcc3cbf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,40 +1,50 @@ -#include -#include -#include #include +#include +#include +#include -#define CS D8 -Adafruit_MAX31855 thermocouple(CS); +#define CS_A D2 +#define CS_B D3 +Adafruit_MAX31855 thermocoupleA(CS_A); +Adafruit_MAX31855 thermocoupleB(CS_B); void setup() { - Serial.begin(9600); - while(!Serial) delay(1); - SPI.begin(); + Serial.begin(9600); + while (!Serial) delay(1); + SPI.begin(); - Serial.println("MAX31855 test"); - delay(500); - Serial.println("sensor init"); - if (!thermocouple.begin()) { - Serial.println("sensor init error"); - while(true) delay(10); - } - - Serial.println("init done"); + Serial.println("MAX31855 test"); + delay(500); + Serial.println("sensor init"); + if (!thermocoupleA.begin() | !thermocoupleB.begin()) { + Serial.println("sensor init error"); + while (true) delay(10); + } + Serial.println("init done"); } void loop() { - Serial.print(">internal:"); - Serial.println(thermocouple.readInternal()); + Serial.print(">internalA:"); + Serial.println(thermocoupleA.readInternal()); + Serial.print(">internalB:"); + Serial.println(thermocoupleB.readInternal()); - double c = thermocouple.readCelsius(); - if (isnan(c)) { - uint8_t e = thermocouple.readError(); - if (e & MAX31855_FAULT_OPEN) Serial.println("FAULT: thermocouple open"); - if (e & MAX31855_FAULT_SHORT_GND) Serial.println("FAULT: thermocouple short to GND"); - if (e & MAX31855_FAULT_SHORT_VCC) Serial.println("FAULT: thermocouple short to VCC"); - } else { - Serial.print(">tempc:"); - Serial.println(c); - } - delay(1000); + double cA = thermocoupleA.readCelsius(); + double cB = thermocoupleB.readCelsius(); + if (isnan(cA) | isnan(cB)) { + uint8_t eA = thermocoupleA.readError(); + uint8_t eB = thermocoupleB.readError(); + if (eA & MAX31855_FAULT_OPEN) Serial.println("FAULT: thermocouple A open"); + if (eA & MAX31855_FAULT_SHORT_GND) Serial.println("FAULT: thermocouple A short to GND"); + if (eA & MAX31855_FAULT_SHORT_VCC) Serial.println("FAULT: thermocouple A short to VCC"); + 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"); + 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); } \ No newline at end of file