max31855 question calibration not seeing it.

Status
Not open for further replies.

Bastiaan

Well-known member
Dear Guys/Girls,

Currently I am working with 4 Thermocouple sensors MAX31855 and I am using
https://blog.heypete.com/wp-content/uploads/2016/09/MAX31855-Linearized-Thermocouple-Temperature.pdf correction:

second all thermocouples are put into a cold glass of water 25.0C° i am also using a CL3512A Thermocouple K and a keithley 2700 multimeter set on Thermocuple K

Cl3512A gives me= 25.0C°
2700 gives me= 25.40C°
Serialmonitor with 4 max31855 gives me.

anybody see what I am doing wrong? like a double declaration?

second question how can I reduce the code so that I call 4 separate functions like something = Thermocouple[4](); and run it through a for loop...

many thanks for looking into this.



Code:
Int Temp 14=28.69Corr Value 28.25

Int Temp15=28.69Hot Corr Value 28.02

Int Temp16=29.13Hot Corr Value 32.17

Int Temp17=29.56Hot Corr Value 37.15



Code:
/***************************************************
  
#include <SPI.h>
#include "Adafruit_MAX31855.h"


// Example creating a TH1 instance with software SPI on any three
// digital IO pins.
#define MAXDO   9
#define MAXCLK  13

// initialize the TH1
SPISettings SettingsA(14000000,MSBFIRST,SPI_MODE1);


Adafruit_MAX31855 TH1(MAXCLK, 14, MAXDO);
Adafruit_MAX31855 TH2(MAXCLK, 15, MAXDO);
Adafruit_MAX31855 TH3(MAXCLK, 16, MAXDO);
Adafruit_MAX31855 TH4(MAXCLK, 17, MAXDO);

[COLOR="#B22222"]double CorrectionfromCasing=4;[/COLOR]


void setup() {
 
  SPI.begin();
  Serial.begin(9600);
      delay(500);
  SPI.beginTransaction(SettingsA);
  digitalWrite(14,LOW);
  while (!Serial) delay(1); // wait for Serial on Leonardo/Zero, etc
  // wait for MAX chip to stabilize

  Serial.print("Initializing sensor...");
  if (!TH1.begin()) {
    Serial.println("ERROR.");
    while (1) delay(10);
  }
  Serial.println("DONE.");
  digitalWrite(14,HIGH);


SPI.endTransaction();

  SPI.beginTransaction(SettingsA);
   digitalWrite(15,LOW);
         delay(500);
  while (!Serial) delay(1); // wait for Serial on Leonardo/Zero, etc
  // wait for MAX chip to stabilize

  Serial.print("Initializing sensor...");
  if (!TH2.begin()) {
    Serial.println("ERROR.");
    while (1) delay(10);
  }
  Serial.println("DONE.");
  digitalWrite(15,HIGH);


SPI.endTransaction();
 
  SPI.beginTransaction(SettingsA);
  digitalWrite(16,LOW);
        delay(500);
  while (!Serial) delay(1); // wait for Serial on Leonardo/Zero, etc
  // wait for MAX chip to stabilize
  Serial.print("Initializing sensor...");
  if (!TH3.begin()) {
    Serial.println("ERROR.");
    while (1) delay(10);
  }
  Serial.println("DONE.");
  digitalWrite(16,HIGH);


SPI.endTransaction();
  SPI.beginTransaction(SettingsA);
   digitalWrite(17,LOW);
         delay(500);
  while (!Serial) delay(1); // wait for Serial on Leonardo/Zero, etc
  // wait for MAX chip to stabilize

  Serial.print("Initializing sensor...");
  if (!TH4.begin()) {
    Serial.println("ERROR.");
    while (1) delay(10);
  }
  Serial.println("DONE.");
  digitalWrite(17,HIGH);


SPI.endTransaction();
  
}


void loop() 
{ 
  
  Thermocouple1();
  Thermocouple2();
  Thermocouple3();
  Thermocouple4();
}




int Thermocouple1()
{
/*
 * five steps to calulate from a linear voltage to temperature to non linear max31855 which truely resembles the Temperature in 5 Steps
 * 1 substract the min temperature - internal temperature.
 * 
 * 2 multiply min temperature x this Thermocouple K voltage (check max31855 datasheet on ThermocoupleK voltage which is 0.041276mV/C)
 * 3 Calculate Cold Junction equivalent thermocouple voltage using the formula below with NIST
 *   ����=��0+��1∗��������+��2∗��������'^'2+��3∗��������'^'3+⋯+��0∗����1∗(��������−��2)'^'2
 * 4 add cold junction equiv calculated in step 3.  
 * 5 use the result of step 4 and the NIST voltage to tempeature (inverse) coefficients B0,B1,B2 to calculate the cold junction compensation, lineariszed value
 * ��������=��0+��1∗����+��2∗����2+��3∗����3+⋯
 * 0+(2.52∗101∗−3.528157)+(−1.17∗−3.5281572)+(−1.08∗−3.5281573)+⋯=−99.16
 */

   
   delay(1000);
   SPI.beginTransaction(SettingsA);
   digitalWrite(14,LOW);
   Serial.print("Int Temp ");
   Serial.print(14);
   Serial.print("=");
   Serial.print(TH1.readInternal());
  
   if(TH1.readCelsius()<0)//if temperature is lower than 0   ////Thermocouple 1
   {
   double intc1=TH1.readInternal();
   double c1 = TH1.readCelsius();
   double SubC1_int=c1-intc1;
   double SubCalc=SubC1_int*0.041276; /*mV*/
   double E1=(-0.176*pow(10,-1));
   double E2=(0.389*pow(10,-1)*pow(intc1,1));
   double E3=(0.186*pow(10,-4)*pow(intc1,2));
   double E4=(-0.995*pow(10,-7)*pow(intc1,3));
   double E5=(0.318*pow(10,-9)*pow(intc1,4));
   double E6=(-0.561*pow(10,-12)*pow(intc1,5));
   double E7=(0.561*pow(10,-15)*pow(intc1,6));
   double E8=(-0.320*pow(10,-18)*pow(intc1,7));
   double E9=(0.972*pow(10,-22)*pow(intc1,8));
   double E10=(-0.121*pow(10,-25)*pow(intc1,9));
   double E11=(0.119*pow(exp(-0.118*pow(10,-3)*(intc1-0.127*pow(10,3))),2));
   double E1_11=E1+E2+E3+E4+E5+E6+E7+E8+E9+E10+E11;
   double AddCJError=E1_11+SubCalc;
   double R1=0+(2.51734*pow(AddCJError,1));
   double R2=(-1.17*pow(AddCJError,2));
   double R3=(-1.08*pow(AddCJError,3));
   double R4=(-8.977*pow(10,-1)*pow(AddCJError,4));
   double R5=(-3.73*10*pow(10,-1)*pow(AddCJError,5));
   double R6=(-8.6632*pow(10,-2)*pow(AddCJError,6));
   double R7=(-1.045*pow(10,-2)*pow(AddCJError,7));
   double R8=(-5.1920577*pow(10,-4)*pow(AddCJError,8));
   double R9=0*pow(AddCJError,9);
   double R1_9=R1+R2+R3+R4+R5+R6+R7+R8+R9;
   Serial.print("Cold ");
   Serial.print("Corr Value ");
   Serial.println(R1_9/100000000);
   
   if (isnan(c1)) {
     Serial.print("Something wrong with Thermocouple ");

   } 
   else {
     Serial.print("C = ");
     Serial.println(c1);
   }
   }
   else //this is the 0...1270°
   {
   
   double intc1=TH1.readInternal();
   double c1 = TH1.readCelsius();
   double SubC1_int=c1-intc1;
   double SubCalc=SubC1_int*0.041276; /*mV*/
   double H1=(-0.17600413686*pow(10,-1));
   double H2=(0.389212049750*pow(intc1,1));
   double H3=(0.185587700320*pow(10,-4)*pow(intc1,2));
   double H4=(-0.99457592874*pow(10,-7)*pow(intc1,3));
   double H5=(0.318409457190*pow(10,-9)*pow(intc1,4));
   double H6=(-0.56072844889*pow(10,-12)*pow(intc1,5));
   double H7=(0.560750590590*pow(10,-15)*pow(intc1,6));
   double H8=(-0.320200720003*pow(10,-18)*pow(intc1,7));
   double H9=(0.971511471520*pow(10,-22)*pow(intc1,8));
   double H10=(-0.121047212750*pow(10,-25)*pow(intc1,9));
   double H11=(0.119*pow(exp(-0.118*pow(10,-3)*(intc1-0.127*pow(10,3))),2));
   double H1_11=H1+H2+H3+H4+H5*H6+H7+H8+H9+H10+H11;
   double AddCJError=H1_11+SubCalc;
   double E1=(-1.318058*pow(10,2)*pow(AddCJError,0));
   double E2=(4.830222*pow(10,1)*pow(AddCJError,1));
   double E3=(-1.64603*pow(10,0)*pow(AddCJError,2));
   double E4=(5.46473*pow(10,-2)*pow(AddCJError,3));
   double E5=(-9.65071*pow(10,-4)*pow(AddCJError,4));
   double E6=(8.802193*10*pow(10,-6)*pow(AddCJError,5));
   double E7=(-3.11081*pow(10,-8)*pow(AddCJError,6));
   double E8=(0*pow(10,0)*pow(AddCJError,7));
   double E9=(0*pow(10,0)*pow(AddCJError,8));
   double E10=(0*pow(10,0)+pow(AddCJError,9));
   double E1_9=E1+E2+E3+E4+E5+E6+E7+E8+E9+E10;
   double CorVal=(E1_9/100000000);
   Serial.print("Corr Value ");
   Serial.println(CorVal);
   }                               
   //Serial.print("F = ");
   //Serial.println(TH1.readFahrenheit());
   digitalWrite(14,HIGH);
   SPI.endTransaction();//----------------------------------------------------------------------------------
   
   

 

  

}




