Variable type conflict (?) using MAX6675_Thermocouple.h library and PID library

So I am writing a sketch to use an Arduino Mega 2560 as a PID controller. I have been looking at examples and have partial functionality in that this code would read and print three different thermocouple values from three different MAX6675 boards. I implemented that first per an Arduino example and it worked fine.

However when I added the PID library and functionality I started getting this error message:
exit status 1
cannot convert ‘Thermocouple*’ to ‘double’ in assignment

The line that is highlighted by the error is about 1/2 way through the code:
Input = thermocouple_A

Here is the code

/*
  Arduino Sketch for running a temperature controlled smoker.

  Reads three temperatures from three thermocouple boards based
  on the MAX6675 driver. Channel A will be used for the 
  temperature measurement of the smoker box. Channels B and C
  will be used to measure the meat temperatures.

  A MOSFET based power driver board is used to control the speed
  of a 12VDC fan that feeds oxygen into the firebox. By monitoring 
  thermocouple Channel A (smoker temperature) a PID control loop
  is used to vary the fan speed to a preselected set point. 
  Channels B and C are used to monitor the meat temperature only. 

  Thermocouple board library and thermocouple read code by Y. Salimov
  https://github.com/YuriiSalimov/MAX6675_Thermocouple
  Created by Yurii Salimov, May, 2019.
  Released into the public domain.
*/

//Loads the libraries needed to read the thermocouple boards and the PID functions
#include <Thermocouple.h>
#include <MAX6675_Thermocouple.h>
#include <AverageThermocouple.h>
#include <PID_v1.h>


// Create the thermocouple channels
Thermocouple * thermocouple_A = NULL;
Thermocouple * thermocouple_B = NULL;
Thermocouple * thermocouple_C = NULL;

// Define Channel A digital I/O pin numbers
#define SCK_PIN_A 3
#define CS_PIN_A  4
#define SO_PIN_A  5

//Define Channel B digital I/O pin numbers
#define SCK_PIN_B 7
#define CS_PIN_B  8
#define SO_PIN_B  9

//Define Channel C digital I/O pin numbers
#define SCK_PIN_C 11
#define CS_PIN_C  12
#define SO_PIN_C  13

//Define number of readings per measurement (averaging)
#define READINGS_NUMBER  10

//Define ndelay for each measurement (in ms)
#define DELAY_TIME  10

//Define the PID MOSFET Fan Driver Output Pin
#define OUTPUT_PIN 2

//Define PID Variables we'll be connecting to
double Setpoint, Input, Output;

//Define the aggressive and conservative Tuning Parameters
double aggKp=4, aggKi=0.2, aggKd=1;
double consKp=1, consKi=0.05, consKd=0.25;

//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, DIRECT);

// the setup function for the thermocouple boards runs once when you press reset or power the board
void setup() {
  Serial.begin(9600);

// Initialize the thermocouple variables
thermocouple_A = new AverageThermocouple( new MAX6675_Thermocouple(SCK_PIN_A, CS_PIN_A, SO_PIN_A),READINGS_NUMBER,DELAY_TIME );
thermocouple_B = new AverageThermocouple( new MAX6675_Thermocouple(SCK_PIN_B, CS_PIN_B, SO_PIN_B),READINGS_NUMBER,DELAY_TIME );
thermocouple_C = new AverageThermocouple( new MAX6675_Thermocouple(SCK_PIN_C, CS_PIN_C, SO_PIN_C),READINGS_NUMBER,DELAY_TIME );

//thermocouple = new AverageThermocouple(new MAX6675_Thermocouple(SCK_PIN, CS_PIN, SO_PIN),READINGS_NUMBER,DELAY_TIME);


//initialize the PID variables we're linked to
  Input = thermocouple_A
  Setpoint = 275;

//turn the PID on
myPID.SetMode(AUTOMATIC);

}//void setup

