UIPEthernet and liquidcrystal libraries question

HI All,
Hope I am posting this in the right section…
I have been playing with the UIPEthernet library and found it to work well except when trying to use it with an LCD display.
Either the LCD displays back squares and ether adapter works or neither work.
Have tried 16x2 and 20x4 displays with same results.
Tried the same sketches using the LCD and ethercard library and all works well except the ether stops responding after a few hours (have tried a heatsink on theh ENC chip as well as extra decoupling capacitors on the power leads,various power supplies,etc with no luck)

Have tried the default pins for LCD as well as the pins specified in my sketch below.

Below is my modified code found on the net,probably not the best in the world but are learning slowly :slight_smile:

Can anyone advise how to resolve this or where I an going wrong ?

Thanks Dave

/
/
-----( Import needed libraries )-----*/
#include <SPI.h>
#include <UIPEthernet.h>
#include <dht11.h>
#include <Wire.h>

/-----( Declare Constants and Pin Numbers )-----/
#define DHT11PIN 2 // The Temperature/Humidity sensor

unsigned long minutes; // use unsigned long as integer will overflow eventually
int hours=0;
int days=0;
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac = {
0x00, 0x01, 0x02, 0x03, 0x04, 0xED };

/-----( Declare objects )-----/
IPAddress ip(192,168,0, 1);

// Initialize the Ethernet server library
// with the IP address and port you want to use
//(port 80 is default for HTTP):
EthernetServer server(80);

dht11 DHT11; //The Sensor Object
/-----( Declare Variables )-----/

// LCD
// LCD RS=3, EN=4, DS4=5, DS5=6, DS6=7, DS7=8
#include <LiquidCrystal.h>
LiquidCrystal lcd( 19, 18, 17, 16, 15, 14);

void setup() /****** SETUP: RUNS ONCE ******/
{
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
pinMode(A4, OUTPUT);
pinMode(A5, OUTPUT);
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print(“INIT”);
}

// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}//–(end setup )—

void loop() /----( LOOP: RUNS OVER AND OVER AGAIN )----/
{

minutes = millis() / 60000; // uptime, minutes
hours = minutes / 60; // uptime, hours
days = hours / 24; // uptime, days

//LCD Print

// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println(“new client”);
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you’ve got to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == ‘\n’ && currentLineIsBlank) {
// send a standard http response header
client.println(“HTTP/1.1 200 OK”);
client.println(“Content-Type: text/html”);
client.println(“Connnection: close”);
client.println();
client.println("");
client.println("");
// add a meta refresh tag, so the browser pulls again every 5 seconds:
client.println("<meta http-equiv=“refresh” content=“5”>");
client.println(" Weather Station");
client.println("
“);
client.print(” Online & LCD Weather Station");
client.println("
“);
client.println(”
");

/----(Get sensor reading, calculate and print results )-----------------/

int chk = DHT11.read(DHT11PIN);

Serial.print("Read sensor: ");
switch (chk)
{
case 0:
Serial.println(“OK”);
break;
case -1:
Serial.println(“Checksum error”);
break;
case -2:
Serial.println(“Time out error”);
break;
default:
Serial.println(“Unknown error”);
break;
}

client.print("Temperature (C) : “);
client.println((float)DHT11.temperature, 1);
client.println(”
");

client.print("Temperature (F) : “);
client.println(Fahrenheit(DHT11.temperature), 1);
client.println(”
");

client.print("Humidity (%) : “);
client.println((float)DHT11.humidity, 0);
client.println(”
");

client.print("Temperature (K) : “);
client.println(Kelvin(DHT11.temperature), 1);
client.println(”
");

client.print("Dew Point (C) : “);
client.println(dewPoint(DHT11.temperature, DHT11.humidity));
client.println(”
");

client.print("Dew PointFast (C) : “);
client.println(dewPointFast(DHT11.temperature, DHT11.humidity));
client.println(”
“);
client.println(”
");
client.print("Uptime : “);
client.println(days );
client.print(” Day(s) “);
client.println(”
“);
client.print(” Or “);
client.println(”
“);
client.print(hours );
client.print(” Hour(s) “);
client.println(”
“);
client.print(” Or “);
client.println(”
“);
client.print(minutes );
client.print(” Minute(s) ");

/--------( End Sensor Read )--------------------------------/
client.println("");
break;
}
if (c == ‘\n’) {
// you’re starting a new line
currentLineIsBlank = true;
}
else if (c != ‘\r’) {
// you’ve got a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println(“client disonnected”);
}
} // END Loop

/-----( Declare User-written Functions )-----/
//
//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
return 1.8 * celsius + 32;
}

//Celsius to Kelvin conversion
double Kelvin(double celsius)
{
return celsius + 273.15;
}

// dewPoint function NOAA
// reference: http://wahiduddin.net/calc/density_algorithms.htm
double dewPoint(double celsius, double humidity)
{
double A0= 373.15/(273.15 + celsius);
double SUM = -7.90298 * (A0-1);
SUM += 5.02808 * log10(A0);
SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
SUM += log10(1013.246);
double VP = pow(10, SUM-3) * humidity;
double T = log(VP/0.61078); // temp var
return (241.88 * T) / (17.558-T);
}

// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
double a = 17.271;
double b = 237.7;
double temp = (a * celsius) / (b + celsius) + log(humidity/100);
double Td = (b * temp) / (a - temp);
return Td;
}
/* ( THE END ) */

Can anyone advise how to resolve this . . .

Here’s a start:

  • Go back and edit your original post. Highlight the part that is code and then press the ‘code’ button (the scroll with < > symbols near the right end of the top line).

  • Get rid of the pinMode instructions for the analog pins, this is handled by the LiquidCrystal library.

  • Reduce your code to the bare minimum that still illustrates your problem.

Don