int Thermocouple2()
{
    SPI.beginTransaction(SettingsA);                               ////Thermocouple 2
   
    digitalWrite(15,LOW);

   Serial.print("Int Temp");
   Serial.print(15);
   Serial.print("=");
   Serial.print(TH2.readInternal());

   if(TH2.readCelsius()<0)//if temperature is lower than 0
   {
   double intc1=TH2.readInternal();
   double c1 = TH2.readCelsius();
   double SubC1_int=c1-intc1;
   double SubCalc=SubC1_int*0.041276; /*mV*/
   double E1=(-0.176*pow(10,-1));
   double E2=(0.389*pow(10,-1)*pow(intc1,1));
   double E3=(0.186*pow(10,-4)*pow(intc1,2));
   double E4=(-0.995*pow(10,-7)*pow(intc1,3));
   double E5=(0.318*pow(10,-9)*pow(intc1,4));
   double E6=(-0.561*pow(10,-12)*pow(intc1,5));
   double E7=(0.561*pow(10,-15)*pow(intc1,6));
   double E8=(-0.320*pow(10,-18)*pow(intc1,7));
   double E9=(0.972*pow(10,-22)*pow(intc1,8));
   double E10=(-0.121*pow(10,-25)*pow(intc1,9));
   double E11=(0.119*pow(exp(-0.118*pow(10,-3)*(intc1-0.127*pow(10,3))),2));
   double E1_11=E1+E2+E3+E4+E5+E6+E7+E8+E9+E10+E11;
   double AddCJError=E1_11+SubCalc;
   double R1=0+(2.51734*pow(AddCJError,1));
   double R2=(-1.17*pow(AddCJError,2));
   double R3=(-1.08*pow(AddCJError,3));
   double R4=(-8.977*pow(10,-1)*pow(AddCJError,4));
   double R5=(-3.73*10*pow(10,-1)*pow(AddCJError,5));
   double R6=(-8.6632*pow(10,-2)*pow(AddCJError,6));
   double R7=(-1.045*pow(10,-2)*pow(AddCJError,7));
   double R8=(-5.1920577*pow(10,-4)*pow(AddCJError,8));
   double R9=0*pow(AddCJError,9);
   double R1_9=R1+R2+R3+R4+R5+R6+R7+R8+R9;
   Serial.print("Cold ");
   Serial.print("Corr Value ");
   Serial.println(R1_9/100000000);
   
   if (isnan(c1)) {
     Serial.print("Something wrong with Thermocouple ");

   } 
   else {
     Serial.print("C = ");
     Serial.println(c1);
   }
   }
   else //this is the 0...1270°
   {
   
   double intc1=TH2.readInternal();
   double c1 = TH2.readCelsius();
   double SubC1_int=c1-intc1;
   double SubCalc=SubC1_int*0.041276; /*mV*/
   double H1=(-0.17600413686*pow(10,-1));
   double H2=(0.389212049750*pow(intc1,1));
   double H3=(0.185587700320*pow(10,-4)*pow(intc1,2));
   double H4=(-0.99457592874*pow(10,-7)*pow(intc1,3));
   double H5=(0.318409457190*pow(10,-9)*pow(intc1,4));
   double H6=(-0.56072844889*pow(10,-12)*pow(intc1,5));
   double H7=(0.560750590590*pow(10,-15)*pow(intc1,6));
   double H8=(-0.320200720003*pow(10,-18)*pow(intc1,7));
   double H9=(0.971511471520*pow(10,-22)*pow(intc1,8));
   double H10=(-0.121047212750*pow(10,-25)*pow(intc1,9));
   double H11=(0.119*pow(exp(-0.118*pow(10,-3)*(intc1-0.127*pow(10,3))),2));
   double H1_11=H1+H2+H3+H4+H5*H6+H7+H8+H9+H10+H11;
   double AddCJError=H1_11+SubCalc;
   double E1=(-1.318058*pow(10,2)*pow(AddCJError,0));
   double E2=(4.830222*pow(10,1)*pow(AddCJError,1));
   double E3=(-1.64603*pow(10,0)*pow(AddCJError,2));
   double E4=(5.46473*pow(10,-2)*pow(AddCJError,3));
   double E5=(-9.65071*pow(10,-4)*pow(AddCJError,4));
   double E6=(8.802193*10*pow(10,-6)*pow(AddCJError,5));
   double E7=(-3.11081*pow(10,-8)*pow(AddCJError,6));
   double E8=(0*pow(10,0)*pow(AddCJError,7));
   double E9=(0*pow(10,0)*pow(AddCJError,8));
   double E10=(0*pow(10,0)+pow(AddCJError,9));
   double E1_9=E1+E2+E3+E4+E5+E6+E7+E8+E9+E10;
   double CorVal=(E1_9/100000000);
   
   Serial.print("Hot ");
   Serial.print("Corr Value ");
   Serial.println(CorVal);
   }                               
   digitalWrite(15,HIGH);
   SPI.endTransaction();//----------------------------------------------------------------------------------
  
}