// the loop function runs over and over again forever
void loop() {
  // Reads temperatures
  double fahrenheit_A = thermocouple_A->readFahrenheit();
  double fahrenheit_B = thermocouple_B->readFahrenheit();
  double fahrenheit_C = thermocouple_C->readFahrenheit();

  // Output of temperature information. 
  // This information can be monitored in the Arduino App using the Serial Monitor tool. 
  // Output Temperature_A
  Serial.print("Temperature_A: ");
  Serial.print(fahrenheit_A);
  Serial.print(" F    ");
  // Output Temperature_B
  Serial.print("Temperature_B: ");
  Serial.print(fahrenheit_B);
  Serial.print(" F    ");
  // Output Temperature_C
  Serial.print("Temperature_C: ");
  Serial.print(fahrenheit_C);
  Serial.println(" F");

  // PID loop functions
  Input = thermocouple_A
  
  double gap = abs(Setpoint-Input); //distance away from setpoint
  
  if(gap<10)
  {  //we're close to setpoint, use conservative tuning parameters
    myPID.SetTunings(consKp, consKi, consKd);
  }
  else
  {
     //we're far from setpoint, use aggressive tuning parameters
     myPID.SetTunings(aggKp, aggKi, aggKd);
  }

  myPID.Compute();
  analogWrite(OUTPUT_PIN,Output);
   
  // This sets the delay for each loop iteration in milliseconds
delay(10000);  
}

There is some kind of conflict between the variable types for “Input” and “thermocouple_A” when I try to update “Input”. “Input” is the current temperature measurement for the temperature the PID function is controlling.

When the value returned by MAX6675_Thermocouple() is printed (and looked at on the serial monitor) it is a XXX.X number and indeed appears to be a double since everything works fine with thermocouple measurements and printing without the PID function.

The problem appears to be with the “Input” variable. However in my sketch, and in the example sketches, “Input” is set up as a double, so there should not be a type conflict? I do not get how to correct this.

thermocouple_B and thermocouple_C can be ignored since they are just printed. They are not used in the PID loop.

I forgot to mention that the temperature measurements are coming in as digital values from the thermocouple board (to digital inputs) and not as voltages.

“thermocouple_A” is an instance of your “AverageThermocouple” class and does not return anything.

this on the other hand compiles (changed “Input = thermocouple_A;” to “Input = fahrenheit_A;”):

/*
  Arduino Sketch for running a temperature controlled smoker.

  Reads three temperatures from three thermocouple boards based
  on the MAX6675 driver. Channel A will be used for the
  temperature measurement of the smoker box. Channels B and C
  will be used to measure the meat temperatures.

  A MOSFET based power driver board is used to control the speed
  of a 12VDC fan that feeds oxygen into the firebox. By monitoring
  thermocouple Channel A (smoker temperature) a PID control loop
  is used to vary the fan speed to a preselected set point.
  Channels B and C are used to monitor the meat temperature only.

  Thermocouple board library and thermocouple read code by Y. Salimov
  https://github.com/YuriiSalimov/MAX6675_Thermocouple
  Created by Yurii Salimov, May, 2019.
  Released into the public domain.
*/

//Loads the libraries needed to read the thermocouple boards and the PID functions
#include <Thermocouple.h>
#include <MAX6675_Thermocouple.h>
#include <AverageThermocouple.h>
#include <PID_v1.h>


// Create the thermocouple channels
Thermocouple * thermocouple_A = NULL;
Thermocouple * thermocouple_B = NULL;
Thermocouple * thermocouple_C = NULL;

// Define Channel A digital I/O pin numbers
#define SCK_PIN_A 3
#define CS_PIN_A  4
#define SO_PIN_A  5

//Define Channel B digital I/O pin numbers
#define SCK_PIN_B 7
#define CS_PIN_B  8
#define SO_PIN_B  9

//Define Channel C digital I/O pin numbers
#define SCK_PIN_C 11
#define CS_PIN_C  12
#define SO_PIN_C  13

//Define number of readings per measurement (averaging)
#define READINGS_NUMBER  10

//Define ndelay for each measurement (in ms)
#define DELAY_TIME  10

//Define the PID MOSFET Fan Driver Output Pin
#define OUTPUT_PIN 2

//Define PID Variables we'll be connecting to
double Setpoint, Input, Output;

