There is more code in my program, but here is the parts I think are relevant.
// Thermocouple Sensor
#include <Adafruit_MAX31856.h>
// Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31856 max0 = Adafruit_MAX31856(10, 11, 12, 13);
// RTD Sensor
#include <Adafruit_MAX31865.h>
// Use software SPI: CS, DI, DO, CLK
//Adafruit_MAX31865 max1 = Adafruit_MAX31865(25, 51, 50, 52);
// Use hardware SPI, just pass in the CS pin
Adafruit_MAX31865 max1 = Adafruit_MAX31865(25);
// The value of the Rref resistor. Use 430.0!
#define RREF 430.0
const int RTDchipSelect = 25;
// LCD Display
#include <Wire.h>
#include <Adafruit_RGBLCDShield.h>
#include <utility/Adafruit_MCP23017.h>
// The shield uses the I2C SCL and SDA pins. SCL 21, SDA 20.
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
// Set the backlight color
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7
// ***************************************************************************************
// Setup Code
// ***************************************************************************************
void setup() {
// Set SPI CS pin for RTD
pinMode(RTDchipSelect, OUTPUT);
// Open serial communications and wait for port to open:
Serial.begin(9600);
// Wait for serial port only when programming and debuging code.
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Begin hardware setup.");
// Setup Thermocouple Sensor
max1.begin();
max0.setThermocoupleType(MAX31856_TCTYPE_T);
Serial.print("Thermocouple type: ");
switch ( max0.getThermocoupleType() ) {
case MAX31856_TCTYPE_B: Serial.println("B Type"); break;
case MAX31856_TCTYPE_E: Serial.println("E Type"); break;
case MAX31856_TCTYPE_J: Serial.println("J Type"); break;
case MAX31856_TCTYPE_K: Serial.println("K Type"); break;
case MAX31856_TCTYPE_N: Serial.println("N Type"); break;
case MAX31856_TCTYPE_R: Serial.println("R Type"); break;
case MAX31856_TCTYPE_S: Serial.println("S Type"); break;
case MAX31856_TCTYPE_T: Serial.println("T Type"); break;
case MAX31856_VMODE_G8: Serial.println("Voltage x8 Gain mode"); break;
case MAX31856_VMODE_G32: Serial.println("Voltage x8 Gain mode"); break;
default: Serial.println("Unknown"); break;
}
// Setup RTD Sensor
max1.begin(MAX31865_3WIRE); // set to 2WIRE or 4WIRE as necessary
Serial.println("RTD sensor.");
// Setup LCD Display
lcd.begin(16, 2);
Serial.println("LCD screen.");
}
There is other setup code for an SD card reader, keypad, digital pins for solnoids, etc.
void loop() {
//
// Wait For Start
//
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Press # to");
lcd.setCursor(0, 1);
lcd.print("begin test.");
char startKey = 0;
while (startKey != 35){
startKey = keypad.getKey();
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Starting...3");
Serial.println("Starting...");
delay(1000);
lcd.print("Starting...2");
delay(1000);
lcd.print("Starting...1");
delay(1000);
lcd.clear();
//
// Open Valves and Display Temps
//
digitalWrite(solenoidHot, LOW);
digitalWrite(solenoidCold, LOW);
double thermoTemp = 0;
double rtdTemp = 0;
lcd.setCursor(0, 0);
lcd.print("T Type: ");
lcd.setCursor(0, 1);
lcd.print("RTD: ");
startKey = 0;
while (startKey != 35){
startKey = keypad.getKey();
thermoTemp = max0.readThermocoupleTemperature();
rtdTemp = max1.temperature(100,RREF);
lcd.setCursor(8, 0);
lcd.print(thermoTemp);
lcd.setCursor(8, 1);
lcd.print(rtdTemp);
}
startKey = 0;
while (startKey != 42){
startKey = keypad.getKey();
}
Serial.println("Finished");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Finished");
delay(5000);
resetFunc(); //call reset
}
The only issue I have had so far with the adafruit thermocouple shield is to do with the max calling protocol (not sure how to phrase it) that was addressed in Adafruit Max31856 thermocouple amp and Max31865 RTD amp codes will not compile - Programming Questions - Arduino Forum which is why there is max0 and max1.