int Thermocouple3()
{
  SPI.beginTransaction(SettingsA);
   
    digitalWrite(16,LOW);

   Serial.print("Int Temp");
   Serial.print(16);
   Serial.print("=");
   Serial.print(TH3.readInternal());

  if(TH3.readCelsius()<0)//if temperature is lower than 0
   {
   double intc1=TH3.readInternal();
   double c1 = TH3.readCelsius();
   double SubC1_int=c1-intc1;
   double SubCalc=SubC1_int*0.041276; /*mV*/
   double E1=(-0.176*pow(10,-1));
   double E2=(0.389*pow(10,-1)*pow(intc1,1));
   double E3=(0.186*pow(10,-4)*pow(intc1,2));
   double E4=(-0.995*pow(10,-7)*pow(intc1,3));
   double E5=(0.318*pow(10,-9)*pow(intc1,4));
   double E6=(-0.561*pow(10,-12)*pow(intc1,5));
   double E7=(0.561*pow(10,-15)*pow(intc1,6));
   double E8=(-0.320*pow(10,-18)*pow(intc1,7));
   double E9=(0.972*pow(10,-22)*pow(intc1,8));
   double E10=(-0.121*pow(10,-25)*pow(intc1,9));
   double E11=(0.119*pow(exp(-0.118*pow(10,-3)*(intc1-0.127*pow(10,3))),2));
   double E1_11=E1+E2+E3+E4+E5+E6+E7+E8+E9+E10+E11;
   double AddCJError=E1_11+SubCalc;
   double R1=0+(2.51734*pow(AddCJError,1));
   double R2=(-1.17*pow(AddCJError,2));
   double R3=(-1.08*pow(AddCJError,3));
   double R4=(-8.977*pow(10,-1)*pow(AddCJError,4));
   double R5=(-3.73*10*pow(10,-1)*pow(AddCJError,5));
   double R6=(-8.6632*pow(10,-2)*pow(AddCJError,6));
   double R7=(-1.045*pow(10,-2)*pow(AddCJError,7));
   double R8=(-5.1920577*pow(10,-4)*pow(AddCJError,8));
   double R9=0*pow(AddCJError,9);
   double R1_9=R1+R2+R3+R4+R5+R6+R7+R8+R9;
   Serial.print("Cold ");
   Serial.print("Corr Value ");
   Serial.println(R1_9/100000000);
   
   if (isnan(c1)) {
     Serial.print("Something wrong with Thermocouple ");

   } 
   else {
     Serial.print("C = ");
     Serial.println(c1);
   }
   }
   else //this is the 0...1270°
   {
   
   double intc1=TH3.readInternal();
   double c1 = TH3.readCelsius();
   double SubC1_int=c1-intc1;
   double SubCalc=SubC1_int*0.041276; /*mV*/
   double H1=(-0.17600413686*pow(10,-1));
   double H2=(0.389212049750*pow(intc1,1));
   double H3=(0.185587700320*pow(10,-4)*pow(intc1,2));
   double H4=(-0.99457592874*pow(10,-7)*pow(intc1,3));
   double H5=(0.318409457190*pow(10,-9)*pow(intc1,4));
   double H6=(-0.56072844889*pow(10,-12)*pow(intc1,5));
   double H7=(0.560750590590*pow(10,-15)*pow(intc1,6));
   double H8=(-0.320200720003*pow(10,-18)*pow(intc1,7));
   double H9=(0.971511471520*pow(10,-22)*pow(intc1,8));
   double H10=(-0.121047212750*pow(10,-25)*pow(intc1,9));
   double H11=(0.119*pow(exp(-0.118*pow(10,-3)*(intc1-0.127*pow(10,3))),2));
   double H1_11=H1+H2+H3+H4+H5*H6+H7+H8+H9+H10+H11;
   double AddCJError=H1_11+SubCalc;
   double E1=(-1.318058*pow(10,2)*pow(AddCJError,0));
   double E2=(4.830222*pow(10,1)*pow(AddCJError,1));
   double E3=(-1.64603*pow(10,0)*pow(AddCJError,2));
   double E4=(5.46473*pow(10,-2)*pow(AddCJError,3));
   double E5=(-9.65071*pow(10,-4)*pow(AddCJError,4));
   double E6=(8.802193*10*pow(10,-6)*pow(AddCJError,5));
   double E7=(-3.11081*pow(10,-8)*pow(AddCJError,6));
   double E8=(0*pow(10,0)*pow(AddCJError,7));
   double E9=(0*pow(10,0)*pow(AddCJError,8));
   double E10=(0*pow(10,0)+pow(AddCJError,9));
   double E1_9=E1+E2+E3+E4+E5+E6+E7+E8+E9+E10;
   double CorVal=(E1_9/100000000);
   Serial.print("Hot ");
   Serial.print("Corr Value ");
   Serial.println(CorVal);
   }                               
   digitalWrite(16,HIGH);
  SPI.endTransaction();//----------------------------------------------------------------------------------
 
}



