MAX 6675 - Live Reading Problem

Hello Everyone!

I’m using MAX 6675 module, with max6675 library.

I’ve uploaded the basic example, and it works fine:

// this example is public domain. enjoy!
// www.ladyada.net/learn/sensors/thermocouple

#include "max6675.h"

int thermoDO = 11;
int thermoCS = 12;
int thermoCLK = 13;

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);

  
void setup() {
  Serial.begin(9600);
  
  Serial.println("MAX6675 test");
  // wait for MAX chip to stabilize
  delay(500);
}

void loop() {
  // basic readout test, just print the current temp
  
   Serial.print("C = "); 
   Serial.println(thermocouple.readCelsius());
   Serial.print("F = ");
   Serial.println(thermocouple.readFahrenheit());
 
   delay(1000);
}

By “works fine” I mean the temperature is changing, and showing the changes on the Serial Monitor.

I’ve tried to implement it in my code:

while (PS == 1){
    if (check == 2) {
      Serial.println("Pedal Was Pressed. Now awaiting START command.");
      check++;
    }
    PedalState = digitalRead(Pedal);
    if (PedalState == 0) PS = 0;
    digitalWrite(Pneumatics, HIGH);
    MeasuredTemp = thermocouple.readCelsius();
    SendMesuredTempToDisplay(MeasuredTemp);
    Serial.print("1. Temp is ");
    Serial.println(MeasuredTemp);
    StartState = digitalRead(Start);
    if (StartState == 1) StS = 1;
    delay(1);
    while (StS == 1){
      delay(1000);
      if (check == 3) {
        Serial.println("Start Button was pressed.");
        check++;
      }
      HeatingProccess();    
      CoolingProccess();
      if (check == 11){
        Serial.println("Done with heating and cooling, exiting 'if' command");
        check++;
      }
    }
    if (StartState == 0){
      PedalState = digitalRead(Pedal);
      delay(1);
    }
  }

Heating Proccess (another place that the values of thermocouple is being read):

void HeatingProccess(){
  Serial.println("Heating Started");
  while (MeasuredTemp <= HeatingTemp){
    digitalWrite(Heating, HIGH);
    MeasuredTemp = thermocouple.readCelsius();
    SendMesuredTempToDisplay(MeasuredTemp);
    Serial.print("2. Temp is ");
    Serial.println(MeasuredTemp);
    if (check == 4) {
      Serial.print("Heating to heat temperature ");
      Serial.print(HeatingTemp);
      Serial.print("\n");
      check++;
    }
    //Serial.println(MeasuredTemp);
  }

  if (check == 5) {
    Serial.print("Heat done. Now maintaining temp for ");
    Serial.print(HeatingTime);
    Serial.print(" msecs.");
    Serial.print("\n");
    check++;
  }
  
  StartTime = millis();
  EndTime = StartTime + HeatingTime;
  while ((EndTime - StartTime) <= HeatingTime){

    if (check == 6){
      Serial.println("Started Counting time");
      Serial.println("Start Time: ");
      Serial.print(StartTime);
      Serial.print("\n");
      check++;
    }
    
    MeasuredTemp = thermocouple.readCelsius();
    SendMesuredTempToDisplay(MeasuredTemp);
    temp_check[0] = MeasuredTemp;
    delay(50);
    MeasuredTemp = thermocouple.readCelsius();
    temp_check[1] = MeasuredTemp;
    if ((temp_check[1]-temp_check[0])>0) index=1;
    else if ((temp_check[1]-temp_check[0])<0) index=-1;
    
    if (MeasuredTemp <= HeatingTemp+HeatingTemp*Err) {
      digitalWrite(Heating, HIGH);
      Serial.println("if_1");
      Serial.println(Err);
    }
    else if (MeasuredTemp > HeatingTemp-HeatingTemp*Err) {
      digitalWrite(Heating, LOW);
      Serial.println("if_2");
      Serial.println(Err);
    }
    else if ((index == 1) && (MeasuredTemp > (HeatingTemp-HeatingTemp*Err)) && (MeasuredTemp < (HeatingTemp+HeatingTemp*Err))) {
      digitalWrite(Heating, HIGH);
      Serial.println("if_3");
    }
    else if ((index == -1) && (MeasuredTemp > (HeatingTemp-HeatingTemp*Err)) && (MeasuredTemp < (HeatingTemp+HeatingTemp*Err))) {
      digitalWrite(Heating, LOW); 
      Serial.println("if_4");
    }
    else Serial.println("Failed to determine if temp is rising or falling");
    
    EndTime = millis();
  }
  digitalWrite(Heating, LOW);
  if (check == 7){
    Serial.println("Heating Done by time. End time: ");
    Serial.print(EndTime);
    Serial.print("\n");
    check++;
  }
}

The Problem I’m having is as follows:

The program starts fine, then when I step into the posted “while” loop, the thermocouple reading shows a temperature, however - it does not change when I apply heat to the thermocouple.

When the program steps into the “HeatingProccess” function, the thermocouple reading changes (as if it did read the sensor properly), but again - the value does not update live.

I’m guessing its some kind of logical problem, but can’t seem to figure it out.

Any help would be greatly appreciated :slight_smile:

OK, so I figured it out, if anybody has the same problem in the future:

The MAX6675 module can read values every 170-220 ms, so between 2 readings there should be a delay, of 220 ms.