I am trying to read 2x temperature sensors at the same time. In my test setup I have a PT100 connected on CH0 and a K type thermocouple connected on CH1.
When following the example RTD and Thermocouple examples they work fine and I can read both temperature sensors no problem. So I tried to combine both sketches to read both sensors at the same time. I can read the PT100 after it is initialised but as soon as I call initThermocouple() the PT100 no longer reads, instead giving a "RTD Low Threshold" error. The Thermocouple reads fine after it is initialised.
I have created the following script which demonstrates the problem.
/*
Machine Control - Simultaneous PT100 and Thermocouple Sensors.
The circuit:
- Portenta H7
- Portenta Machine Control Carrier
- 3-wire RTD sensor connected to
TEMP PROBES CH0 on the PMC
- K Type thermocouple temperature sensor connected to
TEMP PROBES CH1 on the PMC
Adapted from:
https://github.com/arduino-libraries/Arduino_MachineControl/blob/master/examples/Temp_probes_Thermocouples/Temp_probes_Thermocouples.ino
https://github.com/arduino-libraries/Arduino_MachineControl/blob/master/examples/Temp_probes_RTD/Temp_probes_RTD.ino
*/
// The value of the Rref resistor. Use 400.0 for PT100 and 4000.0 for PT1000
#define RREF 400.0
// The 'nominal' 0-degrees-C resistance of the sensor (100.0 for PT100, 1000.0 for PT1000)
#define RNOMINAL 100.0
#include <Arduino_MachineControl.h>
using namespace machinecontrol;
bool plot = false;
bool delayTCInit = false;
unsigned long startSetup = millis();
void initPT100() {
// Initialize RTDs
temp_probes.rtd.begin(THREE_WIRE);
// Enable PT100 readings
temp_probes.enableRTD();
}
void initThermocouple() {
// Initialize Thermocouples
temp_probes.tc.begin();
// Enable Thermocouples
temp_probes.enableTC();
}
void readPT100(int channel) {
// Set Channel, has internal 150 ms delay
temp_probes.selectChannel(channel);
// Take channel measurement
uint16_t rtd = temp_probes.rtd.readRTD();
float ratio = rtd;
ratio /= 32768;
// Check and print any faults
uint8_t fault = temp_probes.rtd.readFault();
if (fault) {
if (plot == false) {
if (temp_probes.rtd.getHighThresholdFault(fault)) {
Serial.print("RTD: High Threshold ");
}
if (temp_probes.rtd.getLowThresholdFault(fault)) {
Serial.print("RTD: Low Threshold ");
}
if (temp_probes.rtd.getLowREFINFault(fault)) {
Serial.print("REFIN- > 0.85 x Bias ");
}
if (temp_probes.rtd.getHighREFINFault(fault)) {
Serial.print("REFIN- < 0.85 x Bias - FORCE- open ");
}
if (temp_probes.rtd.getLowRTDINFault(fault)) {
Serial.print("RTDIN- < 0.85 x Bias - FORCE- open ");
}
if (temp_probes.rtd.getVoltageFault(fault)) {
Serial.print("Under/Over voltage ");
}
}
temp_probes.rtd.clearFault();
} else {
if (plot == false) {
Serial.print("RTD: ");
}
Serial.print(temp_probes.rtd.readTemperature(RNOMINAL, RREF));
Serial.print(" ");
}
}
void readThermocouple(int channel) {
// Set Channel, has internal 150 ms delay
temp_probes.selectChannel(channel);
// Take channel measurement
float temp_ch1 = temp_probes.tc.readTemperature();
if (plot == false) {
Serial.print("KTC: ");
}
Serial.print(temp_ch1);
Serial.print(" ");
}
void setup() {
Serial.begin(115200);
while (!Serial) {
delay(100);
}
startSetup = millis();
initPT100();
Serial.println("Init: PT100");
}
void loop() {
delay(1000);
readPT100(0);
// Init and read Thermocouples after delay
if (millis() - startSetup > 10000) {
if (delayTCInit == false) {
// If this lines is commented out I can read the PT100
initThermocouple();
Serial.println();
Serial.println("Init: TC");
delayTCInit = true;
}
readThermocouple(1);
}
Serial.println();
}
For me, this outputs the following:
Init: PT100
RTD: 22.06
RTD: 22.03
RTD: 22.06
RTD: 22.06
RTD: 22.06
RTD: 22.06
RTD: 22.06
RTD: 22.06
Init: TC
KTC: nan
RTD: Low Threshold KTC: 27.39
RTD: Low Threshold KTC: 27.90
RTD: Low Threshold KTC: 27.14
RTD: Low Threshold KTC: 28.16
RTD: Low Threshold KTC: 28.41
RTD: Low Threshold KTC: 27.90
RTD: Low Threshold KTC: 28.16
RTD: Low Threshold KTC: 28.16
So clearly the board can read both sensors but how can I read them both at the same time?
The manual clearly says "Do not connect a thermocouple and a PT100 to the same channel" on page 13 but it does not say anything about not connecting a thermocouple and PT100 on different channels.
Any help would be greatly appreciated!