int Thermocouple4()
{
   SPI.beginTransaction(SettingsA);
   
    digitalWrite(17,LOW);

   Serial.print("Int Temp");
   Serial.print(17);
   Serial.print("=");
   Serial.print(TH4.readInternal());

  if(TH4.readCelsius()<0)//if temperature is lower than 0
   {
   double intc1=TH4.readInternal();
   double c1 = TH4.readCelsius();
   double SubC1_int=c1-intc1;
   double SubCalc=SubC1_int*0.041276; /*mV*/
   double E1=(-0.176*pow(10,-1));
   double E2=(0.389*pow(10,-1)*pow(intc1,1));
   double E3=(0.186*pow(10,-4)*pow(intc1,2));
   double E4=(-0.995*pow(10,-7)*pow(intc1,3));
   double E5=(0.318*pow(10,-9)*pow(intc1,4));
   double E6=(-0.561*pow(10,-12)*pow(intc1,5));
   double E7=(0.561*pow(10,-15)*pow(intc1,6));
   double E8=(-0.320*pow(10,-18)*pow(intc1,7));
   double E9=(0.972*pow(10,-22)*pow(intc1,8));
   double E10=(-0.121*pow(10,-25)*pow(intc1,9));
   double E11=(0.119*pow(exp(-0.118*pow(10,-3)*(intc1-0.127*pow(10,3))),2));
   double E1_11=E1+E2+E3+E4+E5+E6+E7+E8+E9+E10+E11;
   double AddCJError=E1_11+SubCalc;
   double R1=0+(2.51734*pow(AddCJError,1));
   double R2=(-1.17*pow(AddCJError,2));
   double R3=(-1.08*pow(AddCJError,3));
   double R4=(-8.977*pow(10,-1)*pow(AddCJError,4));
   double R5=(-3.73*10*pow(10,-1)*pow(AddCJError,5));
   double R6=(-8.6632*pow(10,-2)*pow(AddCJError,6));
   double R7=(-1.045*pow(10,-2)*pow(AddCJError,7));
   double R8=(-5.1920577*pow(10,-4)*pow(AddCJError,8));
   double R9=0*pow(AddCJError,9);
   double R1_9=R1+R2+R3+R4+R5+R6+R7+R8+R9;
   Serial.print("Cold ");
   Serial.print("Corr Value ");
   Serial.println(R1_9/100000000);
   
   if (isnan(c1)) {
     Serial.print("Something wrong with Thermocouple ");

   } 
   else {
     Serial.print("C = ");
     Serial.println(c1);
   }
   }
   else //this is the 0...1270°
   {
   
   double intc1=TH4.readInternal();
   double c1 = TH4.readCelsius();
   double SubC1_int=c1-intc1;
   double SubCalc=SubC1_int*0.041276; /*mV*/
   double H1=(-0.17600413686*pow(10,-1));
   double H2=(0.389212049750*pow(intc1,1));
   double H3=(0.185587700320*pow(10,-4)*pow(intc1,2));
   double H4=(-0.99457592874*pow(10,-7)*pow(intc1,3));
   double H5=(0.318409457190*pow(10,-9)*pow(intc1,4));
   double H6=(-0.56072844889*pow(10,-12)*pow(intc1,5));
   double H7=(0.560750590590*pow(10,-15)*pow(intc1,6));
   double H8=(-0.320200720003*pow(10,-18)*pow(intc1,7));
   double H9=(0.971511471520*pow(10,-22)*pow(intc1,8));
   double H10=(-0.121047212750*pow(10,-25)*pow(intc1,9));
   double H11=(0.119*pow(exp(-0.118*pow(10,-3)*(intc1-0.127*pow(10,3))),2));
   double H1_11=H1+H2+H3+H4+H5*H6+H7+H8+H9+H10+H11;
   double AddCJError=H1_11+SubCalc;
   double E1=(-1.318058*pow(10,2)*pow(AddCJError,0));
   double E2=(4.830222*pow(10,1)*pow(AddCJError,1));
   double E3=(-1.64603*pow(10,0)*pow(AddCJError,2));
   double E4=(5.46473*pow(10,-2)*pow(AddCJError,3));
   double E5=(-9.65071*pow(10,-4)*pow(AddCJError,4));
   double E6=(8.802193*10*pow(10,-6)*pow(AddCJError,5));
   double E7=(-3.11081*pow(10,-8)*pow(AddCJError,6));
   double E8=(0*pow(10,0)*pow(AddCJError,7));
   double E9=(0*pow(10,0)*pow(AddCJError,8));
   double E10=(0*pow(10,0)+pow(AddCJError,9));
   double E1_9=E1+E2+E3+E4+E5+E6+E7+E8+E9+E10;
   double CorVal=(E1_9/100000000);
   Serial.print("Hot ");
   Serial.print("Corr Value ");
   Serial.println(CorVal);
   }                               
   digitalWrite(17,HIGH);
  SPI.endTransaction();//----------------------------------------------------------------------------------

}
 

