Show Posts
|
|
Pages: [1]
|
|
1
|
Using Arduino / Networking, Protocols, and Devices / Re: Ethernet lockups/freezes/non responsive
|
on: June 11, 2013, 09:21:45 pm
|
Thank you very much for your reply SurferTim. Sorry it took so long for me to reply. I merged my code into the code you suggested and uploaded to the Mega. i will let you know the outcome. Again....thanks Below is the merged code //web stuff
EthernetClient client = monserver.available(); if(client) { boolean currentLineIsBlank = true; boolean currentLineIsGet = true; int tCount = 0; char tBuf[64]; int r,t; char *pch;
Serial.print(F("Client request: "));
// this controls the timeout int loopCount = 0;
while (client.connected()) { while(client.available()) { // if packet, reset loopCount loopCount = 0; char c = client.read();
if(currentLineIsGet && tCount < 63) { tBuf[tCount] = c; tCount++; tBuf[tCount] = 0; }
if (c == '\n' && currentLineIsBlank) { // send a standard http response Serial.println(tBuf); Serial.print(F("POST data: ")); while(client.available()) Serial.write(client.read()); Serial.println();
pch = strtok(tBuf,"?");
while(pch != NULL) { if(strncmp(pch,"t=",2) == 0) { t = atoi(pch+2); Serial.print("t="); Serial.println(t,DEC); }
if(strncmp(pch,"r=",2) == 0) { r = atoi(pch+2); Serial.print("r="); Serial.println(r,DEC); }
pch = strtok(NULL,"& "); } Serial.println(F("Sending response")); client.print(F("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<html>"));
client.print("<title>HVAC monitor</title>");
client.println("<h1>HVAC monitor</h1>"); client.println("<hr />"); client.println("<hr />");
//TOD DateTime now = RTC.now();
client.print(now.year(), DEC); client.print('/'); client.print(now.month(), DEC); client.print('/'); client.print(now.day(), DEC); client.print(' '); client.print(now.hour(), DEC); client.print(':'); client.print(now.minute(), DEC); client.print(':'); client.print(now.second(), DEC); client.println(); client.println();
client.println("<table>"); client.println("<table border='1'>"); client.print("<tr><td>OWB_Supply_Temp"); client.print("</td><td>"); client.print(OWB_supply_temp ); client.print((char)176); client.print("F"); client.print("</td><td>"); client.print("pool heated temp"); client.print("</td><td>"); client.print(pool_heated_temp ); client.print((char)176); client.print("F"); client.println("</td></tr>");
client.print("<tr><td>OWB_Return_Temp"); client.print("</td><td>"); client.print(OWB_return_temp ); client.print((char)176); client.print("F"); client.print("</td><td>"); client.print("pool unheated temp"); client.print("</td><td>"); client.print(pool_unheated_temp ); client.print((char)176); client.print("F"); client.println("</td></tr>"); client.println("</table>");
client.print("<p><font color='#339900' size=’5′>Outside air temp (front porch) = "); client.print(OAT ); client.print((char)176); client.print("F"); client.print("</p>");
OWB_Temp_House_DIFFERENCE = OWB_DWT - EWT; client.print("<p><font color='#339900' size=’5′>Outside air temp (at the OWB) = "); client.print(OWB_OAT ); client.print((char)176); client.print("F"); client.print("</p>");
client.print("<p>Space temperature(Great room) = "); client.print(temp_f ); client.print((char)176); client.print("F"); client.print("</p>");
client.print("<p>Space Humidity(Great room) = "); client.print(humidity); client.print("%"); client.print("</p>");
client.print("<p> Boiler water temperature (in the house) = "); client.print(EWT ); client.print((char)176); client.print("F"); client.print("</p>");
client.print("<p>OWB water temperature (at the OWB) = "); client.print(OWB_DWT ); client.print((char)176); client.print("F"); client.print("</p>");
client.print("<p>TEMP difference between the OWB and the H20 temp in the house = "); client.print(OWB_Temp_House_DIFFERENCE ); client.print((char)176); client.print("F"); client.print("</p>");
client.print("<p>Number of XBee modem status messages = "); client.print(modemstatus ); client.print("</p>");
if (digitalRead(blowerRunning) == LOW) { client.println("<p>The blower is running"); } else { client.println("<p>The blower is off"); } client.print("</p>"); client.print("<p>Discharge air temperature is = "); client.print(DAT ); client.print((char)176); client.print("F"); client.print("</p>");
client.print("<p>DX suction line temp is = "); client.print(DSLT ); client.print((char)176); client.print("F"); client.print("</p>");
client.println("<hr />"); client.println("Debug info"); client.println("<hr />"); client.println(); client.println(); client.println("<p>Thermostat data"); client.print("</p>");
if (digitalRead(rTstatPin) == LOW) { client.println("<p>R = 24Vac"); } else { client.println("<p>R = 0Vac"); } client.print("</p>");
if (digitalRead(yTstatPin) == LOW) { client.println("<p>Y = 24Vac"); } else { client.println("<p>Y = 0Vac"); } client.print("</p>");
if (digitalRead(wTstatPin) == LOW) { client.println("<p>W = 24Vac"); } else { client.println("<p>W = 0Vac"); } client.print("</p>");
if (digitalRead(gTstatPin) == LOW) { client.println("<p>G = 24Vac"); } else { client.println("<p>G = 0Vac"); } client.print("</p>");
client.print("<p>Highest boiler water temperature = "); client.print(HWT ); client.print((char)176); client.print("F"); client.print("</p>");
client.print("<p>Lowest boiler water temperature = "); client.print(LWT ); client.print((char)176); client.print("F"); client.print("</p>");
client.print("<p>Highest discharge air temperature = "); client.print(max_DAT ); client.print((char)176); client.print("F"); client.print("</p>");
client.print("<p>EWT EC = "); //display the EWT errors client.print(EC ); client.print("</p>");
client.print("<p>SHT15 reads = "); //display the SHT reads client.print(num_SHT_reads ); client.print("</p>");
client.print("<p>Each sensor was read "); client.print(numReadings); client.print(" times"); client.print("</p>");
client.print("</HTML>"); client.stop(); } else if (c == '\n') { currentLineIsBlank = true; currentLineIsGet = false; } else if (c != '\r') { currentLineIsBlank = false; } }
loopCount++;
// if 10000ms has passed since last packet if(loopCount > 10000) { // close connection client.stop(); Serial.println("\r\nTimeout"); }
// delay 1ms for timeout timing delay(1); } Serial.println(F("done")); } //end web stuff }
|
|
|
|
|
2
|
Using Arduino / Networking, Protocols, and Devices / Re: Ethernet lockups/freezes/non responsive
|
on: June 10, 2013, 09:48:15 pm
|
for sure the rest of the code //web stuff
EthernetClient client = monserver.available(); if (client) { // an http request ends with a blank line boolean current_line_is_blank = true; while (client.connected()) { if (client.available()) { char c = client.read(); // if we've gotten to the end of the line (received a newline // character) and the line is blank, the http request has ended, // so we can send a reply if (c == '\n' && current_line_is_blank) { // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(); client.println("<HTML>"); client.print("<title>HVAC monitor</title>");
client.println("<h1>HVAC monitor</h1>"); client.println("<hr />"); client.println("<hr />");
//TOD DateTime now = RTC.now();
client.print(now.year(), DEC); client.print('/'); client.print(now.month(), DEC); client.print('/'); client.print(now.day(), DEC); client.print(' '); client.print(now.hour(), DEC); client.print(':'); client.print(now.minute(), DEC); client.print(':'); client.print(now.second(), DEC); client.println(); client.println();
client.println("<table>"); client.println("<table border='1'>"); client.print("<tr><td>OWB_Supply_Temp"); client.print("</td><td>"); client.print(OWB_supply_temp ); client.print((char)176); client.print("F"); client.print("</td><td>"); client.print("pool heated temp"); client.print("</td><td>"); client.print(pool_heated_temp ); client.print((char)176); client.print("F"); client.println("</td></tr>");
client.print("<tr><td>OWB_Return_Temp"); client.print("</td><td>"); client.print(OWB_return_temp ); client.print((char)176); client.print("F"); client.print("</td><td>"); client.print("pool unheated temp"); client.print("</td><td>"); client.print(pool_unheated_temp ); client.print((char)176); client.print("F"); client.println("</td></tr>"); client.println("</table>");
client.print("<p><font color='#339900' size=’5′>Outside air temp (front porch) = "); client.print(OAT ); client.print((char)176); client.print("F"); client.print("</p>");
OWB_Temp_House_DIFFERENCE = OWB_DWT - EWT; client.print("<p><font color='#339900' size=’5′>Outside air temp (at the OWB) = "); client.print(OWB_OAT ); client.print((char)176); client.print("F"); client.print("</p>");
client.print("<p>Space temperature(Great room) = "); client.print(temp_f ); client.print((char)176); client.print("F"); client.print("</p>");
client.print("<p>Space Humidity(Great room) = "); client.print(humidity); client.print("%"); client.print("</p>");
client.print("<p> Boiler water temperature (in the house) = "); client.print(EWT ); client.print((char)176); client.print("F"); client.print("</p>");
client.print("<p>OWB water temperature (at the OWB) = "); client.print(OWB_DWT ); client.print((char)176); client.print("F"); client.print("</p>");
client.print("<p>TEMP difference between the OWB and the H20 temp in the house = "); client.print(OWB_Temp_House_DIFFERENCE ); client.print((char)176); client.print("F"); client.print("</p>");
client.print("<p>Number of XBee modem status messages = "); client.print(modemstatus ); client.print("</p>");
if (digitalRead(blowerRunning) == LOW) { client.println("<p>The blower is running"); } else { client.println("<p>The blower is off"); } client.print("</p>"); client.print("<p>Discharge air temperature is = "); client.print(DAT ); client.print((char)176); client.print("F"); client.print("</p>");
client.print("<p>DX suction line temp is = "); client.print(DSLT ); client.print((char)176); client.print("F"); client.print("</p>");
client.println("<hr />"); client.println("Debug info"); client.println("<hr />"); client.println(); client.println(); client.println("<p>Thermostat data"); client.print("</p>");
if (digitalRead(rTstatPin) == LOW) { client.println("<p>R = 24Vac"); } else { client.println("<p>R = 0Vac"); } client.print("</p>");
if (digitalRead(yTstatPin) == LOW) { client.println("<p>Y = 24Vac"); } else { client.println("<p>Y = 0Vac"); } client.print("</p>");
if (digitalRead(wTstatPin) == LOW) { client.println("<p>W = 24Vac"); } else { client.println("<p>W = 0Vac"); } client.print("</p>");
if (digitalRead(gTstatPin) == LOW) { client.println("<p>G = 24Vac"); } else { client.println("<p>G = 0Vac"); } client.print("</p>");
client.print("<p>Highest boiler water temperature = "); client.print(HWT ); client.print((char)176); client.print("F"); client.print("</p>");
client.print("<p>Lowest boiler water temperature = "); client.print(LWT ); client.print((char)176); client.print("F"); client.print("</p>");
client.print("<p>Highest discharge air temperature = "); client.print(max_DAT ); client.print((char)176); client.print("F"); client.print("</p>");
client.print("<p>EWT EC = "); //display the EWT errors client.print(EC ); client.print("</p>");
client.print("<p>SHT15 reads = "); //display the SHT reads client.print(num_SHT_reads ); client.print("</p>");
client.print("<p>Each sensor was read "); client.print(numReadings); client.print(" times"); client.print("</p>");
client.print("</HTML>"); break; } if (c == '\n') { // we're starting a new line current_line_is_blank = true; } else if (c != '\r') { // we've gotten a character on the current line current_line_is_blank = false; } } } // give the web browser time to receive the data delay(1); client.stop(); } //end web stuff }
|
|
|
|
|
3
|
Using Arduino / Networking, Protocols, and Devices / Re: Ethernet lockups/freezes/non responsive
|
on: June 10, 2013, 09:46:55 pm
|
more of the code void loop() {
// xbee stuff
xbee.readPacket(); // so the read above will set the available up to // work when you check it. if (xbee.getResponse().isAvailable()) { if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) { // got a zb rx packet, the kind this code is looking for // now that you know it's a receive packet // fill in the values xbee.getResponse().getZBRxResponse(rx); point_identifier = rx.getData(0); Serial.print("point indentifier = "); Serial.println(point_identifier);
switch(point_identifier) { case 2: //outdoor wood boiler (OWB) Xbee
union { float f; byte b[4]; } OAT;
union { float h; byte b[4]; } DWT;
Serial.print("Point Identifier = "); Serial.println(rx.getData(0));
OAT.b[0] = rx.getData(1); OAT.b[1] = rx.getData(2); OAT.b[2] = rx.getData(3); OAT.b[3] = rx.getData(4); Serial.print("Outside_air_temp = "); Serial.println(OAT.f); OWB_OAT = OAT.f;
DWT.b[0] = rx.getData(5); DWT.b[1] = rx.getData(6); DWT.b[2] = rx.getData(7); DWT.b[3] = rx.getData(8);
Serial.print("Discharge_water_temp = "); Serial.println(DWT.h); OWB_DWT = DWT.h; lasttime = millis(); break;
case 3: //pool Xbee union { float f; byte b[4]; } OWB_supply_t; OWB_supply_t.b[0] = rx.getData(1); OWB_supply_t.b[1] = rx.getData(2); OWB_supply_t.b[2] = rx.getData(3); OWB_supply_t.b[3] = rx.getData(4); Serial.print("owb supply temp = "); Serial.println(OWB_supply_t.f); OWB_supply_temp = OWB_supply_t.f;
union { float f; byte b[4]; } OWB_return_t; OWB_return_t.b[0] = rx.getData(5); OWB_return_t.b[1] = rx.getData(6); OWB_return_t.b[2] = rx.getData(7); OWB_return_t.b[3] = rx.getData(8); Serial.print("owb return temp = "); Serial.println(OWB_return_t.f); OWB_return_temp = OWB_return_t.f;
union { float f; byte b[4]; } pool_unheated_t; pool_unheated_t.b[0] = rx.getData(9); pool_unheated_t.b[1] = rx.getData(10); pool_unheated_t.b[2] = rx.getData(11); pool_unheated_t.b[3] = rx.getData(12); Serial.print("pool unheated temp = "); Serial.println(pool_unheated_t.f); pool_unheated_temp = pool_unheated_t.f;
union { float f; byte b[4]; } pool_heated_t; pool_heated_t.b[0] = rx.getData(13); pool_heated_t.b[1] = rx.getData(14); pool_heated_t.b[2] = rx.getData(15); pool_heated_t.b[3] = rx.getData(16); Serial.print("pool heated temp = "); Serial.println(pool_heated_t.f); pool_heated_temp = pool_heated_t.f; break;
default : Serial.print(point_identifier); Serial.println("was received but not expected"); break; } } else if (xbee.getResponse().getApiId() == MODEM_STATUS_RESPONSE) { modemstatus = modemstatus + 1; //increment the modemstatus counter xbee.getResponse().getModemStatusResponse(msr); // the local XBee sends this response on certain events, like association/dissociation //main thing is to get the msg out of the serial buffer..I think.. FR if (msr.getStatus() == ASSOCIATED) { // yay this is great. //do nothing } else if (msr.getStatus() == DISASSOCIATED) { // this is awful.. //do nothing } else { // another status //do nothing } } } // end xbee stuff
if (millis() - lastTempRequest >= delayInMillis) // waited long enough?? { OAT = OUTSIDE_AIR_TEMP.getTempFByIndex(0); EWT = ENTERING_WATER_TEMP.getTempFByIndex(0); DAT = DISCHARGE_AIR_TEMP.getTempFByIndex(0); DSLT = DX_SUCTION_TEMP.getTempFByIndex(0); numReadings = numReadings + 1 ;
// immediately after fetching the temperature we request a new sample // in the async modus
OUTSIDE_AIR_TEMP.requestTemperatures(); ENTERING_WATER_TEMP.requestTemperatures(); DISCHARGE_AIR_TEMP.requestTemperatures(); DX_SUCTION_TEMP.requestTemperatures();
lastTempRequest = millis(); }
// begin SHT non-blocking unsigned long curMillis = millis(); // Get current time if (curMillis - trhMillis >= TRHSTEP) { // Time for new measurements? measActive = true; measType = TEMP; sht.meas(TEMP, &rawData, NONBLOCK); // Start temp measurement trhMillis = curMillis; } if (measActive && sht.measRdy()) { // Check measurement status if (measType == TEMP) { // Process temp or humi? measType = HUMI; temp_c = sht.calcTemp(rawData); // Convert raw sensor data temp_f = (temp_c * 9.0)/5.0 + 32.0; sht.meas(HUMI, &rawData, NONBLOCK); // Start humi measurement } else { measActive = false; humidity = sht.calcHumi(rawData, temp_f); // Convert raw sensor data // dewpoint = sht.calcDewpoint(humidity, temperature); } }
//set the high (HWT) and the low (LWT) water temperatures if ((EWT > lastEWT + 1.0) || (EWT < lastEWT - 1.0)) //EWT sanity check { EC = EC + 1; } //increment the error counter else { if (EWT > HWT) { HWT = EWT; } if (EWT < LWT) { LWT = EWT; } lastEWT = EWT; } if (DAT > max_DAT) { max_DAT = DAT; }
|
|
|
|
|
4
|
Using Arduino / Networking, Protocols, and Devices / Ethernet lockups/freezes/non responsive
|
on: June 10, 2013, 09:44:01 pm
|
I am having trouble with ethernet becoming non responsive after a period of time ranging from a few hours to a day or sometimes more. The hardware is an Arduino Mega 2560 with an R3 ethernet shield. I was using a previous generation of Ethernet shield and bought a new shield to resolve this issue but the problem remains. I am using windows 7 IDE = 1.0.5 . I have searched the forum for many hours but cant seem to find a solution. Ive found many people with seemingly the same problem but no concrete solution. I am posting the complete code for my sketch in hope the somebody will see something that could cause this issue. The sketch is rather long and it gives me the exact info I need when not locked up. The ethernet stuff is near the end of the sketch. I have no formal training in c programming as you will soon see from the code but it works. If any more info is needed please let me know. oh...the URL is http://67.231.227.82:8250/ I will have to post the code in two posts as it exceeds the 9500 character count. #include <OneWire.h> #include <DallasTemperature.h> #include <SPI.h> #include <Ethernet.h> #include <Sensirion.h> #include <Wire.h> #include "RTClib.h" // Date and time functions using a Chronodot RTC connected via I2C and Wire lib #include "Arduino.h" #include <XBee.h>
long lasttime ; //for calculating xbee packet times long elapsedtime; //for calculating xbee packet times
XBee xbee = XBee(); XBeeResponse response = XBeeResponse(); // create reusable response objects for responses we expect to handle ZBRxResponse rx = ZBRxResponse(); ModemStatusResponse msr = ModemStatusResponse(); int modemstatus = 0; uint8_t point_identifier = 0;
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0x93, 0xB1 }; byte ip[] = { 192, 168, 1, 125 }; byte gateway[] = { 192, 168, 1, 1 }; byte subnet[] = { 255, 255, 255, 0 };
EthernetClient client;
EthernetServer monserver(8250); RTC_DS1307 RTC;
OneWire OUTSIDE_AIR_TEMP_BUS (2) ; // Data wire is plugged into pin 2 on the Arduino OneWire ENTERING_WATER_TEMP_BUS (3) ; // Data wire is plugged into pin 3 on the Arduino OneWire DISCHARGE_AIR_TEMP_BUS (9) ; OneWire DX_SUCTION_TEMP_BUS (A3) ;
DeviceAddress tempDeviceAddress;
DallasTemperature OUTSIDE_AIR_TEMP (&OUTSIDE_AIR_TEMP_BUS) ; DallasTemperature ENTERING_WATER_TEMP (&ENTERING_WATER_TEMP_BUS) ; DallasTemperature DISCHARGE_AIR_TEMP (&DISCHARGE_AIR_TEMP_BUS) ; DallasTemperature DX_SUCTION_TEMP (&DX_SUCTION_TEMP_BUS) ;
unsigned long lastTempRequest = 0; int delayInMillis = 0; int idle = 0;
float OAT = 0.00 ; //outside air temp temperature float EWT = 0.00; //boiler water temp entering the house float HWT = 0.00 ; //highest water temperature float LWT = 0.00 ; //lowest water temperature float DAT = 0.00 ; //discharge air temperature float DSLT = 0.00 ; //DX suction line temperature float lastEWT = 0.00; //variable for EWT sanity check int EC ; //sensor error count long numReadings ; //number of time EWT sensor is read float temp_f = 0.00; //SHT15 temp float temp_c = 0.00; float humidity = 0.00; //SHT15 humidity unsigned long last_read_SHT = millis(); unsigned long max_SHT_time = 5000; unsigned long num_SHT_reads = 0; float max_DAT = 0.00; //maximum discharge air temperature float OWB_OAT = 0.00; //outside aie temp at the OWB float OWB_DWT = 0.00; // discharge water temp at the OWB float OWB_Temp_House_DIFFERENCE = 0.00; // difference in water temp between the OWB and the temp in house
//variables from the pool controller via xbee float OWB_supply_temp = 0.0; float OWB_return_temp = 0.0; float pool_unheated_temp = 0.0; float pool_heated_temp = 0.0;
int SD_deselect = 4;
const int rTstatPin = 5; //r (power) tstat const int yTstatPin = 6; //y (cooling) tstat const int wTstatPin = 7; //w (heating) tstat const int gTstatPin = 8; //g (fan) tstat const int blowerRunning = A2; //blower running
const byte dataPin = 16; // SHTxx serial data const byte sclkPin = 17; // SHTxx serial clock const unsigned long TRHSTEP = 5000UL; // Sensor query period
Sensirion sht = Sensirion(dataPin, sclkPin); unsigned int rawData; byte measActive = false; byte measType = TEMP; unsigned long trhMillis = 0; // Time interval tracking
void setup() { // start serial port Serial.begin(9600); Serial1.begin(9600); // start the xbee serial port
xbee.setSerial(Serial1); // hook the xbee into the Serial1 serial port Serial.println(" Home Monitor");
pinMode(SD_deselect, OUTPUT); digitalWrite(SD_deselect, HIGH); //initialize the pool relay to 'not heating'
pinMode(rTstatPin, INPUT); pinMode(yTstatPin, INPUT); pinMode(wTstatPin, INPUT); pinMode(gTstatPin, INPUT); pinMode(blowerRunning, INPUT); pinMode(A3, INPUT);
// turn on the internal pullup resistors fot tstat inputs digitalWrite(rTstatPin, HIGH); digitalWrite(yTstatPin, HIGH); digitalWrite(wTstatPin, HIGH); digitalWrite(gTstatPin, HIGH); digitalWrite(blowerRunning, HIGH);
// Start up the librarys //set the ds18b20 resolution to 12 bit OUTSIDE_AIR_TEMP.begin(); OUTSIDE_AIR_TEMP.getAddress(tempDeviceAddress, 0); OUTSIDE_AIR_TEMP.setResolution(tempDeviceAddress, 12); ENTERING_WATER_TEMP.begin(); ENTERING_WATER_TEMP.getAddress(tempDeviceAddress, 0); ENTERING_WATER_TEMP.setResolution(tempDeviceAddress, 12); DISCHARGE_AIR_TEMP.begin(); DISCHARGE_AIR_TEMP.getAddress(tempDeviceAddress, 0); DISCHARGE_AIR_TEMP.setResolution(tempDeviceAddress, 12); DX_SUCTION_TEMP.begin(); DX_SUCTION_TEMP.getAddress(tempDeviceAddress, 0); DX_SUCTION_TEMP.setResolution(tempDeviceAddress, 12);
OUTSIDE_AIR_TEMP.setWaitForConversion(false); OUTSIDE_AIR_TEMP.requestTemperatures(); ENTERING_WATER_TEMP.setWaitForConversion(false); ENTERING_WATER_TEMP.requestTemperatures(); DISCHARGE_AIR_TEMP.setWaitForConversion(false); DISCHARGE_AIR_TEMP.requestTemperatures(); DX_SUCTION_TEMP.setWaitForConversion(false); DX_SUCTION_TEMP.requestTemperatures();
delayInMillis = 5000 ; lastTempRequest = millis(); delay(750);
Ethernet.begin(mac, ip, gateway, subnet); monserver.begin();
Wire.begin(); RTC.begin();
//initalize HWT and LWT to the current entering water pemperature EWT = ENTERING_WATER_TEMP.getTempFByIndex(0); DAT = DISCHARGE_AIR_TEMP.getTempFByIndex(0); DSLT = DX_SUCTION_TEMP.getTempFByIndex(0);
//initalize HWT and LWT to the current entering water pemperature HWT = EWT; LWT = EWT; lastEWT = EWT;
EC = 0 ; numReadings = 0 ; }
//see next post
|
|
|
|
|
5
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: controlling temperature with a differential
|
on: April 17, 2010, 08:33:36 pm
|
Thanks for the replies Guys!! PaulS said... Your code will turn the heater on when the temperature drops more than diff below setpoint, and will turn it off as soon as temperature gets to setpoint. That is what I wanted to know. I was just looking for different/more efficient/better ways to achieve the end result. I am new to coding and the sample code in my first post is the ONLY way I could figure to do it. Is there another way? How would you do it? (without using PID)
|
|
|
|
|
6
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: controlling temperature with a differential
|
on: April 17, 2010, 07:01:20 pm
|
|
PaulS Thanks for the reply but I dont think a PID controller is needed in this case . The application is an electric heating element in a large volume of water(think electric hot water tank). My question is.....What is the best coding methodoly to keep the temperature between the 'setpoint' and the 'setpoint minus the differential'. IE between 120 and 115.
Thanks Frank
|
|
|
|
|
7
|
Forum 2005-2010 (read only) / Syntax & Programs / controlling temperature with a differential
|
on: April 17, 2010, 10:56:13 am
|
I am looking for the best/accepted way to control temperature with a differential or deadband. In other words I want to keep the temperature between a setpoint of 120 with a diffential/deadband of 5. So the temperature needs to stay between 115 and 120. It seems that I must first test to see if the TEMP is below (setpoint minus the diffential) and then keep the program flow contained inside a while loop until the temp is up to setpoint. I posted some sample code below (that works) but I just wanted to see how others would handle this. Any thoughts/code/examples would be appreciated. Thanks Frank if (TEMP < SPT - DIFF) //temp is below setpoint minus diff {digitalWrite (TE, HIGH); //turn heat on while (TEMP < SPT) { TEMP = sensorsTOP.getTempFByIndex(0); //update TEMP
if (TEMP < SPT) { do nothing } else { digitalWrite (TE, LOW) //turn the heat off } } }
|
|
|
|
|
9
|
Forum 2005-2010 (read only) / Syntax & Programs / Multiple Dallas onewire busses on one Arduino
|
on: March 30, 2010, 02:59:59 pm
|
I am trying to setup an Arduino with two onewire busses attached to it using the DallasTemperature library. Below is some sample code from the Dallastemperature library of setting up 2 ds18b20 sensors on one bus. I cannot figure out how to modify this code to add another onewire bus . Everything I try to add another bus will not compile. I cannot find an example on the internet . Can some kind soul help me with this perplexing(to me) problem? Maybe what I am trying to do isnt even possible? Thanks Frank #include <OneWire.h> #include <DallasTemperature.h>
// Data wire is plugged into port 2 on the Arduino #define ONE_WIRE_BUS 2
// 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);
void setup(void) { // start serial port Serial.begin(9600); Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library sensors.begin(); }
void loop(void) { // call sensors.requestTemperatures() to issue a global temperature // request to all devices on the bus Serial.print("Requesting temperatures..."); sensors.requestTemperatures(); // Send the command to get temperatures Serial.println("DONE"); Serial.print("Temperature for the device 1 (index 0) is: "); Serial.println(sensors.getTempFByIndex(0)); delay(2000);
Serial.print("Temperature for the device 2 (index 1) is: "); Serial.println(sensors.getTempFByIndex(1)); delay(2000); }
|
|
|
|
|
10
|
Forum 2005-2010 (read only) / Troubleshooting / Re: dallastemperature code
|
on: March 29, 2010, 06:37:15 pm
|
well...not like that above....like this uint8_t TOP_STAT_ADDR[8] = { 0x28, 0x63, 0xfa, 0x5e, 0x02, 0x00, 0x00, 0x1d }; uint8_t BOT_STAT_ADDR[8] = { 0x28, 0xc7, 0x12, 0x44, 0x02, 0x00, 0x00, 0x5a };
|
|
|
|
|
11
|
Forum 2005-2010 (read only) / Troubleshooting / Re: dallastemperature code
|
on: March 29, 2010, 06:36:01 pm
|
|
Thank MarkT
I moved the 'array initializers to the top above the SETUP (). It looks like this.... [code][/code uint8_t TOP_STAT_ADDR[8] = { 0x28, 0x63, 0xfa, 0x5e, 0x02, 0x00, 0x00, 0x1d }; uint8_t BOT_STAT_ADDR[8] = { 0x28, 0xc7, 0x12, 0x44, 0x02, 0x00, 0x00, 0x5a };]
It now compiles and functions properly.
Thanks again!!
Frank
|
|
|
|
|
12
|
Forum 2005-2010 (read only) / Troubleshooting / dallastemperature code
|
on: March 29, 2010, 05:18:14 pm
|
I am really new to Arduino and coding. Can anyone help me figure out why this little bit of code will not compile. It fail at the TOP_STAT_ADDR address assignment in the SETUP () portion. Arduino 18 reports the following error: error: expected primary-expression before '{' token I know the error is staring me in the face but I just cant see it. Thanks in advance. Frank #include <OneWire.h> #include <DallasTemperature.h>
// Data wire is plugged into port 2 on the Arduino #define ONE_WIRE_BUS 2 #define TOP_ELEMENT 3 //top element relay #define BOT_ELEMENT 4 //bottom element relay
// 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);
uint8_t TOP_STAT_ADDR[8]; uint8_t BOT_STAT_ADDR[8];
float TOP_TEMP; float BOT_TEMP;
void setup() { pinMode(TOP_ELEMENT, OUTPUT); //top element is an output pinMode(BOT_ELEMENT, OUTPUT); //bottom element is an output TOP_STAT_ADDR = { 0x28, 0xc7, 0x12, 0x44, 0x02, 0x00, 0x00, 0x5a }; BOT_STAT_ADDR = { 0x28, 0x63, 0xfa, 0x5e, 0x02, 0x00, 0x00, 0x1d };
// start serial port Serial.begin(9600); Serial.println(" Hot Water Tank Control");
// Start up the library sensors.begin(); }
void loop() { // call sensors.requestTemperatures() to issue a global temperature // request to all devices on the bus Serial.print("Requesting temperatures..."); sensors.requestTemperatures(); // Send the command to get temperatures Serial.println("DONE"); TOP_TEMP = sensors.getTempF(TOP_STAT_ADDR); BOT_TEMP = sensors.getTempF(BOT_STAT_ADDR);
Serial.print("TOP_TEMP "); Serial.println(TOP_TEMP); Serial.print("BOT_TEMP "); Serial.println(BOT_TEMP);
}
|
|
|
|
|