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.
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
Last edited: