SPI Problem with K-Thermocouple and Potentiometer? I have a setup where the Arduino reads input from the k-thermocouple and uses that info to regultate the an output voltage through a potentiometer. I know the potentiometer is not faulty because able to read the output from the wiper when I run the program but for some reason, k-thermocouple is stuck at 0 Celsius. I know that the k-thermocouple is not faulty either because it works accordingly when I run a program specifically by itself.

Does anybody know why there is a problem with how the k-thermocouple is operating in junction with the potentiometer? Here is a declarations of my program.

#include &lt;SPI.h&gt;

// K-couple dependent DigiPot Regulator

#include "SPI.h"
#include "max6675.h"

byte address = 0x10;
int CLK = 13;
int CS = 10;
int SDI = 11;
const int ktcSO = 12;
int ktcCS = 9;
int ktcCLK = 13;

MAX6675 ktc(ktcCLK, ktcCS, ktcSO);


int digitalPotWrite(int value) //Everything that happens when the DigiPot is 
called
{
  digitalWrite(CS, LOW); // Chip Select is ACTIVE LOW (so now it's selected)
  SPI.transfer(address);
  SPI.transfer(value);
  digitalWrite(CS, HIGH);
}

void setup() 
{
  SPI.begin();
  pinMode (CLK, OUTPUT);
  pinMode (CS, OUTPUT);
  pinMode (SDI, OUTPUT);
  Serial.begin(9600);
  // give the MAX a little time to settle
  delay(500);
}

void loop() 
{
  if (ktc.readFahrenheit() &lt; 60)  // While it's still in Safe Zone
  {
    digitalPotWrite(255);
    // Show the current temp in C and F
    Serial.print("Deg C = "); 
    Serial.print(ktc.readCelsius());
    Serial.print("\t Deg F = ");
    Serial.print(ktc.readFahrenheit());
    int sensorValue = analogRead(A0);
    float voltage = sensorValue * (5.0 / 1023.0);
    Serial.print("\t V = ");
    Serial.println(voltage);
    int clockValue = analogRead(A1);
    Serial.print("\t Clock = ");
    Serial.println(clockValue);
  }
        if (ktc.readFahrenheit() &lt; 65) // While in Caution Zone
        digitalPotWrite(51);
        else if (ktc.readFahrenheit() &lt; 70)
        digitalPotWrite(102);
        else if (ktc.readFahrenheit() &lt; 75)
        digitalPotWrite(153);
        else if (ktc.readFahrenheit() &lt; 78)
        digitalPotWrite(184);
        else if (ktc.readFahrenheit() &lt; 80) //Getting into Danger Zone
        digitalPotWrite(204);
        else if (ktc.readFahrenheit() &lt; 81)
        digitalPotWrite(214);
        else if (ktc.readFahrenheit() &lt; 82)
        digitalPotWrite(224);
        else if (ktc.readFahrenheit() &lt; 83)
        digitalPotWrite(235);
        else if (ktc.readFahrenheit() &lt; 84)
        digitalPotWrite(245);
        else (ktc.readFahrenheit() &lt; 85); //Complete Shutoff 
        digitalPotWrite(255);
    {
     Serial.print("Deg C = "); 
     Serial.print(ktc.readCelsius());
     Serial.print("\t Deg F = ");
     Serial.print(ktc.readFahrenheit());
     int sensorValue = analogRead(A0);
     float voltage = sensorValue * (5.0 / 1023.0);
     Serial.print("\t V = ");
     Serial.println(voltage);
     int clockValue = analogRead(A1);
     Serial.print("\t Clock = ");
     Serial.println(clockValue);
    }
}


Also, the code I used to test the K-Thermocouple is one that can be found on the internet (with just a little bit of adjustments)...

// Sample Arduino MAX6675 Arduino Sketch

#include "max6675.h"

int ktcSO = 12;
int ktcCS = 9;
int ktcCLK = 13;

MAX6675 ktc(ktcCLK, ktcCS, ktcSO);


void setup() {
  Serial.begin(9600);
  // give the MAX a little time to settle
  delay(500);
}

void loop() {
  // basic readout test

   Serial.print("Deg C = "); 
   Serial.print(ktc.readCelsius());
   Serial.print("\t Deg F = ");
   Serial.println(ktc.readFahrenheit());
   int clockValue = analogRead(A1);
    Serial.print("\t Clock = ");
    Serial.println(clockValue);

   delay(500);
}
The wiring diagram, if accurate, shows a couple of problems.

First, A0 has nothing attached to it, so sensorValue may read in as zero or some small random number.

Second, attaching the digital pot's analog output pin 6, P1W, to the Uno's digital input pin 12 is pointless.  Instead connect P1W to whatever it is supposed to control.  If you want to handle data from the MCP42X1, connect its pin 13, SDO, to an Uno input. 

However, neither of those problems appears to be related to misreading the MAX6675 temperature.  I don't know of a good approach to solving that problem, but if I were working with the circuit, would remove the wire between P1W and the Uno's digital pin 12, and would use 12 as the input from the MAX6675; that is, would wire it to d12 instead of d8, and instead of int ktcSO = 8 would say const int ktcSO = 12.  Also, I'd probably replace the bit of code

  }
  else
  {
    while (ktc.readFahrenheit() &lt; 85) 
      {


with just a closing }.  In the Arduino paradigm, loop() runs repeatedly, and the if–else sequence adequately guards each of the digitalPotWrite() calls.

Note, the digitalPotWrite() function should be defined or declared before any calls to it appear.  Instead of placing that function at the end, put it before  loop() or before setup().