From 5df2d0f4ab1b1864181953771b093bff1b368ca9 Mon Sep 17 00:00:00 2001 From: DeltaLima Date: Sun, 8 Dec 2024 14:12:26 +0100 Subject: [PATCH] firmware - add FAN2 PWM setting --- Arduino/CanGrow/CanGrow.ino | 3 +++ Arduino/CanGrow/CanGrow_Init.h | 5 +++-- Arduino/CanGrow/CanGrow_PinAssignments.h | 5 +++-- Arduino/CanGrow/CanGrow_SysFunctions.h | 21 ++++++++++++++++++--- Arduino/CanGrow/CanGrow_Version.h | 2 +- Arduino/CanGrow/CanGrow_WebFunctions.h | 13 +++++++++++-- 6 files changed, 39 insertions(+), 10 deletions(-) diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino index 9659204..4f969e6 100644 --- a/Arduino/CanGrow/CanGrow.ino +++ b/Arduino/CanGrow/CanGrow.ino @@ -64,6 +64,7 @@ void setup() { //pinMode(PINdht, INPUT); pinMode(PINwaterlevel, OUTPUT); pinMode(PINsoilmoisture, OUTPUT); + pinMode(PinFAN2, OUTPUT); pinMode(PinWIPE, OUTPUT); // set all OUTPUT to low @@ -76,6 +77,8 @@ void setup() { // except PINsoilmoisture // PINsoilmoisture is always HIGH and gets LOW in moment of waterlevel measurement digitalWrite(PINsoilmoisture, HIGH); + // set FAN2 to off with digitalWrite LOW + analogWrite(PinFAN2, PinFAN2PWM); // set PWM frequency to 13.37KHz analogWriteFreq(13370); diff --git a/Arduino/CanGrow/CanGrow_Init.h b/Arduino/CanGrow/CanGrow_Init.h index ab1e466..4632880 100644 --- a/Arduino/CanGrow/CanGrow_Init.h +++ b/Arduino/CanGrow/CanGrow_Init.h @@ -141,8 +141,9 @@ byte SunriseHour = 7; byte SunriseMinute = 0; // PinLEDPWM - contains the PWM value for dimming the grow light // default is 255 to ensure it is just on for the case UseLEDrelais is true -byte PinLEDPWM = 255; -byte PinFANPWM = 255; +byte PinLEDPWM = 0; +byte PinFANPWM = 0; +byte PinFAN2PWM = 0; // fade in and out sunrise and sunset? bool SunFade; diff --git a/Arduino/CanGrow/CanGrow_PinAssignments.h b/Arduino/CanGrow/CanGrow_PinAssignments.h index 2c274a6..f7270e6 100644 --- a/Arduino/CanGrow/CanGrow_PinAssignments.h +++ b/Arduino/CanGrow/CanGrow_PinAssignments.h @@ -4,9 +4,9 @@ * * D0 - MOSFET Pump * D1, D2 - I2C - * D3 - DHT11 + * D3 - Fan2 PWM * D4 - PinWIPE - * D5 - MOSFET Fan + * D5 - MOSFET Fan1, PWM * D6 - MOSFET Grow LED, PWM * D7 - waterlevel (set HIGH to read value) * D8 - analog soil moisture (set HIGH to read value) @@ -24,6 +24,7 @@ const uint8_t PinPUMP = D0; // DO NOT PULL D4 DOWN AT WHEN POWERING ON !!! BOOT WILL FAIL const uint8_t PinWIPE = D4; const uint8_t PinFAN = D5; +const uint8_t PinFAN2 = D3; const uint8_t PinLED = D6; // const uint8_t PINwaterlevel = D7; const uint8_t PINsoilmoisture = D8; diff --git a/Arduino/CanGrow/CanGrow_SysFunctions.h b/Arduino/CanGrow/CanGrow_SysFunctions.h index e5d2e3e..9af08f6 100644 --- a/Arduino/CanGrow/CanGrow_SysFunctions.h +++ b/Arduino/CanGrow/CanGrow_SysFunctions.h @@ -110,7 +110,8 @@ bool loadEEPROM() { * 243 OutputInvert (1 byte) * 244 SoilmoistureWet (2 byte) * 246 SoilmoistureDry (2 byte) - * 248 ... + * 248 PinFAN2PWM (1 byte) + * 249 ... * */ @@ -220,6 +221,8 @@ bool loadEEPROM() { EEPROM.get(241, PumpIntervalVeg); // size is 1 byte EEPROM.get(242, PumpIntervalBloom); + // size is 1 byte + EEPROM.get(248, PinFAN2PWM); } @@ -290,6 +293,8 @@ bool loadEEPROM() { Serial.println(PinLEDPWM); Serial.print("PinFANPWM: "); Serial.println(PinFANPWM); + Serial.print("PinFAN2PWM: "); + Serial.println(PinFAN2PWM); Serial.print("SunFade: "); Serial.println(SunFade); Serial.print("SunFadeDuration: "); @@ -417,6 +422,7 @@ void setOutput(byte Output, byte OutputState) { * 1 - LED * 2 - FAN * 3 - PUMP + * 4 - FAN2 * */ bool UseRelais = true; @@ -444,6 +450,10 @@ void setOutput(byte Output, byte OutputState) { case 3: OutputPin = PinPUMP; break; + case 4: + OutputPin = PinFAN2; + UseRelais = false; + break; } //~ Serial.print("Output: "); @@ -467,7 +477,9 @@ void setOutput(byte Output, byte OutputState) { } digitalWrite(OutputPin, OutputState_tmp); } else { - if(OutputInvert == true) { + // when OutputInvert is set true AND output is not Fan2, invert + // for the 4-pin Fan PWM we dont need to invert, this could + if( (OutputInvert == true) && (OutputPin != PinFAN2) ) { OutputState_tmp = 255 - OutputState; } else { OutputState_tmp = OutputState; @@ -785,6 +797,9 @@ void controlPUMP() { void controlFAN() { - setOutput(2, PinFANPWM); //inverted pwm + // FAN1 + setOutput(2, PinFANPWM); + // FAN2 + setOutput(4, PinFAN2PWM); } diff --git a/Arduino/CanGrow/CanGrow_Version.h b/Arduino/CanGrow/CanGrow_Version.h index ed23ee4..b152786 100644 --- a/Arduino/CanGrow/CanGrow_Version.h +++ b/Arduino/CanGrow/CanGrow_Version.h @@ -1,5 +1,5 @@ /* CanGrow_Version.h gets generated from cangrow.sh */ const char* CanGrowVer = "0.1-dev"; -const char* CanGrowBuild = "d782cae-20241205044935"; +const char* CanGrowBuild = "61c7af5-20241208140924"; diff --git a/Arduino/CanGrow/CanGrow_WebFunctions.h b/Arduino/CanGrow/CanGrow_WebFunctions.h index 302a3f7..07e2c4a 100644 --- a/Arduino/CanGrow/CanGrow_WebFunctions.h +++ b/Arduino/CanGrow/CanGrow_WebFunctions.h @@ -509,16 +509,20 @@ void WEBgrowSettings() { } if(UseFANrelais == false) { - body += "FAN speed: %
\n"; } else { - body += "FAN on/off: \n"; body += "\n"; body += "\n"; body += "
\n"; } + body += "FAN2 speed: %
\n"; + body += "Pump interval vegetation: every