firmware wip - swap PINfan and PINpump, according to PCB
set analogWriteFreq to 220Hz. This was so far the sweetspot for Fan PWM control in combination with a 47µF electrolyt capacitor. If I had a PWM pin free, i would use PWM functionality of pc fans but all pins are in use. So I went with putting a capacitor to the output and regulate the fan speed this way.
This commit is contained in:
parent
ace7c8b678
commit
ae72fe6188
1 changed files with 78 additions and 14 deletions
|
@ -707,8 +707,10 @@ bool loadEEPROM() {
|
|||
*
|
||||
* -- afterwards added, need to sort --
|
||||
*
|
||||
* 213 UseLEDrelais
|
||||
* 213 PINled_PWM
|
||||
* 214 TemperatureSensor_Type
|
||||
* 215 UseFANrelais
|
||||
* 216 PINfan_PWM
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -768,7 +770,13 @@ bool loadEEPROM() {
|
|||
// I forgot to add TemperatureSensor_Type to EEPROM and noticed it
|
||||
// quite late in the process of programming. So this value residents
|
||||
// in 214 and not directly after UseLEDrelais
|
||||
EEPROM.get(213, PINled_PWM);
|
||||
// size is 1 byte
|
||||
EEPROM.get(214, TemperatureSensor_Type);
|
||||
// size is 1 byte
|
||||
EEPROM.get(215, UseFANrelais);
|
||||
// size is 1 byte
|
||||
EEPROM.get(216, PINfan_PWM);
|
||||
}
|
||||
// TODO auth does not work atm
|
||||
// EEPROM.get(160, WebUiUsername);
|
||||
|
@ -798,14 +806,6 @@ bool loadEEPROM() {
|
|||
// size is 1 byte
|
||||
EEPROM.get(212, DayOfGrow);
|
||||
|
||||
// to ensure PINled_PWM always set to 255 when UseLEDrelais is true
|
||||
// we set it here again, does not matter whats stored.
|
||||
// size is 1 byte
|
||||
if(UseLEDrelais == true) {
|
||||
PINled_PWM = 255;
|
||||
} else {
|
||||
EEPROM.get(213, PINled_PWM);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -837,6 +837,8 @@ bool loadEEPROM() {
|
|||
Serial.println(ntpOffset);
|
||||
Serial.print("UseLEDrelais: ");
|
||||
Serial.println(UseLEDrelais);
|
||||
Serial.print("UseFANrelais: ");
|
||||
Serial.println(UseFANrelais);
|
||||
|
||||
Serial.println("---- Grow values ----");
|
||||
Serial.print("GrowName: ");
|
||||
|
@ -859,6 +861,8 @@ bool loadEEPROM() {
|
|||
Serial.println(DayOfGrow);
|
||||
Serial.print("PINled_PWM: ");
|
||||
Serial.println(PINled_PWM);
|
||||
Serial.print("PINfan_PWM: ");
|
||||
Serial.println(PINfan_PWM);
|
||||
|
||||
|
||||
} else {
|
||||
|
@ -972,6 +976,9 @@ void setup() {
|
|||
digitalWrite(PINled, LOW);
|
||||
digitalWrite(PINpump, LOW);
|
||||
|
||||
// set frequency lower to avoid annoying noises
|
||||
analogWriteFreq(220);
|
||||
|
||||
// Start Serial
|
||||
Serial.begin(115200);
|
||||
|
||||
|
@ -1438,8 +1445,14 @@ void WEBroot() {
|
|||
body += "<option disabled value='' selected hidden>---</option>\n";
|
||||
body += "<option value='1'>On</option>\n";
|
||||
body += "<option value='0'>Off</option>\n";
|
||||
|
||||
body += "</select><br>\n";
|
||||
|
||||
if(UseFANrelais == false) {
|
||||
body += "Speed FAN: <input type='range' id='PINfan_PWM' name='PINfan_PWM' min='1' max='255' value='";
|
||||
body += PINfan_PWM;
|
||||
body += "'/><br>\n";
|
||||
}
|
||||
|
||||
body += "<input type='submit' value='Save'>\n";
|
||||
body += "</form>";
|
||||
|
||||
|
@ -1569,6 +1582,13 @@ void WEBsystemSettings() {
|
|||
body += "<option value='0'" + returnStrSelected(UseLEDrelais, 0) + ">No</option>\n";
|
||||
body += "</select><br>\n";
|
||||
|
||||
// UseFANrelais bool
|
||||
body += "Use relais for FAN: <select id='UseFANrelais' name='UseFANrelais' required>\n";
|
||||
if(configured == false){body += "<option disabled value='' selected hidden>---</option>\n";}
|
||||
body += "<option value='1'" + returnStrSelected(UseFANrelais, 1) + ">Yes</option>\n";
|
||||
body += "<option value='0'" + returnStrSelected(UseFANrelais, 0) + ">No</option>\n";
|
||||
body += "</select><br>\n";
|
||||
|
||||
// TODO ugly. can this done be better?
|
||||
// PumpOnTime int
|
||||
body += "Pump on time: <input type='number' name='PumpOnTime' min='0' max='255' value='";
|
||||
|
@ -1687,6 +1707,12 @@ void WEBgrowSettings() {
|
|||
body += "'/><br>\n";
|
||||
}
|
||||
|
||||
if(UseFANrelais == false) {
|
||||
body += "Speed FAN: <input type='range' id='PINfan_PWM' name='PINfan_PWM' min='1' max='255' value='";
|
||||
body += PINfan_PWM;
|
||||
body += "'/><br>\n";
|
||||
}
|
||||
|
||||
body += "<input type='submit' value='Save'>\n";
|
||||
body += "</form>\n";
|
||||
body += FPSTR(JSconvertDateToEpoch);
|
||||
|
@ -1713,6 +1739,14 @@ void POSTgrowSettings() {
|
|||
PINled_PWM = webserver.arg("PINled_PWM").toInt();
|
||||
}
|
||||
|
||||
if(UseFANrelais == true) {
|
||||
// if a relais is used to turn on grow light, we force PWM to max val
|
||||
PINfan_PWM = 255;
|
||||
} else {
|
||||
// otherwise just do PWM
|
||||
PINfan_PWM = webserver.arg("PINfan_PWM").toInt();
|
||||
}
|
||||
|
||||
String GrowName_tmp = webserver.arg("GrowName");
|
||||
GrowName_tmp.toCharArray(GrowName, 32);
|
||||
|
||||
|
@ -1743,6 +1777,9 @@ void POSTgrowSettings() {
|
|||
EEPROM.put(211, SunriseMinute);
|
||||
// size is 1 byte
|
||||
EEPROM.put(213, PINled_PWM);
|
||||
// size is 1 byte
|
||||
EEPROM.put(216, PINfan_PWM);
|
||||
|
||||
|
||||
EEPROM.commit();
|
||||
|
||||
|
@ -1771,6 +1808,8 @@ void POSTgrowSettings() {
|
|||
Serial.println(SunriseMinute);
|
||||
Serial.print("PINled_PWM: ");
|
||||
Serial.println(PINled_PWM);
|
||||
Serial.print("PINfan_PWM: ");
|
||||
Serial.println(PINfan_PWM);
|
||||
|
||||
webserver.sendHeader("Location", String("/growSettings?success"), true);
|
||||
webserver.send(302, "text/plain", "growSettings/save: success!\n");
|
||||
|
@ -1785,6 +1824,7 @@ void POSTsystemSettings() {
|
|||
PumpOnTime = webserver.arg("PumpOnTime").toInt();
|
||||
UseFan = webserver.arg("UseFan").toInt();
|
||||
UseLEDrelais = webserver.arg("UseLEDrelais").toInt();
|
||||
UseFANrelais = webserver.arg("UseFANrelais").toInt();
|
||||
TemperatureSensor_Type = webserver.arg("TemperatureSensor_Type").toInt();
|
||||
|
||||
configured = true;
|
||||
|
@ -1807,6 +1847,8 @@ void POSTsystemSettings() {
|
|||
EEPROM.put(169, UseLEDrelais);
|
||||
// size is 1 byte
|
||||
EEPROM.put(214, TemperatureSensor_Type);
|
||||
// size is 1 byte
|
||||
EEPROM.put(215, UseFANrelais);
|
||||
|
||||
// write data to EEPROM
|
||||
EEPROM.commit();
|
||||
|
@ -1828,6 +1870,13 @@ void POSTsystemSettings() {
|
|||
Serial.println("UseLEDrelais is 1, forcing PINled_PWM to max to prevent relais damage");
|
||||
}
|
||||
|
||||
if(UseFANrelais == true) {
|
||||
PINfan_PWM = 255;
|
||||
EEPROM.put(215, PINfan_PWM);
|
||||
EEPROM.commit();
|
||||
Serial.println("UseFANrelais is 1, forcing PINfan_PWM to max to prevent relais damage");
|
||||
}
|
||||
|
||||
Serial.print("configured: ");
|
||||
Serial.println(configured);
|
||||
Serial.print("UseFan: ");
|
||||
|
@ -1844,6 +1893,8 @@ void POSTsystemSettings() {
|
|||
Serial.println(ntpOffset);
|
||||
Serial.print("UseLEDrelais: ");
|
||||
Serial.println(UseLEDrelais);
|
||||
Serial.print("UseFANrelais: ");
|
||||
Serial.println(UseFANrelais);
|
||||
Serial.print("TemperatureSensor_Type: ");
|
||||
Serial.println(TemperatureSensor_Type);
|
||||
|
||||
|
@ -1922,6 +1973,7 @@ void POSTwifiSettings() {
|
|||
void POSTswitchMOSFET() {
|
||||
byte MosfetState = webserver.arg("state").toInt();
|
||||
byte MosfetNr = webserver.arg("output").toInt();
|
||||
byte PINfan_PWM = webserver.arg("PINfan_PWM").toInt();
|
||||
|
||||
Serial.println(":: GETswitchMOSFET ::");
|
||||
Serial.print("MosfetState: ");
|
||||
|
@ -1934,8 +1986,12 @@ void POSTswitchMOSFET() {
|
|||
} else {
|
||||
switch(MosfetNr) {
|
||||
case 1:
|
||||
if( MosfetState == 1) {
|
||||
analogWrite(PINled, PINled_PWM);
|
||||
if(MosfetState == 1) {
|
||||
if(UseLEDrelais == true) {
|
||||
digitalWrite(PINled, MosfetState);
|
||||
} else {
|
||||
analogWrite(PINled, PINled_PWM);
|
||||
}
|
||||
} else {
|
||||
digitalWrite(PINled, MosfetState);
|
||||
}
|
||||
|
@ -1944,7 +2000,15 @@ void POSTswitchMOSFET() {
|
|||
digitalWrite(PINpump, MosfetState);
|
||||
break;
|
||||
case 3:
|
||||
digitalWrite(PINfan, MosfetState);
|
||||
if(MosfetState == 1) {
|
||||
if(UseFANrelais == true) {
|
||||
digitalWrite(PINfan, MosfetState);
|
||||
} else {
|
||||
analogWrite(PINfan, PINfan_PWM);
|
||||
}
|
||||
} else {
|
||||
digitalWrite(PINfan, MosfetState);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
webserver.send(400, "text/plain", "not valid\n");
|
||||
|
@ -1996,7 +2060,7 @@ void APIgetSensors() {
|
|||
* - PWM for fan control
|
||||
* - avoid using javascript to set the GrowName in the Menu and the time
|
||||
* as well
|
||||
* -
|
||||
* - rework UseLEDrelais usage
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue