Last active
March 18, 2023 23:29
-
-
Save seansplayin/1fe4243a964a7d14c5076a3259aedd52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "uptime_formatter.h" | |
float DTemp1, DTemp2, DTemp3, DTemp4, DTemp5, DTemp6, DTemp7, DTemp8, DTemp9, DTemp10, DTemp11; | |
float DTemp1Average, DTemp2Average, DTemp3Average, DTemp4Average, DTemp5Average, DTemp6Average, DTemp7Average, DTemp8Average, DTemp9Average, DTemp10Average, DTemp11Average; | |
#define BUFFER_SIZE 40 | |
int PT1000Buffer[BUFFER_SIZE]; | |
int PT1000BufferIndex = 0; | |
int PT1000Sum = 0; | |
// Libraries | |
//LCD Library and Settings | |
#include <LiquidCrystal.h> | |
// define pins used by lcd display. | |
//lcd(RS, E, D4, D5, D6, D7) | |
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); | |
//Ethernet Libraries and Settings | |
#include <SPI.h> | |
#include <Ethernet.h> | |
//Set unique MAC address | |
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF }; | |
//Set IP address | |
byte ip[] = { 10, 0, 0, 189 }; | |
EthernetServer server(80); | |
//Libraries needed for Dallas 1-wire thermometers | |
#include <OneWire.h> | |
#include <DallasTemperature.h> | |
//Math Library for log coversion of 10k sensors | |
#include <math.h> | |
//Time and I2C bus libs for Real Time Clock | |
#include <Wire.h> | |
#include <Time.h> | |
#include <DS1307RTC.h> | |
#include <DS3231.h> | |
//Flowmeter | |
#include <FlowMeter.h> // https://github.com/sekdiy/FlowMeter | |
FlowSensorProperties MySensor1 = {45.0f, 19.48f, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}; | |
FlowSensorProperties MySensor2 = {45.0f, 22.50f, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}; | |
FlowSensorProperties MySensor3 = {45.0f, 22.50f, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}; | |
FlowSensorProperties MySensor4 = {45.0f, 19.50f, {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}}; | |
// connect a flow meter to an interrupt pin (see notes on your Arduino model for pin numbers) | |
FlowMeter *Meter1; | |
FlowMeter *Meter2; | |
FlowMeter *Meter3; | |
FlowMeter *Meter4; | |
// set the measurement update period to 1s (1000 ms) | |
const unsigned long period = 1000; | |
// define an 'interrupt service handler' (ISR) for every interrupt pin you use | |
void Meter1ISR() { | |
// let our flow meter count the pulses | |
Meter1->count(); | |
} | |
// define an 'interrupt service handler' (ISR) for every interrupt pin you use | |
void Meter2ISR() { | |
// let our flow meter count the pulses | |
Meter2->count(); | |
} | |
// define an 'interrupt service handler' (ISR) for every interrupt pin you use | |
void Meter3ISR() { | |
// let our flow meter count the pulses | |
Meter3->count(); | |
} | |
// define an 'interrupt service handler' (ISR) for every interrupt pin you use | |
void Meter4ISR() { | |
// let our flow meter count the pulses | |
Meter4->count(); | |
} | |
//G2 Solar functions include | |
#include "G2solarControllerFunctions.h" | |
#include "EthernetWebReport.h" | |
#include <TimeLib.h> | |
// Global | |
void setup() { | |
// analog stuff | |
analogReference(DEFAULT); // 5v | |
// analogReference(INTERNAL2V56); // 2.56v | |
// analogReference(INTERNAL1V1); // 1.1v | |
// flush analog input - - ?? | |
rawPanel12bit = analogRead(pt1000SensorInput); | |
// prep the 2 x 16 char LCD display | |
lcd.begin(2, 16); | |
// prep the relay control pins | |
// setup pins as outputs | |
pinMode (PANEL_LEAD_PUMP_RELAY, OUTPUT); | |
pinMode (PANEL_LAG_PUMP_RELAY, OUTPUT); | |
pinMode (DHW_PUMP_RELAY, OUTPUT); | |
pinMode (STORAGE_HEAT_RELAY, OUTPUT); | |
pinMode (Circ_Pump_Relay, OUTPUT); | |
// set all pumps to off to begin - | |
digitalWrite (PANEL_LEAD_PUMP_RELAY, HIGH); | |
digitalWrite (PANEL_LAG_PUMP_RELAY, HIGH); | |
digitalWrite (DHW_PUMP_RELAY, HIGH); | |
digitalWrite (STORAGE_HEAT_RELAY, HIGH); | |
digitalWrite (Circ_Pump_Relay, HIGH); | |
// setup ethernet | |
Ethernet.begin(mac, ip); | |
server.begin(); | |
//provide power to DS1307 or DS3231 RTC module or | |
pinMode (14, OUTPUT); //Gnd formorly 18 | |
pinMode (15, OUTPUT); //Vcc formorly 19 | |
digitalWrite (14, LOW); //Gnd formorly 18 | |
digitalWrite (15, HIGH); //Vcc formorly 19 | |
// get a new FlowMeter instance for an uncalibrated flow sensor and let them attach their 'interrupt service handler' (ISR) on every rising edge | |
Meter1 = new FlowMeter(digitalPinToInterrupt(2), MySensor1, Meter1ISR, RISING); | |
#define meter1volume (Meter1->getCurrentFlowrate()) | |
// do this setup step for every FlowMeter and ISR you have defined, depending on how many you need | |
Meter2 = new FlowMeter(digitalPinToInterrupt(3), MySensor2, Meter2ISR, RISING); | |
#define meter2volume (Meter2->getCurrentFlowrate()) | |
// do this setup step for every FlowMeter and ISR you have defined, depending on how many you need | |
Meter3 = new FlowMeter(digitalPinToInterrupt(18), MySensor3, Meter3ISR, RISING); | |
#define meter3volume (Meter3->getCurrentFlowrate()) | |
// do this setup step for every FlowMeter and ISR you have defined, depending on how many you need | |
Meter4 = new FlowMeter(digitalPinToInterrupt(19), MySensor4, Meter4ISR, RISING); | |
#define meter4volume (Meter4->getCurrentFlowrate()) | |
#define CollectorTemperatureRise ((CreturnT) - (supplyT)) | |
#define DhwTemperatureDrop ((DhwSupplyT) - (DhwReturnT)) | |
#define HeatingTemperatureDrop ((HeatingSupplyT) - (HeatingReturnT)) | |
#define CirculationTemperatureDrop ((supplyT) - (CircReturnT)) | |
//#define SENSOR_COUNT 11 | |
//#define INVALID_TEMPERATURE -196.6 | |
} | |
void loop() { | |
// get time stamp | |
readTimeDate(); | |
delay(period); | |
// process the (possibly) counted ticks | |
Meter1->tick(period); | |
Meter2->tick(period); | |
Meter3->tick(period); | |
Meter4->tick(period); | |
WebReporting(); | |
// wait between output updates | |
// Read Analog Panel Temp | |
Readpt1000Temperature(); | |
// Read Digital Temps | |
ReadDigitalTemperatures(); | |
outsideT= DTemp3; | |
storageT= DTemp2; | |
dhwT = DTemp1; | |
// CircSupplyT = | |
CircReturnT = DTemp6; | |
supplyT = DTemp5; | |
CreturnT = DTemp4; | |
DhwSupplyT = DTemp7; | |
DhwReturnT = DTemp8; | |
HeatingSupplyT = DTemp9; | |
HeatingReturnT = DTemp10; | |
CSupplyT = DTemp11; | |
//panelT = TempA; | |
//supplyT = TempB; | |
//storageT= TempC; | |
//dhwT = TempD; | |
//outsideT= TempE; | |
panelT = pt1000Average; | |
// Alarm if needed | |
//supplyT = 155; //test alarm high temp | |
//outsideT = -10; //test freeze alarm | |
Alarm(); | |
// PUMP CONTROL: Control Panel Circ, Heat Exchanger Circ and DHW Circ Pumps | |
PumpControl(); | |
//Update Serial Monitor | |
UpdateSerialMonitor(); | |
int measurement = pt1000; | |
addPT1000Measurement(measurement); | |
float PT1000Average = getPT1000Average(); | |
Serial.println(PT1000Average); | |
} | |
void addPT1000Measurement(int measurement) { | |
PT1000Sum -= PT1000Buffer[PT1000BufferIndex]; | |
PT1000Buffer[PT1000BufferIndex] = measurement; | |
PT1000Sum += measurement; | |
PT1000BufferIndex = (PT1000BufferIndex + 1) % BUFFER_SIZE; | |
} | |
float getPT1000Average() { //renamed due to DTemp Algo name conflict | |
return (float)PT1000Sum / BUFFER_SIZE; // Calculate and return the average. | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// client.print(" "); client.print(" "); client.print(" "); client.print(" "); line 527 for the first half. | |
// G2 Solar Controller Web Reporting Function | |
// | |
String readString = ""; // Used to store Form value | |
/* | |
Read web command strings | |
This function checks if any of the web buttons have been selected and sets the | |
Pump state variables appropriately (PumpControl function uses these states to actually control the pumps) | |
*/ | |
void doreadStringAction() | |
{ | |
if (readString.indexOf("?panelleadon") >0) | |
{ | |
state_panel_lead = PUMP_ON; | |
} | |
else | |
{ | |
if (readString.indexOf("?panelleadoff") >0) | |
{ | |
state_panel_lead = PUMP_OFF; | |
} | |
else | |
{ | |
if (readString.indexOf("?panelleadauto") >0) | |
{ | |
state_panel_lead = PUMP_AUTO; | |
} | |
else | |
{ | |
if (readString.indexOf("?panellagon") >0) | |
{ | |
state_panel_lag = PUMP_ON; | |
} | |
else | |
{ | |
if (readString.indexOf("?panellagoff") >0) | |
{ | |
state_panel_lag = PUMP_OFF; | |
} | |
else | |
{ | |
if (readString.indexOf("?panellagauto") >0) | |
{ | |
state_panel_lag = PUMP_AUTO; | |
} | |
else | |
{ | |
if (readString.indexOf("?dhwon") >0) | |
{ | |
state_dhw = PUMP_ON; | |
} | |
else | |
{ | |
if (readString.indexOf("?dhwoff") >0) | |
{ | |
state_dhw = PUMP_OFF; | |
} | |
else | |
{ | |
if (readString.indexOf("?dhwauto") >0) | |
{ | |
state_dhw = PUMP_AUTO; | |
} | |
else | |
{ | |
if (readString.indexOf("?heaton") >0) | |
{ | |
state_heat = PUMP_ON; | |
} | |
else | |
{ | |
if (readString.indexOf("?heatoff") >0) | |
{ | |
state_heat = PUMP_OFF; | |
} | |
else | |
{ | |
if (readString.indexOf("?heatauto") >0) | |
{ | |
state_heat = PUMP_AUTO; | |
} | |
else | |
{ | |
if (readString.indexOf("?circon") >0) | |
{ | |
state_circ = PUMP_ON; | |
} | |
else | |
{ | |
if (readString.indexOf("?circoff") >0) | |
{ | |
state_circ = PUMP_OFF; | |
} | |
else | |
{ | |
if (readString.indexOf("?circauto") >0) | |
{ | |
state_circ = PUMP_AUTO; | |
} | |
else | |
{ | |
if (readString.indexOf("?auto") >0) | |
{ | |
state_panel_lead = PUMP_AUTO; | |
state_panel_lag = PUMP_AUTO; | |
state_dhw = PUMP_AUTO; | |
state_heat = PUMP_AUTO; | |
state_circ = PUMP_AUTO; | |
} | |
else | |
{ | |
if (readString.indexOf("?alloff") >0) | |
{ | |
state_panel_lead = PUMP_OFF; | |
state_panel_lag = PUMP_OFF; | |
state_dhw = PUMP_OFF; | |
state_heat = PUMP_OFF; | |
state_circ = PUMP_OFF; | |
} | |
} | |
} | |
}}}}}}}}}}} | |
} | |
}} | |
} | |
/* | |
Web reporting | |
Provides html to draw the web page and buttons and reports the temps and pump states | |
Updates form values when buttons are pressed to be acted on by doreadStringAction above | |
*/ | |
void WebReporting() { | |
// listen for incoming clients | |
EthernetClient client = server.available(); | |
if ( client ) // then send html to web page | |
{ | |
while (client.connected()) | |
{ | |
if (client.available()) | |
{ // start up the server and get string | |
char c = client.read(); | |
if (readString.length() < 100) | |
{ | |
readString += c; | |
} | |
if (c == '\n') | |
{ | |
client.println("HTTP/1.1 200 OK"); | |
client.println("Content-Type: text/html"); | |
client.println("<html>"); | |
client.println(); | |
// send head | |
client.print("<head>"); | |
client.print("<style type=\"text/css\">"); | |
client.print("body{"); | |
client.print("background-color:#CAD4E0;"); | |
client.print("font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif, Helvetica;"); | |
client.print("font-size:12px;"); | |
client.print("line-height:120%;"); | |
client.print("text-align:left;"); | |
client.print("}"); | |
client.print("h1 {"); | |
client.print("color:#459;"); | |
//client.print("font-family:15px;"); | |
client.print("font-size:30px;"); | |
client.print("line-height:100%;"); | |
client.print("font-weight:bold;"); | |
client.print("}"); | |
client.print("h3 {"); | |
client.print("color:#459;"); | |
client.print("font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif, Helvetica;"); | |
client.print("font-size:14px;"); | |
client.print("line-height:100%;"); | |
client.print("font-weight:bold;"); | |
client.print("}"); | |
client.print("h4 {"); | |
client.print("color:purple;"); | |
client.print("font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif, Helvetica;"); | |
client.print("font-size:11px;"); | |
client.print("line-height:100%;"); | |
client.print("font-weight:bold;"); | |
client.print("text-align:right;"); | |
client.print("}"); | |
client.print("h5 {"); | |
client.print("color:purple;"); | |
client.print("font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif, Helvetica;"); | |
client.print("font-size:11px;"); | |
client.print("line-height:100%;"); | |
client.print("font-weight:bold;"); | |
client.print("text-align:left;"); | |
client.print("}"); | |
client.print("</style>"); | |
client.print("<title>Solar Control System</title>"); | |
client.println("<meta http-equiv=\"refresh\" content=\"6\">"); // This is used to refresh the page | |
client.print("</head>"); | |
// send body | |
client.print("<body>"); | |
client.println(); | |
client.print("<table border=\"10\" cellpadding=\"4\" cellspacing=\"5\">"); | |
client.print("<tr>"); | |
client.print("<td valign=\"Bottom\" bgcolor=\"#0e1117\"><h5> "); | |
client.print("Uptime :"); | |
client.println(uptime_formatter::getUptime()); | |
client.print("</h5></td>"); | |
client.print("<td align=\"center\" bgcolor=\"#0e1117\"><h1 align=\"center\">Solar Thermal System</h1></td>"); | |
client.print("<td valign=\"Bottom\" font-size=\"11px\" align=\"right\" bgcolor=\"#0e1117\"><h4>"); | |
client.print("Alarm state = "); | |
if (ALARM != ALARM_OFF) | |
{ | |
client.print("<span valign=\"Bottom\"align=\"right\"style=\"color:red\">"); | |
client.print(alarmMessage1); | |
client.print(" "); | |
client.println(alarmMessage2); | |
} | |
else | |
{ | |
client.print("<span style=\"color:blue\">"); | |
client.println ("no Alarms"); | |
} | |
client.print("</span></h4>"); | |
client.print("</td>"); | |
client.print("</tr>"); | |
client.print("<tr><td valign=\"top\" width=\"33%\" valign=\"top\" bgcolor=\"#419527\">"); | |
client.print("<h3 align=\"center\">System Temperatures</h3><div style=\"font-size:14px\">"); | |
client.print("Outside Ambient (DTemp3):"); | |
client.print(" "); | |
client.println(outsideT); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("600 Gal Storage (DTemp2):"); | |
client.print(" "); | |
client.println(storageT); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("Collector Manifold (PT1000avg):"); | |
client.print(" "); | |
client.println(panelT); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("Collector Supply (DTemp11):"); | |
client.print(" "); | |
client.println(CSupplyT); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("Collector Return (DTemp6):"); | |
client.print(" "); | |
client.println(CreturnT); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("Domestic HW Tank (DTemp1):"); | |
client.print(" "); | |
client.println(dhwT); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("Domestic HW Supply (DTemp7):"); | |
client.print(" "); | |
client.println(DhwSupplyT); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("Domestic HW Return (DTemp8):"); | |
client.print(" "); | |
client.print(DhwReturnT); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("Circ Loop Supply (DTemp5):"); | |
client.print(" "); | |
client.println(supplyT); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("Circ Loop Return (DTemp4):"); | |
client.print(" "); | |
client.println(CircReturnT); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("Heat Loop Supply (DTemp9):"); | |
client.print(" "); | |
client.println(HeatingSupplyT); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("Heat Loop Return (DTemp10):"); | |
client.print(" "); | |
client.println(HeatingReturnT); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("<br></div>"); | |
client.print("</td><td width=\"34%\" valign=\"top\" bgcolor=\"#419527\">"); | |
client.print("<h3 align=\"center\">Pump Control & Status</h3><div style=\"font-size:14px\">"); | |
client.print("<form>"); | |
client.print("Lead"); | |
client.print(" "); | |
client.print("<INPUT type=button value=ON onClick=window.location='/?panelleadon\'>"); | |
client.print("<INPUT type=button value=OFF onClick=window.location='/?panelleadoff\'>"); | |
client.print("<INPUT type=button value=AUTO onClick=window.location='/?panelleadauto\'>"); | |
client.print(" "); | |
if (state_panel_lead == PUMP_AUTO) | |
{ | |
client.print("AUTO :"); | |
} | |
else | |
{ | |
if (state_panel_lead == PUMP_OFF) | |
{ | |
client.print("OFF :"); | |
} | |
else | |
{ | |
if (state_panel_lead == PUMP_ON) | |
{ | |
client.print("ON :"); | |
} | |
else | |
{ | |
client.print("????"); | |
} | |
} | |
} | |
if (digitalRead(PANEL_LEAD_PUMP_RELAY)) | |
client.print("<span style=\"color:black\"> STOPPED</span>"); else client.print("<span style=\"color:blue; font-weight:bold;\"> POWERED</span>"); | |
client.print("<br>"); | |
client.print("<br>"); | |
client.print("Lag"); | |
client.print(" "); | |
client.print("<INPUT type=button value=ON onClick=window.location='/?panellagon\'>"); | |
client.print("<INPUT type=button value=OFF onClick=window.location='/?panellagoff\'>"); | |
client.print("<INPUT type=button value=AUTO onClick=window.location='/?panellagauto\'>"); | |
client.print(" "); | |
if (state_panel_lag == PUMP_AUTO) | |
{ | |
client.print("AUTO :"); | |
} | |
else | |
{ | |
if (state_panel_lag == PUMP_OFF) | |
{ | |
client.print("OFF :"); | |
} | |
else | |
{ | |
if (state_panel_lag == PUMP_ON) | |
{ | |
client.print("ON :"); | |
} | |
else | |
{ | |
client.print("????"); | |
} | |
} | |
} | |
if (digitalRead(PANEL_LAG_PUMP_RELAY)) | |
client.print("<span style=\"color:black\"> STOPPED</span>"); else client.print("<span style=\"color:blue; font-weight:bold;\"> POWERED</span>"); | |
client.print("<br>"); | |
client.print("<br>"); | |
client.print("DHW"); | |
client.print(" "); | |
client.print("<INPUT type=button value=ON onClick=window.location='/?dhwon\'>"); | |
client.print("<INPUT type=button value=OFF onClick=window.location='/?dhwoff\'>"); | |
client.print("<INPUT type=button value=AUTO onClick=window.location='/?dhwauto\'>"); | |
client.print(" "); | |
if (state_dhw == PUMP_AUTO) | |
{ | |
client.print("AUTO :"); | |
} | |
else | |
{ | |
if (state_dhw == PUMP_OFF) | |
{ | |
client.print("OFF :"); | |
} | |
else | |
{ | |
if (state_dhw == PUMP_ON) | |
{ | |
client.print("ON :"); | |
} | |
else | |
{ | |
client.print("????"); | |
} | |
} | |
} | |
if (digitalRead(DHW_PUMP_RELAY)) | |
client.print("<span style=\"color:black\"> STOPPED</span>"); else client.print("<span style=\"color:blue; font-weight:bold;\"> POWERED</span>"); | |
client.print("<br>"); | |
client.print("<br>"); | |
client.print("Heat"); | |
client.print(" "); | |
client.print("<INPUT type=button value=ON onClick=window.location='/?heaton\'>"); | |
client.print("<INPUT type=button value=OFF onClick=window.location='/?heatoff\'>"); | |
client.print("<INPUT type=button value=AUTO onClick=window.location='/?heatauto\'>"); | |
client.print(" "); | |
if (state_heat == PUMP_AUTO) | |
{ | |
client.print("AUTO :"); | |
} | |
else | |
{ | |
if (state_heat == PUMP_OFF) | |
{ | |
client.print("OFF :"); | |
} | |
else | |
{ | |
if (state_heat == PUMP_ON) | |
{ | |
client.print("ON :"); | |
} | |
else | |
{ | |
client.print("????"); | |
} | |
} | |
} | |
if (digitalRead(STORAGE_HEAT_RELAY)) | |
client.print("<span style=\"color:black\"> STOPPED</span>"); else client.print("<span style=\"color:blue; font-weight:bold;\"> POWERED</span>"); | |
client.print("<br>"); | |
client.print("<br>"); | |
client.print("Circ"); | |
client.print(" "); | |
client.print("<INPUT type=button value=ON onClick=window.location='/?circon\'>"); | |
client.print("<INPUT type=button value=OFF onClick=window.location='/?circoff\'>"); | |
client.print("<INPUT type=button value=AUTO onClick=window.location='/?circauto\'>"); | |
client.print(" "); | |
if (state_circ == PUMP_AUTO) | |
{ | |
client.print("AUTO :"); | |
} | |
else | |
{ | |
if (state_circ == PUMP_OFF) | |
{ | |
client.print("OFF :"); | |
} | |
else | |
{ | |
if (state_circ == PUMP_ON) | |
{ | |
client.print("ON :"); | |
} | |
else | |
{ | |
client.print("????"); | |
} | |
} | |
} | |
if (digitalRead(Circ_Pump_Relay)) | |
client.print("<span style=\"color:black\"> STOPPED</span>"); else client.print("<span style=\"color:blue; font-weight:bold;\"> POWERED</span>"); | |
client.print("<br>"); | |
client.print("<br>"); | |
//client.print("      <input type=button value=\"CLEAR\" onClick=window.location=\'/\'>"); | |
client.print("Circulators <input type=button value=\"CLEAR\" onClick=window.location=\'/\'>"); | |
client.print(" <input type=button value=\"ALL OFF\" onClick=window.location=\'/?alloff\'>"); | |
client.print(" <input type=button value=\"ALL AUTO\" onClick=window.location=\'/?auto\'>"); | |
client.print("</form></div>"); | |
client.print("</td><td valign=\"top\" width=\"33%\" valign=\"top\" bgcolor=\"#419527\">"); | |
client.print("<h3 align=\"center\">not used</h3><div style=\"font-size:14px\">"); | |
client.print("<br></div>"); | |
client.print("</td>"); | |
client.print("<tr><td valign=\"top\" bgcolor=\"#419527\">"); | |
client.print("<h3 align=\"center\">Temp Sensors</h3><div style=\"font-size:14px\">"); | |
client.print("pt1000 Temp: "); | |
client.println(pt1000); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("pt1000 Average: "); | |
client.println(pt1000Average); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("DTemp1:"); | |
client.print(" "); | |
client.println(DTemp1); | |
client.print("°"); | |
client.print(" "); | |
client.print("DTemp1Average:"); | |
client.print(" "); | |
client.println(DTemp1Average); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("DTemp2:"); | |
client.print(" "); | |
client.println(DTemp2); | |
client.print("°"); | |
client.print(" "); | |
client.print("DTemp2Average:"); | |
client.print(" "); | |
client.println(DTemp2Average); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("DTemp3:"); | |
client.print(" "); | |
client.println(DTemp3); | |
client.print("°"); | |
client.print(" "); | |
client.print("DTemp3Average:"); | |
client.print(" "); | |
client.println(DTemp3Average); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("DTemp4:"); | |
client.print(" "); | |
client.println(DTemp4); | |
client.print("°"); | |
client.print(" "); | |
client.print("DTemp4Average:"); | |
client.print(" "); | |
client.println(DTemp4Average); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("DTemp5:"); | |
client.print(" "); | |
client.println(DTemp5); | |
client.print("°"); | |
client.print(" "); | |
client.print("DTemp5Average:"); | |
client.print(" "); | |
client.println(DTemp5Average); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("DTemp6:"); | |
client.print(" "); | |
client.println(DTemp6); | |
client.print("°"); | |
client.print(" "); | |
client.print("DTemp6Average:"); | |
client.print(" "); | |
client.println(DTemp6Average); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("DTemp7:"); | |
client.print(" "); | |
client.println(DTemp7); | |
client.print("°"); | |
client.print(" "); | |
client.print("DTemp7Average:"); | |
client.print(" "); | |
client.println(DTemp7Average); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("DTemp8:"); | |
client.print(" "); | |
client.println(DTemp8); | |
client.print("°"); | |
client.print(" "); | |
client.print("DTemp8Average:"); | |
client.print(" "); | |
client.println(DTemp8Average); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("DTemp9:"); | |
client.print(" "); | |
client.println(DTemp9); | |
client.print("°"); | |
client.print(" "); | |
client.print("DTemp9Average:"); | |
client.print(" "); | |
client.println(DTemp9Average); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("DTemp10:"); | |
client.print(" "); | |
client.println(DTemp10); | |
client.print("°"); | |
client.print(" "); | |
client.print("DTemp10Average:"); | |
client.print(" "); | |
client.println(DTemp10Average); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("DTemp11:"); | |
client.print(" "); | |
client.println(DTemp11); | |
client.print("°"); | |
client.print(" "); | |
client.print("DTemp11Average:"); | |
client.print(" "); | |
client.println(DTemp11Average); | |
client.print("°"); | |
client.print("<br>"); | |
client.print("<br></div>"); | |
client.print("</td><td valign=\"top\" bgcolor=\"#419527\">"); | |
client.print("<h3 align=\"center\">Information</h3><div style=\"font-size:14px\">"); | |
//client.print("<span style=\"color:purple; font-weight:bold;\">"); | |
//client.print(timeDate); | |
//client.print("</span><br>"); | |
client.print("<br>"); | |
//client.print("<span style=\"color:black; font-weight:;\">"); | |
//client.print("Uptime "); | |
//client.print("</span>"); | |
//client.print("<span style=\"color:purple; font-weight:;\">"); | |
//client.println(uptime_formatter::getUptime()); | |
//client.print("</span><br>"); | |
//client.print("Alarm state = "); | |
//if (ALARM != ALARM_OFF) | |
// { | |
//client.print("<span style=\"color:red\">"); | |
//client.print(alarmMessage1); | |
//client.print(" "); | |
//client.println(alarmMessage2); | |
//} | |
//else | |
//{ | |
//client.print("<span style=\"color:blue\">"); | |
//client.println ("no Alarms"); | |
//} | |
// client.print("</span>"); | |
//client.print("<br>"); | |
client.print("Min Lead Start Temp(PT1000):"); | |
client.print(" "); | |
client.print(panelTminimum); // Manifold must achieve this temperature in addition to the supply vs panelT setting | |
client.print("°"); | |
client.print("<br>"); | |
client.print("Lead On Diff.(PT1000 vs DTemp5):"); | |
client.print(" "); | |
client.print(PanelOnDifferential); // Panels must be this much warmer than sUpply to turn on pumps | |
client.print("°"); | |
client.print("<br>"); | |
client.print("Lag On Diff.(Dtemp6 vs DTemp11):"); | |
client.print(" "); | |
client.print(PanelLowDifferential); // If Panels are only this much warmer, run slower | |
client.print("°"); | |
client.print("<br>"); | |
client.print("Lead Off Diff.(PT1000 vs DTemp5):"); | |
client.print(" "); | |
client.print(PanelOffDifferential); // If Panels are only this much warmer, turn off | |
client.print("°"); | |
client.print("<br>"); | |
client.print("Lead Min Temp Enable(PT1000):"); | |
client.print(" "); | |
client.print(FREEZE_LIMIT); // don't operate if outside temp is below this temperature | |
client.print("°"); | |
client.print("<br>"); | |
client.print("<br>"); | |
client.print("DHW On Diff. (DTemp2 vs DTemp1):"); | |
client.print(" "); | |
client.print(HotWaterOnDifferential); // Storage must be this much warmer than dhw to turn on pump | |
client.print("°"); | |
client.print("<br>"); | |
client.print("DHW Off Diff. (DTemp2 vs DTemp1):"); | |
client.print(" "); | |
client.print(HotWaterOffDifferential); // If Storage is only this much warmer than dhw, turn off pump | |
client.print("°"); | |
client.print("<br>"); | |
client.print("DHW Tank High Temp Limit:"); | |
client.print(" "); | |
client.print(DHW_HIGHTEMP_LIMIT ); // shut off when this temperature is reached | |
client.print("°"); | |
client.print("<br>"); | |
client.print("<br>"); | |
client.print("Heating Min Temp (DTemp2):"); | |
client.print(" "); | |
client.print(StorageTooCold ); // If Storage isn't hot enough, don't run heat exch pump | |
client.print("°"); | |
client.print("<br>"); | |
client.print("Storage Tank High Limit:"); | |
client.print(" "); | |
client.print(HIGHTEMP_LIMIT ); // shut off when this temperature is reached | |
client.print("°"); | |
client.print("<br>"); | |
client.print("<br>"); | |
client.print("Circ Loop On Diff.(DTemp5 vs DTemp4):"); | |
client.print(" "); | |
client.print(Circ_Pump_On); //turn on circulation pump when deltaT hits this temperature | |
client.print("°"); | |
client.print("<br>"); | |
client.print("Circ Loop Off Diff.(DTemp5 vs DTemp4):"); | |
client.print(" "); | |
client.print(Circ_Pump_Off); //turn off circualtion pump when deltaT hits this temperature | |
client.print("°"); | |
client.print("<br>"); | |
client.print("<br></div>"); | |
client.print("</td><td valign=\"top\" width=\"33%\" valign=\"top\" bgcolor=\"#419527\">"); | |
client.print("<h3 align=\"center\">Energy</h3><div style=\"font-size:14px\">"); | |
client.print("<br>"); | |
client.print ("<div>"); | |
client.print("Collectors Heat Gain:"); | |
client.print(" "); | |
if ((iii) <= (500*((meter1volume) /3.785411784)*(CreturnT-CSupplyT))) | |
{ | |
client.print ("<span style=\"color:blue\"</span>"); | |
client.println ((500*((meter1volume) /3.785411784)*(CreturnT-CSupplyT)) /1000); | |
client.print ("Kbtu "); | |
client.println ((500*((meter1volume) /3.785411784)*(CreturnT-CSupplyT)) / (3412.141633)); | |
client.print ("KW"); | |
} | |
else if ((ii) > (500*((meter1volume) /3.785411784)*(CreturnT-CSupplyT))) | |
{ | |
client.print ("<span style=\"color:red\"</span>"); | |
client.println ((500*((meter1volume) /3.785411784)*(CreturnT-CSupplyT)) /1000); | |
client.print ("Kbtu "); | |
client.println ((500*((meter1volume) /3.785411784)*(CreturnT-CSupplyT)) / (3412.141633)); | |
client.print ("KW"); | |
} | |
else | |
{ | |
client.println ((500*((meter1volume) /3.785411784)*(CreturnT-CSupplyT)) /1000); | |
client.print ("Kbtu "); | |
client.println ((500*((meter1volume) /3.785411784)*(CreturnT-CSupplyT)) / (3412.141633)); | |
client.print ("KW"); | |
} | |
client.print("<br>"); | |
client.print ("</div>"); | |
client.print ("<div>"); | |
client.print("Collectors Temp Rise:"); | |
client.print(" "); | |
if (digitalRead(PANEL_LEAD_PUMP_RELAY) == 0) | |
{ | |
client.print ("<span style=\"color:blue\"</span>"); | |
client.println(CreturnT-CSupplyT); | |
} else { | |
client.print("0"); | |
} | |
client.print("°"); | |
client.print("<br>"); | |
client.print ("</div>"); | |
client.print ("<div>"); | |
client.print("Collectors Flow Rate:"); | |
client.print(" "); | |
//client.println(Meter1->getCurrentFlowrate()); | |
// client.println(meter1volume); | |
if ((iii) <= (meter1volume)) | |
{ | |
client.print ("<span style=\"color:blue\"</span>"); | |
client.println (meter1volume); | |
} | |
else | |
{ | |
client.println (meter1volume); | |
} | |
client.print("L/m"); | |
client.print(" "); | |
if ((iii) <= (meter1volume)) | |
{ | |
client.println ((meter1volume) /3.785411784); | |
} | |
else | |
{ | |
client.println ((meter1volume) /3.785411784); | |
} | |
client.print("G/m"); | |
client.print ("</div>"); | |
client.print("<br>"); | |
client.print ("<div>"); | |
client.print("DHW Heat Loss:"); | |
client.print(" "); | |
if ((iii) <= (500*((meter2volume) /3.785411784)*(DhwSupplyT-DhwReturnT))) | |
{ | |
client.print ("<span style=\"color:blue\"</span>"); | |
client.println ((500*((meter2volume) /3.785411784)*(DhwSupplyT-DhwReturnT)) /1000); | |
client.print ("Kbtu "); | |
client.println ((500*((meter2volume) /3.785411784)*(DhwSupplyT-DhwReturnT)) / (3412.141633)); | |
client.print ("KW"); | |
} | |
else | |
{ | |
client.println ((500*((meter2volume) /3.785411784)*(DhwSupplyT-DhwReturnT)) /1000); | |
client.print ("Kbtu "); | |
client.println ((500*((meter2volume) /3.785411784)*(DhwSupplyT-DhwReturnT)) / (3412.141633)); | |
client.print ("KW"); | |
} | |
client.print("<br>"); | |
client.print ("</div>"); | |
client.print ("<div>"); | |
client.print("DHW Temp Drop:"); | |
client.print(" "); | |
if (digitalRead(DHW_PUMP_RELAY) == 0) | |
{ | |
client.print ("<span style=\"color:blue\"</span>"); | |
client.println(DhwSupplyT-DhwReturnT); | |
} else { | |
client.print("0"); | |
} | |
client.print("°"); | |
client.print("<br>"); | |
client.print ("</div>"); | |
client.print ("<div>"); | |
client.print("DHW Loop Flow Rate: "); | |
if ((iii) <= (meter2volume)) | |
{ | |
client.print ("<span style=\"color:blue\"</span>"); | |
client.println (meter2volume); | |
} | |
else | |
{ | |
client.println (meter2volume); | |
} | |
client.print("L/m"); | |
client.print(" "); | |
if ((iii) <= (meter2volume)) | |
{ | |
client.println ((meter2volume) /3.785411784); | |
} | |
else | |
{ | |
client.println ((meter2volume) /3.785411784); | |
} | |
client.print("G/m"); | |
client.print ("</div>"); | |
client.print("<br>"); | |
client.print ("<div>"); | |
client.print("Heating Heat Loss:"); | |
client.print(" "); | |
if ((iii) <= (500*((meter3volume) /3.785411784)*(HeatingSupplyT-HeatingReturnT))) | |
{ | |
client.print ("<span style=\"color:blue\"</span>"); | |
client.println ((500*((meter3volume) /3.785411784)*(HeatingSupplyT-HeatingReturnT)) /1000); | |
client.print ("Kbtu "); | |
client.println ((500*((meter3volume) /3.785411784)*(HeatingSupplyT-HeatingReturnT)) / (3412.141633)); | |
client.print ("KW"); | |
} | |
else | |
{ | |
client.println ((500*((meter3volume) /3.785411784)*(HeatingSupplyT-HeatingReturnT)) /1000); | |
client.print ("Kbtu "); | |
client.println ((500*((meter3volume) /3.785411784)*(HeatingSupplyT-HeatingReturnT)) / (3412.141633)); | |
client.print ("KW"); | |
} | |
client.print("<br>"); | |
client.print ("</div>"); | |
client.print ("<div>"); | |
client.print("Heating Temp Drop:"); | |
client.print(" "); | |
if (digitalRead(STORAGE_HEAT_RELAY) == 0) | |
{ | |
client.print ("<span style=\"color:blue\"</span>"); | |
client.println(HeatingSupplyT-HeatingReturnT); | |
} else { | |
client.print("0"); | |
} | |
client.print("°"); | |
client.print("<br>"); | |
client.print ("</div>"); | |
client.print ("<div>"); | |
client.print("Heating Loop Flow Rate: "); | |
//client.println(Meter3->getCurrentFlowrate()); | |
//client.println(meter3volume); | |
if ((iii) <= (meter3volume)) | |
{ | |
client.print ("<span style=\"color:blue\"</span>"); | |
client.println (meter3volume); | |
} | |
else | |
{ | |
client.println (meter3volume); | |
} | |
client.print("L/m"); | |
client.print(" "); | |
if ((iii) <= (meter3volume)) | |
{ | |
client.println ((meter3volume) /3.785411784); | |
} | |
else | |
{ | |
client.println ((meter3volume) /3.785411784); | |
} | |
client.print("G/m"); | |
client.print ("</div>"); | |
client.print("<br>"); | |
client.print ("<div>"); | |
client.print("Circ Loop Heat Loss:"); | |
client.print(" "); | |
if ((iii) <= (500*((meter4volume) /3.785411784)*(supplyT-CircReturnT))) | |
{ | |
client.print ("<span style=\"color:blue\"</span>"); | |
client.println ((500*((meter4volume) /3.785411784)*(supplyT-CircReturnT)) /1000); | |
client.print ("Kbtu "); | |
client.println ((500*((meter4volume) /3.785411784)*(supplyT-CircReturnT)) / (3412.141633)); | |
client.print ("KW"); | |
} | |
else | |
{ | |
client.println ((500*((meter4volume) /3.785411784)*(supplyT-CircReturnT)) /1000); | |
client.print ("Kbtu "); | |
client.println ((500*((meter4volume) /3.785411784)*(supplyT-CircReturnT)) / (3412.141633)); | |
client.print ("KW"); | |
} | |
client.print("<br>"); | |
client.print ("</div>"); | |
client.print ("<div>"); | |
client.print("Circ Loop Temp Drop:"); | |
client.print(" "); | |
if (digitalRead(Circ_Pump_Relay) == 0) | |
{ | |
client.print ("<span style=\"color:blue\"</span>"); | |
client.println(supplyT-CircReturnT); | |
} else { | |
client.print("0"); | |
} | |
client.print("°"); | |
client.print("<br>"); | |
client.print("</div>"); | |
client.print ("<div>"); | |
client.print("Circ Loop Flow Rate: "); | |
//client.println(Meter4->getCurrentFlowrate()); | |
//client.println(meter4volume); | |
if ((iii) <= (meter4volume)) | |
{ | |
client.print ("<span style=\"color:blue\"</span>"); | |
client.println (meter4volume); | |
} | |
else | |
{ | |
client.println (meter4volume); | |
} | |
client.print("L/m"); | |
client.print(" "); | |
if ((iii) <= (meter4volume)) | |
{ | |
client.println ((meter4volume) /3.785411784); | |
} | |
else | |
{ | |
client.println ((meter4volume) /3.785411784); | |
} | |
client.print("G/m"); | |
client.print ("</div>"); | |
client.print("<br>"); | |
client.print("</td>"); | |
client.print("</tr>"); | |
client.print("</table>"); | |
client.println("</body></html>"); | |
Serial.println(readString); | |
doreadStringAction(); | |
readString = ""; | |
client.stop(); | |
} | |
} | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// G2 Solar Controller Function Calls - | |
// | |
int rawPanel12bit; | |
float panelTminimum; //minimum temperature manifold must achieve to turn on lead pump | |
float panelT; | |
float dhwT; | |
float storageT; | |
float supplyT; //water going to the collectors | |
float outsideT; | |
float CreturnT; //water returing from the collectors | |
float DhwSupplyT; //water going to the DHW | |
float DhwReturnT; //water returning from the DHW | |
float HeatingSupplyT; //water going to the heating loop | |
float HeatingReturnT; //water returing from the heating loop | |
float CircReturnT; //water returing from the circulating pump | |
float CSupplyT; //water going to collectors read from after the pumps | |
int pt1000; | |
//float DTemp1; | |
//float DTemp2; | |
//float DTemp3; | |
//float DTemp4; | |
//float DTemp5; | |
//float DTemp6; | |
//float DTemp7; | |
//float DTemp8; | |
//float DTemp9; | |
//float DTemp10; | |
float CollectorTemperatureRise; | |
float DhwTemperatureDrop; | |
float HeatingTemperatureDrop; | |
float CirculationTemperatureDrop; | |
String timeDate; | |
// define pins | |
#define pt1000SensorInput A15 //Analog pin where pt1000 is connected | |
#define pt1000Average (getPT1000Average()) | |
// pump relay control pins | |
#define Circ_Pump_Relay 37 | |
#define PANEL_LEAD_PUMP_RELAY 39 | |
#define PANEL_LAG_PUMP_RELAY 41 | |
#define DHW_PUMP_RELAY 43 | |
#define STORAGE_HEAT_RELAY 45 | |
#define PanelOnDifferential 30 // Panels must be this much warmer than sUpply to turn on pumps | |
#define PanelLowDifferential 15 // If Panels are only this much warmer, run slower | |
#define PanelOffDifferential 1 // If Panels are only this much warmer, turn off | |
#define HotWaterOnDifferential 12 // Storage must be this much warmer than dhw to turn on pump | |
#define HotWaterOffDifferential 8 // If Storage is only this much warmer than dhw, turn off pump | |
#define StorageTooCold 125 // If Storage isn't hot enough, don't let heat exch pump run | |
#define DHW_HIGHTEMP_LIMIT 150 // shut off DHW Pump when this temperature is reached in DHW storage tank | |
#define HIGHTEMP_LIMIT 176 // shut off when this temperature is reached in storage tank | |
#define FREEZE_LIMIT 50 // don't operate if Collector Average temp is below this temperature | |
#define Circ_Pump_On 4 // temperature difference when circulation pump comes on | |
#define Circ_Pump_Off 2 // temperature difference when circulation pump turns off | |
#define Circ_Loop_Differential ((supplyT) - (CircReturnT)) | |
#define Collector_Temperature_Rise ((CreturnT) - (supplyT)) | |
#define panelTminimum 125 // lead pump on criteria, minimum manifold temp in addition to collector vs supply requirement | |
#define meter1volume (Meter1->getCurrentFlowrate()) | |
#define meter2volume (Meter2->getCurrentFlowrate()) | |
#define meter3volume (Meter3->getCurrentFlowrate()) | |
#define meter4volume (Meter4->getCurrentFlowrate()) | |
int ii = 0; | |
int iii = 1; | |
// Alarm state values | |
#define ALARM_OFF 0 | |
#define ALARM_FREEZE 1 | |
#define ALARM_HOT 2 | |
int ALARM = ALARM_OFF; // Alarm value, set to off initially | |
String alarmMessage1; // Alarm message in 2 lines to fit LCD | |
String alarmMessage2; | |
// pump state values | |
#define PUMP_OFF 0 | |
#define PUMP_ON 1 | |
#define PUMP_AUTO 2 | |
// pump state - 0 off, 1 on, 2 auto as controlled by ButtonControl or web page function | |
int state_panel_lead = PUMP_AUTO; // default to auto allows temperature logic to control pumps | |
int state_panel_lag = PUMP_AUTO; | |
int state_dhw = PUMP_AUTO; | |
int state_heat = PUMP_AUTO; | |
int state_circ = PUMP_AUTO; | |
// lcd button value | |
int lcd_key = 0; | |
// One Wire Bus Settings - plugged into pin 47 on the Arduino MEGA (was on 53 but ethernet calls were somehow stomping on that pin) | |
const int ONE_WIRE_BUS = 47; | |
const int TEMPERATURE_PRECISION = 12; | |
// setup digital oneWire sensor addresses | |
DeviceAddress DSensor1 = {0x28, 0xF1, 0x15, 0x48, 0xF6, 0xCD, 0x3C, 0x75}; | |
DeviceAddress DSensor2 = {0x28, 0x69, 0x9A, 0x48, 0xF6, 0x7A, 0x3C, 0xAD}; | |
DeviceAddress DSensor3 = {0x28, 0x52, 0x16, 0x96, 0xF0, 0x01, 0x3C, 0x02}; | |
DeviceAddress DSensor4 = {0x28, 0xDD, 0x9B, 0x96, 0xF0, 0x01, 0x3C, 0xEB}; | |
DeviceAddress DSensor5 = {0x28, 0xE5, 0x91, 0x96, 0xF0, 0x01, 0x3C, 0x1A}; | |
DeviceAddress DSensor6 = {0x28, 0x85, 0xEA, 0x81, 0xE3, 0x2B, 0x3C, 0xF2}; | |
DeviceAddress DSensor7 = {0x28, 0x29, 0x1A, 0x81, 0xE3, 0x53, 0x3C, 0xB5}; | |
DeviceAddress DSensor8 = {0x28, 0x22, 0xC6, 0x81, 0xE3, 0x17, 0x3C, 0x92}; | |
DeviceAddress DSensor9 = {0x28, 0x66, 0xF1, 0x81, 0xE3, 0xD2, 0x3C, 0xA5}; | |
DeviceAddress DSensor10 = {0x28, 0x22, 0x14, 0x81, 0xE3, 0xDC, 0x3C, 0xD8}; | |
DeviceAddress DSensor11 = {0x28, 0x37, 0x16, 0x49, 0xF6, 0x0D, 0x3C, 0x2D}; | |
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) | |
OneWire oneWire(ONE_WIRE_BUS); | |
// Pass our oneWire reference to Dallas Temperature. | |
DallasTemperature sensors(&oneWire); | |
// Functions | |
/* | |
Analog read of pt1000 RTD sensor | |
*/ | |
void Readpt1000Temperature() | |
{ | |
// read analog input | |
rawPanel12bit = analogRead(pt1000SensorInput); | |
//adjust raw value | |
// int val = constrain(rawPanel12bit, 700, 1000); | |
int val = constrain(rawPanel12bit, 300, 600); | |
//map 12 bit digital values to temperature in degrees F | |
// 12bitvalue of 775 = 35deg, 910 = 181deg - values from digital pin power and 2.56v ref | |
// panelT = map(val, 775, 910, 35, 181); | |
// 12bitvalue of 391 = 15deg, 472 = 186deg - values from analog reference to divider and default ref | |
pt1000 = map(val, 392, 463, 17, 155); | |
} | |
/* | |
Digital read of DS18B20 one-wire bus sensors | |
*/ | |
void ReadDigitalTemperatures() | |
{ | |
// call sensors.requestTemperatures() to issue a global temperature | |
// request to all devices on the bus | |
sensors.requestTemperatures(); | |
// get temperatures from devices | |
DTemp1 = sensors.getTempF(DSensor1); | |
DTemp2 = sensors.getTempF(DSensor2); | |
DTemp3 = sensors.getTempF(DSensor3); | |
DTemp4 = sensors.getTempF(DSensor4); | |
DTemp5 = sensors.getTempF(DSensor5); | |
DTemp6 = sensors.getTempF(DSensor6); | |
DTemp7 = sensors.getTempF(DSensor7); | |
DTemp8 = sensors.getTempF(DSensor8); | |
DTemp9 = sensors.getTempF(DSensor9); | |
DTemp10 = sensors.getTempF(DSensor10); | |
DTemp11 = sensors.getTempF(DSensor11); | |
} | |
/* | |
build golbal timeDate text string with time and date for serial monitor and web reporting | |
*/ | |
void readTimeDate() //builds timeDate string from RTC reads | |
{ | |
String m; | |
int t; | |
tmElements_t tm; | |
if (RTC.read(tm)) | |
{ | |
timeDate ="Time: "; | |
t=tm.Hour; //hours | |
m="AM"; | |
if ( t > 12) | |
{ | |
t=t-12; | |
m="PM"; | |
} | |
if (t < 10){ | |
timeDate = timeDate + "0" + t + ":"; | |
} else { | |
timeDate = timeDate + t + ":"; | |
} | |
t = tm.Minute; //minutes | |
if (t < 10){ | |
timeDate = timeDate + "0" + t + ":"; | |
} else { | |
timeDate = timeDate + t + ":"; | |
} | |
t = tm.Second; //seconds | |
if (t < 10){ | |
timeDate = timeDate + "0" + t + " "; | |
} else { | |
timeDate = timeDate + t + " "; | |
} | |
timeDate = timeDate + m + ", Date: "; //append AM or PM | |
t = tm.Month; //Month | |
timeDate = timeDate + t + '/'; | |
t = tm.Day; //Day | |
timeDate = timeDate + t + '/'; | |
t = tmYearToCalendar(tm.Year); | |
timeDate = timeDate + t; | |
} else { | |
if (RTC.chipPresent()) | |
{ | |
Serial.println("The DS1307 is stopped. Please run the SetTime"); | |
Serial.println("example to initialize the time and begin running."); | |
Serial.println(); | |
} else | |
{ | |
Serial.println("DS1307 read error! Please check the circuitry."); | |
Serial.println(); | |
} | |
delay(9000); | |
} | |
} | |
/* | |
Report all time and values to the Serial Monitor | |
*/ | |
void UpdateSerialMonitor() | |
{ | |
//print time stamp | |
//Serial.println(timeDate); | |
//show temps | |
// Serial.print("10k A Temp = "); | |
//Serial.println(TempA); | |
//Serial.print("10k B Temp = "); | |
//Serial.println(TempB); | |
//Serial.print("10k C Temp = "); | |
//Serial.println(TempC); | |
//Serial.print("10k D Temp = "); | |
//Serial.println(TempD); | |
//Serial.print("10k E Temp = "); | |
//Serial.println(TempE); | |
//Serial.println(); | |
//Serial.print("pt1000 Temp = "); | |
//Serial.println(pt1000); | |
//Serial.println(); | |
//Serial.print("D 1 Temp = "); | |
//Serial.println(DTemp1); | |
//Serial.print("D 2 Temp = "); | |
//Serial.println(DTemp2); | |
//Serial.print("D 3 Temp = "); | |
//Serial.println(DTemp3); | |
//Serial.print("D 4 Temp = "); | |
//Serial.println(DTemp4); | |
//Serial.print("D 5 Temp = "); | |
//Serial.println(DTemp5); | |
//Serial.print("D 6 Temp = "); | |
//Serial.println(DTemp6); | |
//Serial.print("D 7 Temp = "); | |
//Serial.println(DTemp7); | |
//Serial.print("D 8 Temp = "); | |
//Serial.println(DTemp8); | |
//Serial.print("D 9 Temp = "); | |
//Serial.println(DTemp9); | |
//Serial.print("D 10 Temp = "); | |
//Serial.println(DTemp10); | |
//Serial.println(); | |
//Serial.print("Panel Temperature = "); | |
//Serial.println(panelT); | |
//Serial.print("sUpply Temperature = "); | |
//Serial.println(supplyT); | |
//Serial.print("Creturn Temperature = "); | |
//Serial.println(CreturnT); | |
//Serial.print("Outside Temperature = "); | |
//Serial.println(outsideT); | |
//Serial.print("Storage Temperature = "); | |
//Serial.println(storageT); | |
//Serial.print("DHW Tank Temperature = "); | |
//Serial.println(dhwT); | |
//Serial.print("DHW Supply Temperature = "); | |
//Serial.println(DhwSupplyT); | |
//Serial.print("DHW Return Temperature = "); | |
//Serial.println(DhwReturnT); | |
//Serial.print("Heating Supply Temperature = "); | |
//Serial.println(HeatingSupplyT); | |
//Serial.print("Heating Return Temperature = "); | |
//Serial.println(HeatingReturnT); | |
//Serial.print("Circulation Supply = "); | |
//Serial.println(supplyT); | |
//Serial.print("Circulation Return = "); | |
//Serial.println(CircReturnT); | |
//Serial.println(); | |
//Serial.print("Panel Pump Status Lag/Lead = "); | |
//if (digitalRead(PANEL_LAG_PUMP_RELAY)) | |
//Serial.print( "OFF"); else Serial.print("ON"); | |
//Serial.print(" , "); | |
//if (digitalRead(PANEL_LEAD_PUMP_RELAY)) | |
//Serial.println( "OFF"); else Serial.println("ON"); | |
//Serial.print("DHW Pump Status = "); | |
//if (digitalRead(DHW_PUMP_RELAY)) | |
//Serial.println( "OFF"); else Serial.println("ON"); | |
//Serial.print("Heat Exch Pump Status = "); | |
//if (digitalRead(STORAGE_HEAT_RELAY)) | |
//Serial.println( "OFF"); else Serial.println("ON"); | |
//Serial.print("Circ Loop Pump Status = "); | |
//if (digitalRead(Circ_Pump_Relay)) | |
//Serial.println( "OFF"); else Serial.println("ON"); | |
//Serial.print("Alarm state = "); | |
//if (ALARM != ALARM_OFF) | |
//{ | |
//Serial.print(alarmMessage1); | |
//Serial.print(" "); | |
//Serial.println(alarmMessage2); | |
//} | |
//else Serial.println ("no Alarms"); | |
//Serial.println(); | |
//Serial.println(); | |
} | |
/* | |
Write Temps to LCD. | |
*/ | |
/* | |
Check for any Alarm conditions and if found, turn off panel pumps and set Alarm and Message | |
*/ | |
void Alarm() | |
{ | |
if (storageT >= HIGHTEMP_LIMIT) | |
{ | |
ALARM = ALARM_HOT; | |
alarmMessage1 = "Storage at"; | |
alarmMessage2 = "High Limit"; | |
// ensure panel pumps are off (they should be anyway) | |
if (state_panel_lead == PUMP_AUTO) digitalWrite (PANEL_LEAD_PUMP_RELAY, HIGH); | |
if (state_panel_lag == PUMP_AUTO) digitalWrite (PANEL_LAG_PUMP_RELAY, HIGH); | |
} | |
else if (pt1000Average <= FREEZE_LIMIT) | |
{ | |
ALARM = ALARM_FREEZE; | |
alarmMessage1 = "Collector Manifold"; | |
alarmMessage2 = "Too Cold"; | |
// ensure panel pumps are off | |
if (state_panel_lead == PUMP_AUTO) digitalWrite (PANEL_LEAD_PUMP_RELAY, HIGH); | |
if (state_panel_lag == PUMP_AUTO) digitalWrite (PANEL_LAG_PUMP_RELAY, HIGH); | |
} | |
else if (dhwT >= DHW_HIGHTEMP_LIMIT) | |
{ | |
ALARM = ALARM_HOT; | |
alarmMessage1 = "DHW at"; | |
alarmMessage2 = "High Limit"; | |
// ensure panel pumps are off | |
if (state_dhw == PUMP_AUTO) digitalWrite (DHW_PUMP_RELAY, HIGH); | |
} | |
// add check for water level | |
// | |
else ALARM = ALARM_OFF; | |
if (ALARM != ALARM_OFF) | |
{ | |
// report to LCD display | |
lcd.clear(); | |
lcd.setCursor (0, 0); | |
lcd.print (alarmMessage1); | |
lcd.setCursor (0, 1); | |
lcd.print (alarmMessage2); | |
delay(1000); //delay so you can see alarm message | |
} | |
} | |
/* | |
DF Robot LCD shield Read Button routine | |
*/ | |
/* | |
Read Buttons for User Control of Pumps | |
*/ | |
// Differential Temperature Pump Control | |
void PumpControl() | |
{ | |
//if (panelT > (supplyT + PanelOnDifferential) ) | |
// { | |
// state_panel_lead = PUMP_ON; | |
// state_panel_lag = PUMP_ON; | |
//} | |
//else | |
//{ | |
// manual panel lead pump control: | |
if (state_panel_lead == PUMP_ON) digitalWrite (PANEL_LEAD_PUMP_RELAY, LOW); | |
else { | |
if (state_panel_lead == PUMP_OFF) digitalWrite (PANEL_LEAD_PUMP_RELAY, HIGH); | |
else { | |
// auto panel lead pump control: | |
// if no alarms | |
// set control pin to LOW to turn relay on, HIGH to turn relay off | |
// turn on if panel vs supply differential is greater than turnOnDifferential, checking for button override | |
if (ALARM == ALARM_OFF) | |
{ | |
if (panelT >= panelTminimum && (panelT > (supplyT + PanelOnDifferential))) | |
{ | |
digitalWrite (PANEL_LEAD_PUMP_RELAY, LOW); | |
digitalWrite (PANEL_LAG_PUMP_RELAY, LOW); | |
} | |
} | |
}} | |
//} | |
// manual panel lag pump control: | |
if (state_panel_lag == PUMP_ON) digitalWrite (PANEL_LAG_PUMP_RELAY, LOW); | |
else { | |
if (state_panel_lag == PUMP_OFF) digitalWrite (PANEL_LAG_PUMP_RELAY, HIGH); | |
else { | |
// auto panel lead pump control: | |
//turn off lag pump if differential is down far enough or back on if risen enough | |
if (!digitalRead(PANEL_LEAD_PUMP_RELAY)) //if the lead pump is running | |
{ | |
//if (panelT < (supplyT + PanelLowDifferential) ){ | |
if (Collector_Temperature_Rise < (PanelLowDifferential) ){ | |
digitalWrite (PANEL_LAG_PUMP_RELAY, HIGH); | |
} else { | |
digitalWrite (PANEL_LAG_PUMP_RELAY, LOW); | |
} | |
} | |
}} | |
//turn off both pumps if differential is less than turnOffDifferential | |
if (panelT < (supplyT + PanelOffDifferential) ){ | |
//if (Collector_Temperature_Rise < (PanelOffDifferential) ){ | |
if (state_panel_lead == PUMP_AUTO) digitalWrite (PANEL_LEAD_PUMP_RELAY, HIGH); | |
if (state_panel_lag == PUMP_AUTO) digitalWrite (PANEL_LAG_PUMP_RELAY, HIGH); | |
} | |
// manual dhw pump control | |
if (state_dhw == PUMP_ON) | |
{ | |
digitalWrite (DHW_PUMP_RELAY, LOW); | |
} else { | |
if (state_dhw == PUMP_OFF) | |
{ | |
digitalWrite (DHW_PUMP_RELAY, HIGH); | |
} else { | |
// auto control: turn on DHW Pump when storage enough warmer | |
if (storageT > (dhwT + HotWaterOnDifferential)) { | |
digitalWrite (DHW_PUMP_RELAY, LOW); | |
} | |
if (storageT < (dhwT + HotWaterOffDifferential)) { | |
digitalWrite (DHW_PUMP_RELAY, HIGH); | |
}}} | |
// manual heat exchanger pump control | |
if (state_heat == PUMP_ON) | |
{ | |
digitalWrite (STORAGE_HEAT_RELAY, LOW); | |
} else { | |
if (state_heat == PUMP_OFF) | |
{ | |
digitalWrite (STORAGE_HEAT_RELAY, HIGH); | |
} else { | |
// auto control: prevent forced air heat exchanger pump from coming on if storage is too low | |
if (storageT > (StorageTooCold)) { | |
digitalWrite (STORAGE_HEAT_RELAY, LOW); | |
} | |
if (storageT < (StorageTooCold)) { | |
digitalWrite (STORAGE_HEAT_RELAY, HIGH); | |
}} | |
} | |
// manual Circ pump control | |
if (state_circ == PUMP_ON) | |
{ | |
digitalWrite (Circ_Pump_Relay, LOW); | |
} else { | |
if (state_circ == PUMP_OFF) | |
{ | |
digitalWrite (Circ_Pump_Relay, HIGH); | |
} else { | |
if (!digitalRead(DHW_PUMP_RELAY)) | |
{ | |
digitalWrite (Circ_Pump_Relay, HIGH); | |
} else { | |
if (!digitalRead(STORAGE_HEAT_RELAY)) | |
{ | |
digitalWrite (Circ_Pump_Relay, HIGH); | |
} else { | |
// auto control: turn on Circ Pump when CircReturnT =< supplyT + 15 | |
if (Circ_Pump_On <= (Circ_Loop_Differential)) { | |
digitalWrite (Circ_Pump_Relay, LOW); | |
} | |
if (Circ_Pump_Off >= (Circ_Loop_Differential)) { | |
digitalWrite (Circ_Pump_Relay, HIGH); | |
}} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment