I'm able to solely test the K-Thermocouple and it works perfectly fine but when I built my circuit which also includes a digipot, it doesn't seem to register anything. Supposedly they both communicate with the Arduino Uno through SPI and I'm assuming the conjunction of both K-Thermocouple and Digipot on the same SPI may be the probelm.
Can someone please take a look at this code and identify the problem for me? Thanks.
#include <SPI.h>
// K-couple dependent DigiPot Regulator
#include "SPI.h"
#include "max6675.h"
byte address = 0x10;
int CLK = 13;
int CS = 10;
int SDI = 11;
int ktcSO = 8;
int ktcCS = 9;
int ktcCLK = 13;
MAX6675 ktc(ktcCLK, ktcCS, ktcSO);
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() < 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);
}
else
{
while (ktc.readFahrenheit() < 85)
{
if (ktc.readFahrenheit() < 65) // While in Caution Zone
digitalPotWrite(51);
else if (ktc.readFahrenheit() < 70)
digitalPotWrite(102);
else if (ktc.readFahrenheit() < 75)
digitalPotWrite(153);
else if (ktc.readFahrenheit() < 78)
digitalPotWrite(184);
else if (ktc.readFahrenheit() < 80) //Getting into Danger Zone
digitalPotWrite(204);
else if (ktc.readFahrenheit() < 81)
digitalPotWrite(214);
else if (ktc.readFahrenheit() < 82)
digitalPotWrite(224);
else if (ktc.readFahrenheit() < 83)
digitalPotWrite(235);
else if (ktc.readFahrenheit() < 84)
digitalPotWrite(245);
else (ktc.readFahrenheit() < 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 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);
}