I would do it this way. Set up the ethernet interface once, then make the connection in the loop().
#include <SPI.h>
#include <Ethernet.h>
#include <LiquidCrystal.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,50);
IPAddress server(192,168,0,90);
EthernetClient client;
void setup() {
Serial.begin(9600);
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Web Client:");
Serial.print("Starting ethernet...");
Ethernet.begin(mac,ip);
Serial.println("started");
delay(2000);
}
void loop() {
lcd.clear();
lcd.print("Connecting");
Serial.println("Connecting...");
if (client.connect(server, 80)) {
Serial.println("Connected");
client.println("GET / HTTP/1.0");
client.println();
while(client.connected()) {
while(client.available()) {
Serial.write(client.read());
}
}
client.stop();
Serial.println("disconnected");
}
else {
Serial.println("failed");
}
lcd.clear();
lcd.print("Disconnected");
delay(2000);
}
Add any cursor position changes to that it may need. edit: I added a "lcd.clear()" to each print.
Does this change the LCD display as it goes through the loop? It will not make a connection yet. Leave the shield off. Best to do this one shield at a time.