Attachments

  • 67A87F0F-CC2E-4EA4-B6B9-A59E8C03268A.jpeg
    67A87F0F-CC2E-4EA4-B6B9-A59E8C03268A.jpeg
    128.1 KB · Views: 49
Last edited:
Code:
Adafruit_MAX31855 * all_sensors = { &TH1, &TH2, &TH3, &TH4 } ;
Will give an array of pointers to the instance of the sensor class.
 
Hi MarkT,

I tried what you said:
Code:
Adafruit_MAX31855 TH1(MAXCLK, 14, MAXDO);
Adafruit_MAX31855 TH2(MAXCLK, 15, MAXDO);
Adafruit_MAX31855 TH3(MAXCLK, 16, MAXDO);
Adafruit_MAX31855 TH4(MAXCLK, 17, MAXDO);

Adafruit_MAX31855 *all_sensors[4] ={&TH1,&TH2,&TH3,&TH4};
I guess thats more correct because I have 4 thermocuples.


however in rewriting the code to one function that handles all 4 thermocuples:
Code:
Serial.print(all_sensors[i].readInternal());

I tried to forloop the all_sensors.readInternal(); 4 times. however I get

153: error: expected primary-expression before '->' token

request for member 'readCelsius' in 'all_sensors[4]', which is of pointer type 'Adafruit_MAX31855*' (maybe you meant to use '->' ?)

