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 <Arduino.h>
#include <SPI.h>
#include <pinout.h>
#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);
while (!Serial) delay(1);
SPI.begin();
Serial.println("MAX31855 test");
delay(500);
Serial.println("sensor init");
if (!thermocouple.begin()) {
if (!thermocoupleA.begin() | !thermocoupleB.begin()) {
Serial.println("sensor init error");
while(true) delay(10);
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");
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(">tempc:");
Serial.println(c);
Serial.print(">tempcA:");
Serial.println(cA);
Serial.print(">tempcB:");
Serial.println(cB);
}
delay(1000);
}