//Define the aggressive and conservative Tuning Parameters
double aggKp = 4, aggKi = 0.2, aggKd = 1;
double consKp = 1, consKi = 0.05, consKd = 0.25;

//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, DIRECT);

// the setup function for the thermocouple boards runs once when you press reset or power the board
void setup() {
  Serial.begin(9600);

  // Initialize the thermocouple variables
  thermocouple_A = new AverageThermocouple( new MAX6675_Thermocouple(SCK_PIN_A, CS_PIN_A, SO_PIN_A), READINGS_NUMBER, DELAY_TIME );
  thermocouple_B = new AverageThermocouple( new MAX6675_Thermocouple(SCK_PIN_B, CS_PIN_B, SO_PIN_B), READINGS_NUMBER, DELAY_TIME );
  thermocouple_C = new AverageThermocouple( new MAX6675_Thermocouple(SCK_PIN_C, CS_PIN_C, SO_PIN_C), READINGS_NUMBER, DELAY_TIME );

  //thermocouple = new AverageThermocouple(new MAX6675_Thermocouple(SCK_PIN, CS_PIN, SO_PIN),READINGS_NUMBER,DELAY_TIME);


  //initialize the PID variables we're linked to
  Setpoint = 275;

  //turn the PID on
  myPID.SetMode(AUTOMATIC);

}//void setup

// the loop function runs over and over again forever
void loop() {
  // Reads temperatures
  double fahrenheit_A = thermocouple_A->readFahrenheit();
  double fahrenheit_B = thermocouple_B->readFahrenheit();
  double fahrenheit_C = thermocouple_C->readFahrenheit();

  // Output of temperature information.
  // This information can be monitored in the Arduino App using the Serial Monitor tool.
  // Output Temperature_A
  Serial.print("Temperature_A: ");
  Serial.print(fahrenheit_A);
  Serial.print(" F    ");
  // Output Temperature_B
  Serial.print("Temperature_B: ");
  Serial.print(fahrenheit_B);
  Serial.print(" F    ");
  // Output Temperature_C
  Serial.print("Temperature_C: ");
  Serial.print(fahrenheit_C);
  Serial.println(" F");

  // PID loop functions
  Input = fahrenheit_A;

  double gap = abs(Setpoint - Input); //distance away from setpoint

  if (gap < 10)
  { //we're close to setpoint, use conservative tuning parameters
    myPID.SetTunings(consKp, consKi, consKd);
  }
  else
  {
    //we're far from setpoint, use aggressive tuning parameters
    myPID.SetTunings(aggKp, aggKi, aggKd);
  }

  myPID.Compute();
  analogWrite(OUTPUT_PIN, Output);

  // This sets the delay for each loop iteration in milliseconds
  delay(10000);
}

Hi, Can you post a link to the libraries you are using please?

When the IDE gives you an error, the line concerned is usually highlighted to show you its position.

Thanks.. Tom.. :)

Thanks Sherzaad that was the issue. I made that change and it compiles now.

Here is my final code. For those that want to use this for a smoker controller keep in mind that this is just the sketch and that I have not yet tuned the PID parameters. However they would need to be tuned for your particular smoker anyway.

/*
  Arduino Sketch for running a temperature controlled smoker.

  Reads three temperatures from three thermocouple boards based
  on the MAX6675 driver. Channel A will be used for the
  temperature measurement of the smoker box. Channels B and C
  will be used to measure the meat temperatures.

  A MOSFET based power driver board is used to control the speed
  of a 12VDC fan that feeds oxygen into the firebox. By monitoring
  thermocouple Channel A (smoker temperature) a PID control loop
  is used to vary the fan speed to a preselected set point.
  Channels B and C are used to monitor the meat temperature only.

  Thermocouple board library and thermocouple read code by Y. Salimov
  https://github.com/YuriiSalimov/MAX6675_Thermocouple
  Created by Yurii Salimov, May, 2019.
  Released into the public domain.
*/