if I implement the -> I get
'class Adafruit_MAX31855' has no member named 'TH1'
Serial.print(&all_sensors->TH1.readInternal());

or I tried and got from both occasions with pointer to readInternal and without

all_sensors.*readInternal()

I tried this to.

'readInternal' was not declared in this scope
Serial.print(all_sensors.*readInternal());



all_sensors->(readInternal())


do I require 2 pointers=?
 
Hi MarkT,

I tried what you said:
Code:
Adafruit_MAX31855 TH1(MAXCLK, 14, MAXDO);
Adafruit_MAX31855 TH2(MAXCLK, 15, MAXDO);
Adafruit_MAX31855 TH3(MAXCLK, 16, MAXDO);
Adafruit_MAX31855 TH4(MAXCLK, 17, MAXDO);

Adafruit_MAX31855 *all_sensors[] ={&TH1,&TH2,&TH3,&TH4};
I guess thats more correct because I have 4 thermocuples. why dont I have to define the array?


however in rewriting the code to one function that handles all 4 thermocuples:
Code:
Serial.print(all_sensors[i].readInternal());

I tried to for loop the
all_sensors->readInternal();


works like a charm:) thanks:)
 
Last edited:
I would like to do this also for the Void Setup() part:

the pins 14,15,16,17 are the CS Pins for each of the MAX31855.

