dallas/max switch
This commit is contained in:
parent
4daaa73b83
commit
673fbc03d8
@ -1,6 +1,7 @@
|
||||
#define useEEPROM 1
|
||||
// #define TempSensorMax
|
||||
#define TempSensorDallas
|
||||
|
||||
#include <max6675.h>
|
||||
#include <Wire.h>
|
||||
#include <PID_v1.h>
|
||||
#include <GyverOLED.h>
|
||||
@ -10,11 +11,26 @@
|
||||
#include <EEPROM.h>
|
||||
#endif
|
||||
|
||||
#ifdef TempSensorMax
|
||||
#include <max6675.h>
|
||||
// MAX6675 configuration
|
||||
int max_SO = 12;
|
||||
int max_CS = 10;
|
||||
int max_SCK = 13;
|
||||
MAX6675 thermocouple(max_SCK, max_CS, max_SO);
|
||||
#endif
|
||||
#ifdef TempSensorDallas
|
||||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
// Data wire is plugged into port 2 on the Arduino
|
||||
#define ONE_WIRE_BUS 9
|
||||
|
||||
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
|
||||
OneWire oneWire(ONE_WIRE_BUS);
|
||||
|
||||
// Pass our oneWire reference to Dallas Temperature.
|
||||
DallasTemperature sensors(&oneWire);
|
||||
#endif
|
||||
|
||||
// OLED configuration
|
||||
// GyverOLED<SSD1306_128x64> oled;
|
||||
@ -44,12 +60,12 @@ struct Profile {
|
||||
|
||||
// Profiles definition
|
||||
Profile profiles[] = {
|
||||
{"Chickpeas", 3, {{47, 120}, {53, 120}, {65, 180}, {72, 90}, {90, 90}}, 5},
|
||||
{"Chickpeas", 2, {{30, 1}, {47, 120}, {55, 60}, {65, 150}, {70, 60}, {90, 105}}, 6},
|
||||
{"Lentils", 3, {{47, 120}, {53, 120}, {65, 180}, {72, 90}, {90, 15}}, 5},
|
||||
{"Lentils gradual", 10, {{48, 120}, {80, 60}}, 2},
|
||||
{"Wheat", 3, {{47, 60}, {53, 60}, {65, 20}, {72, 20}, {85, 20}}, 5},
|
||||
{"Sous Vide 55+120", 1, {{55, 30}, {85, 120}}, 2},
|
||||
{"46 (45)", 0, {{46, 45}}, 1},
|
||||
{"Wheat", 1, {{47, 60}, {53, 60}, {65, 20}, {72, 20}, {85, 20}}, 5},
|
||||
{"55-30&85-120", 1, {{55, 30}, {85, 120}}, 2},
|
||||
{"46-45", 0, {{46, 45}}, 1},
|
||||
{"Test", 1, {{49, 1}, {51, 1}}, 2},
|
||||
};
|
||||
|
||||
@ -90,8 +106,10 @@ uint32_t timer = 0;
|
||||
#define T_PERIOD 1000 // period of Execution processing
|
||||
uint32_t timerSSR = 0;
|
||||
#define T_PERIOD_SSR 500 // period of heater handling
|
||||
uint32_t timerDallas = 0;
|
||||
#define T_PERIOD_DALLAS 1000 // period of dallas sensor requesting
|
||||
|
||||
#define PARTS 10
|
||||
#define PARTS 4
|
||||
|
||||
void setup() {
|
||||
pinMode(ssrPin, OUTPUT);
|
||||
@ -101,8 +119,18 @@ void setup() {
|
||||
oled.clear(); // Clear the display
|
||||
readEEPROM();
|
||||
myPID.SetMode(AUTOMATIC);
|
||||
myPID.SetOutputLimits(0, 1);
|
||||
myPID.SetOutputLimits(0, 100);
|
||||
// myPID.SetSampleTime(1000);
|
||||
|
||||
#ifdef TempSensorDallas
|
||||
sensors.begin();
|
||||
DeviceAddress tempDeviceAddress;
|
||||
sensors.getAddress(tempDeviceAddress, 0);
|
||||
sensors.setResolution(tempDeviceAddress, 12);
|
||||
sensors.setWaitForConversion(false);
|
||||
#endif
|
||||
|
||||
// Serial.println("Input, Output, Real Output");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@ -115,8 +143,27 @@ void loop() {
|
||||
}
|
||||
handleExecution();
|
||||
handleHeaterAdv();
|
||||
#ifdef TempSensorDallas
|
||||
handleDallasTemperatureSensor();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef TempSensorDallas
|
||||
void handleDallasTemperatureSensor() {
|
||||
long time = millis();
|
||||
static int currentPart = 0;
|
||||
|
||||
if (time - timerDallas < T_PERIOD_DALLAS) {
|
||||
return;
|
||||
}
|
||||
timerDallas = time;
|
||||
|
||||
Input = (double) sensors.getTempCByIndex(0);
|
||||
|
||||
sensors.requestTemperatures(); // Send the command to get temperatures
|
||||
}
|
||||
#endif
|
||||
|
||||
void handleHeaterSimple() {
|
||||
long time = millis();
|
||||
static int currentPart = 0;
|
||||
@ -164,7 +211,7 @@ void handleHeaterAdv() {
|
||||
}
|
||||
timerSSR = time;
|
||||
|
||||
int current = Output * PARTS;
|
||||
int current = Output/100 * PARTS;
|
||||
|
||||
int last = 0;
|
||||
for (int i = 1; i < PARTS; i++) {
|
||||
@ -173,11 +220,12 @@ void handleHeaterAdv() {
|
||||
states[i-1] = states[i];
|
||||
}
|
||||
}
|
||||
bool next = current > last ? true : false;
|
||||
bool next = current >= last ? true : false;
|
||||
if (Output < 0.05) next = false;
|
||||
states[PARTS-1] = next;
|
||||
|
||||
oled.setCursor(128-6*PARTS, 7);
|
||||
sprintf(timeBuffer, "%3d", (int)(Output*100));
|
||||
sprintf(timeBuffer, "%3d", (int)(Output));
|
||||
char symbol;
|
||||
for (int i = 0; i < PARTS; i++) {
|
||||
int index = i - (PARTS - 3);
|
||||
@ -192,6 +240,14 @@ void handleHeaterAdv() {
|
||||
if (currentPart >= PARTS) {
|
||||
currentPart = 0;
|
||||
}
|
||||
|
||||
Serial.print(Setpoint);
|
||||
Serial.print(",");
|
||||
Serial.print(Input);
|
||||
Serial.print(",");
|
||||
Serial.print(Output);
|
||||
Serial.println(",0,100");
|
||||
|
||||
}
|
||||
|
||||
void handleEncoder() {
|
||||
@ -233,7 +289,10 @@ void handleExecution() {
|
||||
|
||||
getPhaseAndTemperature();
|
||||
|
||||
#ifdef TempSensorMax
|
||||
Input = thermocouple.readCelsius();
|
||||
#endif
|
||||
|
||||
if (isnan(Input)) {
|
||||
Input = 0;
|
||||
}
|
||||
@ -253,7 +312,7 @@ void startExecution() {
|
||||
phaseStartTime = totalStartTime = millis(); // Start the timer
|
||||
totalElapsedTime = 0;
|
||||
myPID.SetMode(AUTOMATIC);
|
||||
myPID.SetOutputLimits(0, 1); // SSR is either ON or OFF
|
||||
myPID.SetOutputLimits(0, 100); // SSR is either ON or OFF
|
||||
// digitalWrite(ssrPin, HIGH); // Start with heater on
|
||||
ssrLastSwitchTime = millis();
|
||||
calculateTotalTime();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user