//Loads the libraries needed to read the thermocouple boards and the PID functions
#include <PID_v1.h>
#include <Thermocouple.h>
#include <MAX6675_Thermocouple.h>
#include <AverageThermocouple.h>

// Create the thermocouple channels
Thermocouple * thermocouple_A = 0;
Thermocouple * thermocouple_B = 0;
Thermocouple * thermocouple_C = 0;

// Define Channel A digital I/O pin numbers
const double SCK_PIN_A = 3;
const double CS_PIN_A = 4;
const double SO_PIN_A = 5;

//Define Channel B digital I/O pin numbers
const double SCK_PIN_B = 7;
const double CS_PIN_B  = 8;
const double SO_PIN_B  = 9;

//Define Channel C digital I/O pin numbers
const double SCK_PIN_C = 11;
const double CS_PIN_C  = 12;
const double SO_PIN_C  = 13;

//Define PID Setpoint
const double Setpoint = 250;

//Define PID number of readings per measurement (averaging)
const double READINGS_NUMBER = 10;

//Define ndelay for each measurement (in ms)
const double DELAY_TIME = 10;

//Define the PID MOSFET Fan Driver Output Pin
const double FAN_PIN = 2;

//Define the aggressive and conservative Tuning Parameters
const double aggKp = 4, aggKi = 0.2, aggKd = 1;
const double consKp = 1, consKi = 0.05, consKd = 0.25;

//Define the PID inputs and outputs
double Input, Output;

//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, DIRECT);

// the setup function for the thermocouple boards runs once when you press reset or power the board
void setup() {
  Serial.begin(9600);

  // Initialize the thermocouple variables
  thermocouple_A = new AverageThermocouple(new MAX6675_Thermocouple(SCK_PIN_A, CS_PIN_A, SO_PIN_A), READINGS_NUMBER, DELAY_TIME );
  thermocouple_B = new AverageThermocouple( new MAX6675_Thermocouple(SCK_PIN_B, CS_PIN_B, SO_PIN_B), READINGS_NUMBER, DELAY_TIME );
  thermocouple_C = new AverageThermocouple( new MAX6675_Thermocouple(SCK_PIN_C, CS_PIN_C, SO_PIN_C), READINGS_NUMBER, DELAY_TIME );

  //turn the PID on
  myPID.SetMode(AUTOMATIC);

}//void setup

// the loop function runs over and over again forever
void loop() {
  
  //Read thermocouple temperatures
  double fahrenheit_A = thermocouple_A->readFahrenheit();
  double fahrenheit_B = thermocouple_B->readFahrenheit();
  double fahrenheit_C = thermocouple_C->readFahrenheit();
  Input = thermocouple_A->readFahrenheit();

  // Output of temperature information.
  // This information can be monitored in the Arduino App using the Serial Monitor tool.
  // Output Temperature_A
  Serial.print("Temperature_A: ");
  Serial.print(fahrenheit_A);
  Serial.print(" F    ");
  // Output Temperature_B
  Serial.print("Temperature_B: ");
  Serial.print(fahrenheit_B);
  Serial.print(" F    ");
  // Output Temperature_C
  Serial.print("Temperature_C: ");
  Serial.print(fahrenheit_C);
  Serial.println(" F");

  double gap = abs(Setpoint - Input); //distance away from setpoint

  if (gap < 10)
  { //we're close to setpoint, use conservative tuning parameters
    myPID.SetTunings(consKp, consKi, consKd);
  }
  else
  {
    //we're far from setpoint, use aggressive tuning parameters
    myPID.SetTunings(aggKp, aggKi, aggKd);
  }

  myPID.Compute();
  analogWrite(FAN_PIN, Output);

  // This sets the delay for each loop iteration in milliseconds
  delay(10000);
}

Hi, Thanks for posting your final working code, it helps to finalise the thread and as you say , help anyone using the same libraries. I have given you a Karma, looks like you read the "how to" stickies before starting your post.

Tom... :)

Yep I did read the stickies and checked my first post to see if I had included what what expected. I appreciate the help so the least I can do is ask the question properly :)

FYI I have loaded the above code onto a MAX 2560 board and it runs correctly.