K Type Thermocouple on Portenta Machine Control returning NaN

Hi

I am developing a control system using the Portenta Machine Control but I have an issue reading thermocouples using the built-in MAX31855 chip.

I have connected a K-type, unshielded thermocouple across the TP0 and TN0 inputs and I have tried running the example Arduino_PortentaMachineControl/Temp_probes_Thermocouples.ino sketch, but the serial monitor returns "nan" for all three TC channels.

Modifying the code to read the internal reference voltage of the MAX31855, the serial monitor prints a temperature value which increases when I hold my finger on the chip, which implies that the chip is working and communicating with the Arduino.

The TC I am using is working on a dedicated thermocouple reader and I have tried another K-type with the same results.

A modified version of the example sketch is below.

TIA,
Tim


#include <Arduino_PortentaMachineControl.h>

void setup() {
  Serial.begin(9600);
  while (!Serial) {
      ;
  }
  // Initialize temperature probes
  MachineControl_TCTempProbe.begin();
  MachineControl_TCTempProbe.selectChannel(0);
}

void loop() {
  //Take CH0 measurement
  float temp = MachineControl_TCTempProbe.readTemperature();
  Serial.print("Temperature CH0: ");
  Serial.print(temp);
  Serial.println("°C");

  //Take ref measurement
  float ref = MachineControl_TCTempProbe.readReferenceTemperature();
  Serial.print("Temperature Ref: ");
  Serial.print(ref);
  Serial.println("°C");

  Serial.println();
  delay(500);
}

Hi! have u had any luck solving this issue?

Im currently facing this as well where the readReferenceTemperature function is working yet my readTemperature function is not working.

No, I still haven't found a solution. I'm thinking of switching the sensors to PT100 to see if that works.

have u tried using the adafruit max31855 library?

also make sure ur thermocouple is not grounded as the max31855k chip on the PMC does not support grounded thermocouple.

honestly i have tried every solution but it still doesn’t work :smiling_face_with_tear:

I tried the max31855 library but couldn't find the pin numbers for the H7 to make it work. I'm sure this would be a solution.

i tried using pin 10, 7, and 9 DO CS CLK respectively

output was:
internal temp=30
C=nan
F=nan
Error=1

but when i use pin 40, 36, and 38

output was:
internal temp=0
C=0
F=32
Error=0

not sure whats wrong as i cant get the temperature output

You may try using the deprecated Arduino_MachineControl library with its example code to get your thermocouple setup to work. I tried and it worked for me but the next issue would be how can we get the setup to work using the new Arduino_PortentaMachineControl library. I will try using V1.0.0 of the new library and see if that works. Hopefully someone from Arduino support can help on this.

Example code from old library:

#include <Arduino_MachineControl.h>

using namespace machinecontrol;

void setup() {
  Serial.begin(9600);
  // Initialize temperature probes
  temp_probes.tc.begin();
  Serial.println("Temperature probes initialization done");
  // Enables Thermocouples chip select
  temp_probes.enableTC();
  Serial.println("Thermocouples enabled");
}

void loop() {
  //Set CH0, has internal 150 ms delay
  temp_probes.selectChannel(0);
  //Take CH0 measurement
  float temp_ch0 = temp_probes.tc.readTemperature();
  Serial.print("Temperature CH0 [°C]: ");
  Serial.print(temp_ch0);
  Serial.println();

  //Set CH1, has internal 150 ms delay
  temp_probes.selectChannel(1);
  //Take CH1 measurement
  float temp_ch1 = temp_probes.tc.readTemperature();
  Serial.print("Temperature CH1 [°C]: ");
  Serial.print(temp_ch1);
  Serial.println();
 
  //Set CH2, has internal 150 ms delay
  temp_probes.selectChannel(2);
  //Take CH2 measurement
  float temp_ch2 = temp_probes.tc.readTemperature();
  Serial.print("Temperature CH2 [°C]: ");
  Serial.print(temp_ch2);
  Serial.println();

  Serial.println();
}

Edit: Using V1.0.0 with the library's example code also did not work for me.

Thanks for the suggestion xcal, I installed the latest version of the Arduino_MachineControl library and it works for me too!

Thankfully it means that my MAX31855 is working but it's annoying that the PortentaMachineControl library doesn't.

Hi,
had the exact same problem and the latest version of the old library also does the trick for me, thanks for the suggestion.
I am in contact with Arduino Support with this problem and made them aware of this forum entry when I found it, hopefully there will be a reply from Support soon. I would also prefer to use the new library instead of the old one, so a fix would be greatly appreciated.

1 Like

I just got a reply from Arduino support team and their response is that they’re aware of the issue most users face with the new library. A fix should be coming in the new release so for the time being, we should continue using the deprecated library to get our setup to work.

2 Likes

It is working fine here: Library version 1.0.1 and Portenta core 4.1.3.

Deprecated library works for me as well, not the new one.
Annoying that Arduinos own example code doesnt work :melting_face: