diff --git a/firmware/weckkubator/weckkubator.ino b/firmware/weckkubator/weckkubator.ino index 1a48d32..a467f53 100644 --- a/firmware/weckkubator/weckkubator.ino +++ b/firmware/weckkubator/weckkubator.ino @@ -2,67 +2,28 @@ #include // Support for PCF8574 --> LCD #include // 1-Wiresupport for DS18B20 #include // Easy reading of DS18B20 -#include // PID-Controller #define ONE_WIRE_BUS 10 // Enable 1-Wirebus on digital 10 (PB2 - Pin16) -#define fan 8 -#define wecktopf 9 LiquidCrystal_I2C lcd(0x3F,20,4); // declare LCD OneWire oneWire(ONE_WIRE_BUS); // declare 1-Wirebus DallasTemperature sensors(&oneWire); // declare sensors -// Define variables PID is connected to -double pidset, watertemp, output; - -// PID adjustment -double Kp=2, Ki=5, Kd=1; -PID myPID(&watertemp, &output, &pidset, Kp, Ki, Kd, DIRECT); -int WindowSize = 5000; -unsigned long windowStartTime; - -// Temp adjustment -int tempset; +float tempset; +float watertemp; int poti; -// time -int onesecond = 1000; -unsigned long previousMillis; - - -// °C for LCD -byte customChar[8] = { - 0b01110, - 0b01010, - 0b01010, - 0b01110, - 0b00000, - 0b00000, - 0b00000, - 0b00000 -}; - void setup() { - // Setup GPIO - pinMode(wecktopf, OUTPUT); // Output "Wecktopf" - pinMode(fan, OUTPUT); // Fan - + pinMode(9, OUTPUT); // Output "Wecktopf" + pinMode(8, OUTPUT); // Fan // Setup sensors sensors.begin(); - // Setup I2C-LCD lcd.init(); lcd.backlight(); lcd.clear(); - lcd.createChar(0, customChar); lcd.setCursor(1, 0); - - // 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 - // Greetings lcd.print("Weckkubator 0.0.1"); delay(3000); @@ -71,34 +32,23 @@ void setup() { } void loop() { + // + settemp(); + readtemp(); + lcdoutput(); - // run pid - pid(); + delay(100); + + if (tempset >= watertemp) { + digitalWrite(9, HIGH); - // update LCD - unsigned long currentMillis = millis(); - if (currentMillis - previousMillis >= onesecond) { - settemp(); - readtemp(); - lcdoutput(); + } -} + else { + digitalWrite(9, LOW); -//------------------------------------------ -// PID-Controller -void pid() { - - myPID.Compute(); - - /************************************************ - * turn the output pin on/off based on pid output - ************************************************/ - if (millis() - windowStartTime > WindowSize) - { //time to shift the Relay Window - windowStartTime += WindowSize; } - if (output < millis() - windowStartTime) digitalWrite(wecktopf, LOW); - else digitalWrite(wecktopf, HIGH); + } //------------------------------------------ @@ -118,32 +68,18 @@ void readtemp() { void lcdoutput() { // Output temperatureset lcd.setCursor(0, 1); - lcd.print("set: "); + lcd.print("s:"); lcd.print(tempset); - lcd.write((byte)0); - lcd.print("C"); // Output watertemp - lcd.setCursor(0, 2); - lcd.print("temp: "); + lcd.setCursor(9, 1); + lcd.print("t:"); lcd.print(watertemp); - lcd.write((byte)0); - lcd.print("C"); - lcd.print(" "); - - // output PID - lcd.setCursor (0, 3); - lcd.print("output: "); - lcd.print(output); - lcd.print(" "); - } - //------------------------------------------ // Read Poti void settemp() { poti = analogRead(A3); - tempset = (18+(poti*0.07)); // range between 18°C and 18+1024*0,07 (~89°C) - pidset = tempset; + tempset = (poti*0.1); }