Code:
SPI.begin();
  Serial.begin(9600);
  
  for(int i=0; i<4;i++)
  {
  SPI.beginTransaction(SettingsA);
  digitalWrite(i+14,LOW);
  while (!Serial) delay(1); // wait for Serial on Leonardo/Zero, etc
  // wait for MAX chip to stabilize
  delay(500);
  Serial.print("Initializing sensor...");
  if (all_sensors[i]->begin()) {
    Serial.println("ERROR.");
    while (1) delay(10);
  }
  Serial.println("DONE.");
  digitalWrite(i+14,HIGH);
  SPI.endTransaction();
  }

on the Serialmonitor the MAX's dont start to initiate how come?
Initializing sensor...ERROR.

so if the delay and digitalWrite are placed before all_sensors->begin();

it works... why is that?
 
Last edited:
The chip selects are active low, so I think need to be initilized HIGH, presuming that the begin() method knows
what its doing. It should handle such details for you. begin() returns success, not error, so you test is backwards.

The initialization of Serial doesn't logicall belong in the loop.
 
You mean chip selects from the max31855 are active low?
So readout commences the moment CS is pulled LOW. ->ok.
I have to set all of them to active HIGH in the beginning.
 
I came across the following problem.


If in the void loop the program HX8357(); is run and the thermocouple1_4(); after that,

I only see the Initialization of the SPI for the HX8357.
If I switch it around: I get 4 readouts from the thermocouple1_4();

The hx8357(); doesnt do hard stuff, it paints on the featherwing3.5 some rectangles and words.


void loop()
{

Hx8357();
Thermocouple1_4();


}

Why is that?


Best regards

Bastian
 
You mean chip selects from the max31855 are active low?
Well that's what the datasheet says, which I checked. Its very rare to see active-high chip selects in fact, a hangover from
TTL conventions where selects and output enables were usually active low. This is due to TTL only allowng pull-up resistors,
not pull-downs (TTL was a very asymmetric logic family, unlike CMOS)
 
Thanks Mark for shorting the code.

I still have one question left.

In the for loop I have:

