firmware - add FAN2 PWM setting

This commit is contained in:
DeltaLima 2024-12-08 14:12:26 +01:00
parent 61c7af5eb5
commit 5df2d0f4ab
6 changed files with 39 additions and 10 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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;

View file

@ -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);
}

View file

@ -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";

View file

@ -509,16 +509,20 @@ void WEBgrowSettings() {
}
if(UseFANrelais == false) {
body += "FAN speed: <input type='range' id='PinFANPWM' name='PinFANPWM' min='0' max='255' value='";
body += "FAN1 speed: <input type='range' id='PinFANPWM' name='PinFANPWM' min='0' max='255' value='";
body += PinFANPWM;
body += "'/> %<br>\n";
} else {
body += "FAN on/off: <select id='PinFANPWM' name='PinFANPWM' required>\n";
body += "FAN1 on/off: <select id='PinFANPWM' name='PinFANPWM' required>\n";
body += "<option value='1'" + returnStrSelected(PinFANPWM, 1) + ">On</option>\n";
body += "<option value='0'" + returnStrSelected(PinFANPWM, 0) + ">Off</option>\n";
body += "</select><br>\n";
}
body += "FAN2 speed: <input type='range' id='PinFAN2PWM' name='PinFAN2PWM' min='0' max='255' value='";
body += PinFAN2PWM;
body += "'/> %<br>\n";
body += "Pump interval vegetation: every <input class='inputShort' type='number' name='PumpIntervalVeg' min='0' max='255' value='";
body += PumpIntervalVeg;
@ -773,6 +777,7 @@ void POSTgrowSettings() {
PinLEDPWM = webserver.arg("PinLEDPWM").toInt();
PinFANPWM = webserver.arg("PinFANPWM").toInt();
PinFAN2PWM = webserver.arg("PinFAN2PWM").toInt();
String GrowName_tmp = webserver.arg("GrowName");
GrowName_tmp.toCharArray(GrowName, 32);
@ -809,6 +814,8 @@ void POSTgrowSettings() {
EEPROM.put(213, PinLEDPWM);
// size is 1 byte
EEPROM.put(216, PinFANPWM);
// size is 1 byte
EEPROM.put(248, PinFAN2PWM);
EEPROM.put(217, SunFade);
EEPROM.put(218, SunFadeDuration);
// size is 1 byte
@ -845,6 +852,8 @@ void POSTgrowSettings() {
Serial.println(PinLEDPWM);
Serial.print("PinFANPWM: ");
Serial.println(PinFANPWM);
Serial.print("PinFAN2PWM: ");
Serial.println(PinFAN2PWM);
webserver.sendHeader("Location", String("/growSettings?success"), true);
webserver.send(302, "text/plain", "growSettings/save: success!\n");