thank you for the super quick response.
I finally finished all the Hardware and im only onto the code now.
I for now settled on "only" controlling the temperature via 2 channel relay and having 2 temperature sensors. The Relay part works and I can control the upper and lower heater manually via my keypad.
But for the life of me I cannot get the 2 Thermocouples to output any useful Value. To simplify my experimentations, I am simply using the Adafruit example for my Thermocouple, which I extended to work with 2 thermocouples.
The Issue is, that both Thermocouples only output 0 as a Value.
Does anyone have a Clue why this does not Work? Could this be Hardware related; that the Arduino UNO doesnt have enough Power to run 2 Max31855k, 2 Channel Relay and a 1602 Keypad Shield?
/***************************************************
This is an example for the Adafruit Thermocouple Sensor w/MAX31855K
Designed specifically to work with the Adafruit Thermocouple Sensor
----> https://www.adafruit.com/products/269
These displays use SPI to communicate, 3 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#include <SPI.h>
#include "Adafruit_MAX31855.h"
// Default connection is using software SPI, but comment and uncomment one of
// the two examples below to switch between software SPI and hardware SPI:
// Example creating a thermocouple instance with software SPI on any three
// digital IO pins.
#define DO 2
#define CSO 3
#define CSU A2
#define CLK A1
// initialize the Thermocouple
//(CLKU, CSU, DU)
Adafruit_MAX31855 thermocoupleO(CLK, CSO, DO);
Adafruit_MAX31855 thermocoupleU(CLK, CSU, DO);
// Example creating a thermocouple instance with hardware SPI
// on a given CS pin.
//#define MAXCS 10
//Adafruit_MAX31855 thermocouple(MAXCS);
// Example creating a thermocouple instance with hardware SPI
// on SPI1 using specified CS pin.
//#define MAXCS 10
//Adafruit_MAX31855 thermocouple(MAXCS, SPI1);
void setup() {
Serial.begin(9600);
while (!Serial) delay(1); // wait for Serial on Leonardo/Zero, etc
Serial.println("MAX31855 test");
// wait for MAX chip to stabilize
delay(500);
Serial.print("Initializing sensor...");
if (!thermocoupleO.begin()) {
Serial.println("ERROR.");
while (1) delay(10);
}
if (!thermocoupleU.begin()) {
Serial.println("ERROR.");
while (1) delay(10);
}
Serial.println("DONE.");
}
void loop() {
double co = thermocoupleO.readCelsius();
if (isnan(co)) {
Serial.println("Something wrong with thermocouple Oben!");
} else {
Serial.print("C O.= ");
Serial.println(co);
}
double cu = thermocoupleU.readCelsius();
if (isnan(cu)) {
Serial.println("Something wrong with thermocouple Unten!");
} else {
Serial.print("C U.= ");
Serial.println(cu);
}
delay(1000);
}
By the Way, I cleaned up my Code itself and changed some stuff, this is it right now. If anyone can give me some more Pointers I would be glad. I used a tool called "TcMenu" to build my Menu. Hence the getvalue/setvalue variables.
Essentially, I want to Set a "goal" temperature. Then in a sub Menu I want to be able to set a lower and upper tolerance for this goal temperature. I also added a "manual" mode so I can turn on/off the relay channels by hand (this is the only part which isnt dependend on the temperature Sensors, so it works).
Anyways, this is it:
#include "ArduinoTemp_menu.h"
#include <SPI.h>
#include "Adafruit_MAX31855.h"
// digital IO pins.
#define RelaisO A5
#define RelaisU A4
#define DO 2
#define CSO 3
#define CSU A2
#define CLK A1
int I = 0;
bool feineinstellungen;
int SollTemp;
int SollTempOben;
int SollTempUnten;
int TempToleranzUnten;
int TempToleranzOben;
int TempSel;
float Timer;
double co;
double cu;
const int numReadings = 10;
int readings1[numReadings]; // the readings from the analog input
int readIndex1 = 0; // the index of the current reading
int total1 = 0; // the running total
int readings2[numReadings]; // the readings from the analog input
int readIndex2 = 0; // the index of the current reading
int total2 = 0; // the running total
double averageo = 0; // the average
double averageu = 0; // the average
Adafruit_MAX31855 thermocoupleO(CLK, CSO, DO);
Adafruit_MAX31855 thermocoupleU(CLK, CSU, DO);
void setup() {
Serial.begin(9600);
while (!Serial) delay(1); // wait for Serial on Leonardo/Zero, etc
Serial.println("MAX31855 test 1");
// wait for MAX chip to stabilize
delay(500);
Serial.print("Initializing sensor...");
if (!thermocoupleO.begin()) {
Serial.println("ERROR. 1");
while (1) delay(10);
}
Serial.println("DONE. 1");
Serial.println("MAX31855 test 2");
// wait for MAX chip to stabilize
delay(500);
Serial.print("Initializing sensor 2...");
if (!thermocoupleU.begin()) {
Serial.println("ERROR. 2");
while (1) delay(10);
}
Serial.println("DONE. 2");
//Relaissteuerung
pinMode(RelaisO, OUTPUT);
pinMode(RelaisU, OUTPUT);
TempToleranzUnten = 5;
TempToleranzOben = 3;
menuFeineinstellungenTempTolUnten.setCurrentValue(TempToleranzUnten);
menuFeineinstellungenTempTolOben.setCurrentValue(TempToleranzOben);
Serial.println("Pizzamaster 3000 READY");
setupMenu();
menuSollTemp.setCurrentValue(20);
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readings1[thisReading] = 0;
readings2[thisReading] = 0;
}
digitalWrite(RelaisO, HIGH);
menuFeineinstellungenHeizOben.setCurrentValue(1);
digitalWrite(RelaisU, HIGH);
menuFeineinstellungenHeizUnten.setCurrentValue(1);
}
void loop() {
taskManager.runLoop();
temperaturereading();
getSensorData();
relaiscontrol();
}
//==================================================================================================
void getSensorData() {
float SollTemp = menuSollTemp.getCurrentValue();
//float TempToleranzUnten = menuFeineinstellungenTempTolUnten.getCurrentValue();
//float TempToleranzOben = menuFeineinstellungenTempTolOben.getCurrentValue();
//float SollTempUnten = menuFeineinstellungenTempUnten.getCurrentValue();
//float SollTempOben = menuFeineinstellungenTempOben.getCurrentValue();
menuIstTempU.setCurrentValue(averageu);
menuIstTempO.setCurrentValue(averageo);
}
//==================================================================================================
void temperaturereading() {
co = thermocoupleO.readCelsius();
cu = thermocoupleU.readCelsius();
// subtract the last reading:
total1 = total1 - readings1[readIndex1];
// read from the sensor:
readings1[readIndex1] = co;
// add the reading to the total:
total1 = total1 + readings1[readIndex1];
// advance to the next position in the array:
readIndex1 = readIndex1 + 1;
// if we're at the end of the array...
if (readIndex1 >= numReadings) {
// ...wrap around to the beginning:
readIndex1 = 0;
}
// calculate the average:
averageo = total1 / numReadings;
// calculate the average:
averageu = total2 / numReadings;
// subtract the last reading:
total2 = total2 - readings2[readIndex2];
// read from the sensor:
readings2[readIndex2] = cu;
// add the reading to the total:
total2 = total2 + readings2[readIndex2];
// advance to the next position in the array:
readIndex2 = readIndex2 + 1;
// if we're at the end of the array...
if (readIndex2 >= numReadings) {
// ...wrap around to the beginning:
readIndex2 = 0;
}
// calculate the average:
averageu = total2 / numReadings;
Serial.print("Temperatur Oben:");
Serial.println(averageo);
Serial.print("Temperatur Unten:");
Serial.println(averageu);
}
//==================================================================================================
void relaiscontrol() {
//Relaissteuerung
if (menuFeineinstellungenFeinTemp.getCurrentValue() == 0) {
if (averageo < (SollTemp - TempToleranzUnten)) {
digitalWrite(RelaisO, LOW);
}
if (averageo > (SollTemp + TempToleranzOben)) {
digitalWrite(RelaisO, HIGH);
}
if (averageu < (SollTemp - TempToleranzUnten)) {
digitalWrite(RelaisU, LOW);
}
if (averageu > (SollTemp + TempToleranzOben)) {
digitalWrite(RelaisU, HIGH);
}
}
if (menuFeineinstellungenManuellHeizen.getCurrentValue() == 1 && menuFeineinstellungenHeizOben.getCurrentValue() == 0) {
digitalWrite(RelaisO, HIGH);
}
if (menuFeineinstellungenManuellHeizen.getCurrentValue() == 1 && menuFeineinstellungenHeizUnten.getCurrentValue() == 0) {
digitalWrite(RelaisU, HIGH);
}
if (menuFeineinstellungenManuellHeizen.getCurrentValue() == 1 && menuFeineinstellungenHeizOben.getCurrentValue() == 1) {
digitalWrite(RelaisO, LOW);
}
if (menuFeineinstellungenManuellHeizen.getCurrentValue() == 1 && menuFeineinstellungenHeizUnten.getCurrentValue() == 1) {
digitalWrite(RelaisU, LOW);
}
/*
if ((menuFeineinstellungenHeizOben.getCurrentValue() == 0) && (menuFeineinstellungenHeizUnten.getCurrentValue() == 0) && (averageo < (SollTempUnten - TempToleranzUnten))) {
digitalWrite(RelaisO, HIGH);
}
if ((menuFeineinstellungenHeizOben.getCurrentValue() == 0 && menuFeineinstellungenHeizUnten.getCurrentValue() == 0 && averageo > (SollTempUnten + TempToleranzOben)) {
digitalWrite(RelaisO, LOW);
}
if (menuFeineinstellungenHeizOben.getCurrentValue() == 0 && menuFeineinstellungenHeizUnten.getCurrentValue() == 0 && averageu < (SollTempOben - TempToleranzUnten)) {
digitalWrite(RelaisU, HIGH);
}
if (menuFeineinstellungenHeizOben.getCurrentValue() == 0 && menuFeineinstellungenHeizUnten.getCurrentValue() == 0 && averageu > (SollTempOben + TempToleranzOben)) {
digitalWrite(RelaisU, LOW);
}
*/
}
//==================================================================================================