For(int i=0;i<4;i++)
{

SPI.BeginTransaction(MAX31855);
digitalWrite(14+i,LOW);
Double c[]=all_sensors->readCelcius();
DgitalWrite(14+i,HIGH);
SPI.EndTransaction();

How do I write this array of 4 variables each time to another function?
pass by reference or argument?

Like to a hx8357(); function?

Best regards

Bastiaan
 
You need to declare the c[] array before the loop so it exists after the loop, and the type is 'double', not 'Double'.
An array variable is already a pointer so you just pass it straightforwardly - any pointer variable is also an array.
C doesn't do any array-bound checking so it very easy to shoot yourself in the foot - its a very primitive programming
language in some respects.

Code:
double c[4] ;
For(int i=0;i<4;i++)
{

SPI.beginTransaction(MAX31855);
digitalWrite(14+i,LOW);
c[i] = all_sensors[i]->readCelcius();
digitalWrite(14+i,HIGH);
SPI.endTransaction();
}
footle (c) ;  // pass array pointer to other function like this.
 
Thanks for the reply. I’ll keep it in notice about the arrays and pointers.
I lost touch to programming a long time a go, but i am picking it up on its interesting puzzle :)

Have nice weekend!
 
Hi MarkT,

I got rid of the previous code and tryouts and resorted to global variables, ( i know.... )

so I am stuck at the beginning of the code:


Libraries that I use:
Code:
#include <SPI.h>
#include "Adafruit_MAX31855.h"
#include "HX8357_t3n.h"
#include <FlickerFreePrint.h>// library to draw w/o flicker
#include <math.h>
#include <stdio.h>

#include <ButtonEvents.h>
#include <ADC.h>
#include <Encoder.h>
#include <PID_v1.h>

SPI defines:

Code:
#define MAXCLK 13 //max31855 nothing else.
#define MAXDO   9  //MISO required for the MAX31855
#define TFT_DC  10
#define TFT_CS 8
#define TFT_RST -1


Code:
void loop() 
{
 nowMillis=millis();
 InternalADC(); 
 Menu1Check();
 
      
       
     if(nowMillis-previousMillis>100)
     {
       Menu1Countdown();
      
      nowMillis=previousMillis;
     }
     else
     { 
      Thermocouples1_4();
      
     
       
     }
 
     
      
  }






if I run this the TFT screen works, but no temperature, if its the otherway around i get no updated screen but temperature
only what is drawn from the void setup();

how can I let the 4 max31855 read a value, post it to the array C[0] and then post it on the tft screen? and how can i get a timing check or a MISO check in this that the SPI line is free?

Code:
int Menu1Countdown() //Menu 1 //Display
{
    Serial.print("test TC0");
        Serial.println(c[0]);
         Serial.print("test TC1");
        Serial.println(c[1]);
         Serial.print("test TC2");
        Serial.println(c[2]);
         Serial.print("test TC3");
        Serial.println(c[3]);
         Serial.print("jep works fine");


 /* all graphics commands have to appear within the loop body. */    
       SPI.beginTransaction(settingsTFT);
            digitalWrite(TFT_CS,LOW);
      
      Data1.setTextColor(C_WHITE, C_BLACK);
   
      tft.setTextSize(2);
      tft.setCursor(0, 0);
      tft.print("Emagnet program");
      

    
    //  // now let's see the tft update with FlickerFree
      tft.setTextSize(1);
      tft.setCursor(0,20);
      Data1.setTextColor(C_WHITE, C_BLACK);
      tft.print("Temperature readout");
      tft.print(" Voltages from Thermocouples ");
      tft.setTextSize(2);
      Data1.setTextColor(C_WHITE, C_BLACK);
      tft.setCursor(20,45);
      Data1.print(j,2);
      sprintf(str,"TempEmag: %lu",c[0]);
      Data1.print(str);
      tft.setCursor(20,60);
      Data1.print(c[0]); //C is a global variable!

      Data1.print(c[1]);
      tft.print(" TempWater");
      tft.setCursor(20,75);
      tft.print(c[2]);
      tft.print(" TEMPTEC2");
      tft.setCursor(20,90);
      Data1.print(c[2]);
      tft.print(" Temp");
      tft.setCursor(20,105);
      tft.print(c[3]);
      tft.print(" C");
      tft.setCursor(20,120);
      Serial.print(c[3]);

  digitalWrite(TFT_CS,HIGH);
       SPI.endTransaction();
}


I tried something simple as this as well: but it doesnt work can someone explain this hard example?

Code:
   if(digitalRead(8)==LOW)//this is the CS from the TFT
     {
      SPI.beginTransaction(settingsTFT);
      Menu1Countdown(); 
      SPI.endTransaction();
     }
     else
     { 
      SPI.beginTransaction(SettingsA);
      Thermocouples1_4();
      SPI.endTransaction();
     }

many thanks for having a look at this!
 
Last edited:
Status
Not open for further replies.
Back
Top