Get ready for 0.1.0

- tuning once more the pid
- enabling fan while on full power
- detect missing sensor
- ...
This commit is contained in:
Fliegerjohn 2024-05-06 22:38:36 +02:00
parent 67c1f0503a
commit a19463b3a1
Signed by: fliegerjohn
GPG key ID: E2221D5FE4656B6A

View file

@ -1,3 +1,12 @@
/* Weckkubator - Weck(topf)-(In)kubator
*
* Version 0.1.0
*
* Fliegerjohn - 06.05.2024
*/
#include <Wire.h> // Support for I2C --> LCD
#include <LiquidCrystal_I2C.h> // Support for PCF8574 --> LCD
#include <OneWire.h> // 1-Wiresupport for DS18B20
@ -16,7 +25,7 @@ DallasTemperature sensors(&oneWire); // declare sensors
double pidset, watertemp, output;
// PID adjustment
double Kp=500, Ki=10, Kd=0;
double Kp=500, Ki=3, Kd=1;
PID myPID(&watertemp, &output, &pidset, Kp, Ki, Kd, DIRECT);
int WindowSize = 5000;
unsigned long windowStartTime;
@ -27,6 +36,7 @@ int poti;
// time
unsigned long previousMillis;
unsigned long previousMillisFan;
// °C for LCD
@ -60,31 +70,15 @@ void setup() {
// Setup PID
windowStartTime = millis();
myPID.SetOutputLimits(0, WindowSize); //tell the PID to range between 0 and the full window size
myPID.SetMode(AUTOMATIC); //turn the PID on
myPID.SetMode(AUTOMATIC); //turn on the PID
// Greetings
lcd.print("Weckkubator 0.0.1");
lcd.print("Weckkubator 0.1.0");
delay(3000);
lcd.clear();
// Setup LCD
// Output temperatureset
lcd.setCursor(0, 1);
lcd.print("set: ");
lcd.print(pidset);
lcd.write((byte)0);
// Output watertemp
lcd.setCursor(0, 2);
lcd.print("temp: ");
lcd.print(watertemp);
lcd.write((byte)0);
lcd.print("C");
// output PID
lcd.setCursor (0, 3);
lcd.print("output: ");
lcd.print(output);
setupdisplay();
}
@ -92,7 +86,7 @@ void loop() {
// run pid
pid();
// update LCD
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= 250) {
@ -101,7 +95,13 @@ void loop() {
lcdoutput();
previousMillis = currentMillis;
}
// start fan if heating on full power
if (currentMillis - previousMillisFan >= 10000) {
if (output >= 4800) digitalWrite(fan, HIGH);
else digitalWrite(fan, LOW);
previousMillisFan = currentMillis;
}
}
//------------------------------------------
@ -127,6 +127,8 @@ void readtemp() {
*/
sensors.requestTemperatures();
watertemp = sensors.getTempCByIndex(0);
if (watertemp == -127.00) missingsensor();
}
@ -170,3 +172,50 @@ void settemp() {
}
//------------------------------------------
// Missing Sensor
void missingsensor() {
// turn of all output
digitalWrite(wecktopf, LOW);
digitalWrite(fan, LOW);
// Clear LCD
lcd.clear();
do {
lcd.setCursor(0, 0);
lcd.print("Error:");
lcd.setCursor(0, 1);
lcd.print("Missing Sensor");
sensors.requestTemperatures();
watertemp = sensors.getTempCByIndex(0);
} while (watertemp == -127.00);
setupdisplay();
}
//------------------------------------------
// Setup LCD
void setupdisplay() {
// Clear LCD
lcd.clear();
// Output temperatureset
lcd.setCursor(0, 1);
lcd.print("set: ");
lcd.print(pidset);
lcd.write((byte)0);
// Output watertemp
lcd.setCursor(0, 2);
lcd.print("temp: ");
lcd.print(watertemp);
lcd.write((byte)0);
lcd.print("C");
// output PID
lcd.setCursor (0, 3);
lcd.print("output: ");
lcd.print(output);
}