Compare commits
No commits in common. "8f9584a8189a1a907c3ae80f931dc4c30144c543" and "4daaa73b83858a3d62b461d1faf02d9c94d2ae15" have entirely different histories.
8f9584a818
...
4daaa73b83
@ -1,8 +1,8 @@
|
||||
#define useEEPROM 1
|
||||
// #define TempSensorMax
|
||||
#define TempSensorDallas
|
||||
|
||||
#include <max6675.h>
|
||||
#include <Wire.h>
|
||||
#include <PID_v1.h>
|
||||
#include <GyverOLED.h>
|
||||
#include "GyverEncoder.h"
|
||||
|
||||
@ -10,26 +10,11 @@
|
||||
#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;
|
||||
@ -59,12 +44,12 @@ struct Profile {
|
||||
|
||||
// Profiles definition
|
||||
Profile profiles[] = {
|
||||
{"Chickpeas", 2, {{30, 1}, {47, 120}, {55, 60}, {65, 150}, {70, 60}, {90, 105}}, 6},
|
||||
{"Chickpeas", 3, {{47, 120}, {53, 120}, {65, 180}, {72, 90}, {90, 90}}, 5},
|
||||
{"Lentils", 3, {{47, 120}, {53, 120}, {65, 180}, {72, 90}, {90, 15}}, 5},
|
||||
{"Lentils gradual", 10, {{48, 120}, {80, 60}}, 2},
|
||||
{"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},
|
||||
{"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},
|
||||
{"Test", 1, {{49, 1}, {51, 1}}, 2},
|
||||
};
|
||||
|
||||
@ -79,12 +64,9 @@ bool isInTransition = false;
|
||||
bool inSelectionMode = true;
|
||||
|
||||
// PID Control variables
|
||||
// double Kp = 0.5, Ki = 1, Kd = 0.05;
|
||||
// PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
|
||||
|
||||
#include "GyverPID.h"
|
||||
double Setpoint, Input, Output;
|
||||
GyverPID regulator(1, 0.5, 0, 1000);
|
||||
double Kp = 0.5, Ki = 1, Kd = 0.05;
|
||||
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
|
||||
|
||||
// Timing variables
|
||||
long phaseStartTime;
|
||||
@ -108,10 +90,8 @@ 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 4
|
||||
#define PARTS 10
|
||||
|
||||
void setup() {
|
||||
pinMode(ssrPin, OUTPUT);
|
||||
@ -120,19 +100,9 @@ void setup() {
|
||||
oled.init(); // Initialize the OLED
|
||||
oled.clear(); // Clear the display
|
||||
readEEPROM();
|
||||
regulator.setDirection(NORMAL); // направление регулирования (NORMAL/REVERSE). ПО УМОЛЧАНИЮ СТОИТ NORMAL
|
||||
regulator.setLimits(0, 100); // пределы (ставим для 8 битного ШИМ). ПО УМОЛЧАНИЮ СТОЯТ 0 И 255
|
||||
regulator.setpoint = 0;
|
||||
myPID.SetMode(AUTOMATIC);
|
||||
myPID.SetOutputLimits(0, 1);
|
||||
|
||||
#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() {
|
||||
@ -145,27 +115,8 @@ 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;
|
||||
@ -213,7 +164,7 @@ void handleHeaterAdv() {
|
||||
}
|
||||
timerSSR = time;
|
||||
|
||||
int current = Output/100 * PARTS;
|
||||
int current = Output * PARTS;
|
||||
|
||||
int last = 0;
|
||||
for (int i = 1; i < PARTS; i++) {
|
||||
@ -222,12 +173,11 @@ void handleHeaterAdv() {
|
||||
states[i-1] = states[i];
|
||||
}
|
||||
}
|
||||
bool next = current >= last ? true : false;
|
||||
if (Output < 0.05) next = false;
|
||||
bool next = current > last ? true : false;
|
||||
states[PARTS-1] = next;
|
||||
|
||||
oled.setCursor(128-6*PARTS, 7);
|
||||
sprintf(timeBuffer, "%3d", (int)(Output));
|
||||
sprintf(timeBuffer, "%3d", (int)(Output*100));
|
||||
char symbol;
|
||||
for (int i = 0; i < PARTS; i++) {
|
||||
int index = i - (PARTS - 3);
|
||||
@ -242,14 +192,6 @@ 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() {
|
||||
@ -291,17 +233,11 @@ void handleExecution() {
|
||||
|
||||
getPhaseAndTemperature();
|
||||
|
||||
#ifdef TempSensorMax
|
||||
Input = thermocouple.readCelsius();
|
||||
#endif
|
||||
|
||||
if (isnan(Input)) {
|
||||
Input = 0;
|
||||
}
|
||||
regulator.input = (float)Input;
|
||||
regulator.setpoint = Setpoint;
|
||||
regulator.getResult();
|
||||
Output = regulator.output;
|
||||
myPID.Compute();
|
||||
|
||||
if (isComplete && currentPhase >= activeProfile.numPhases && !finishTime) {
|
||||
finishTime = currentTime;
|
||||
@ -316,7 +252,8 @@ void startExecution() {
|
||||
inSelectionMode = false; // Switch to execution mode
|
||||
phaseStartTime = totalStartTime = millis(); // Start the timer
|
||||
totalElapsedTime = 0;
|
||||
regulator.setpoint = 0;
|
||||
myPID.SetMode(AUTOMATIC);
|
||||
myPID.SetOutputLimits(0, 1); // 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