Ethernet Shield and LCD conflict: Server hangs

Hi all,

wrestling with a strange problem, and would be very happy, if one of you could give me an hint:

Webserver code works pretty fine, separate LCD code works as well, but if i combine both, the webserver hangs.

If i add this line (All other lcd commands are commented out):

LiquidCrystal lcd(RS, E, D4, D5, D6, D7 );

The server only delivers part of the page, an then seems to stop.
Strangely, on the page only the submit button is missing.

Without LCD initialisation:



With LCD initialisation:



I use the original ethernet shield, Arduino 2009, and an 20x2 LCD.

LCD connected like this:
int RS = 9;
int E = 3;
int D4 = 6;
int D5 = 8;
int D6 = 4;
int D7 = 5;

As far as i found in the internets, there is no pin conflict so far.

My code looks like this:

// Small Arduino Webserver
// by Andreas Cahen
//
// Used libraries and examples:
//
// Arduino Ethershield, server.pde
// TextString Library, WString.h 
// Blinkm Library, BlinkMfuncs.h


#include <Ethernet.h>
#include <WString.h>
#include <LiquidCrystal.h>
//#include <LCD4Bit_mod.h>


#define maxLength 142

int RS = 9;
int E = 3;
int D4 = 6;
int D5 = 8;
int D6 = 4;
int D7 = 5;



byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 
  192, 168, 2, 10 };
String inString = String(maxLength); 
String Anzeigetext = String(maxLength); 
String pin = String(40);
int textstart;
int pinstart;
int intpin;
boolean rightpin;
byte cols = 20;
byte rows = 2;

Server server(80);

//int ledPin = 2;                 // LED connected to digital pin 13

void setup()
{
  LiquidCrystal lcd(RS, E, D4, D5, D6, D7 ); // Initializing Liquid Cristal display
  //pinMode(ledPin, OUTPUT);      // sets the digital pin as output
  Serial.begin(9600);
  Serial.println("Starting Server...");
  Ethernet.begin(mac, ip);
  server.begin();

//  lcd.begin(cols, rows);
//  lcd.print("Hallo Welt");
//  delay (1000);
//  lcd.begin(cols, rows);   
}


void loop()
{
  Client client = server.available();
  if (client) {
    boolean current_line_is_blank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        if (inString.length() < maxLength) {
          inString.append(c);
        }        
        if (c == '\n' && current_line_is_blank) {
          if (inString.contains("?")) { 
            //Serial.println(inString); //show al received characters up to max string length

            //find position of form field name QTXT in string
            int textstart = inString.indexOf("QTXT");

            //find position of form field name QPIN in string    
            int pinstart = inString.indexOf("QPIN");

            //extract the text to be displayed on lcd out of the instring
            Anzeigetext = inString.substring(textstart+5, pinstart-1);  

            //replace the annoing "+" chracters in instring with " " as originally typed in form field
            Anzeigetext.replace( '+', ' ');

            //extract the pin number string out of the instring
            pin = inString.substring(pinstart+5, pinstart+9);

            //calculate numerical value of pin and test if it matches the right number
            intpin = atoi(pin);
            if (intpin == 1684)
            {
              rightpin = true;
              //digitalWrite(ledPin, HIGH);   // sets the LED on
              Serial.println(Anzeigetext); 
              //lcd.print(Anzeigetext); 
            }
            else
            {
              rightpin = false;
              Serial.println("Falsche Pin");
              //digitalWrite(ledPin, LOW);   // sets the LED off

            }

          } 

          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<html><head></head><body>");
          client.println("<h1>Input text to display</h1>");
          client.println("<form method=get>Text:<input type=text size=140 name=QTXT>


Pin:<input type=text size=4 name=QPIN>


<input type=submit value=submit></form>");       

          if (rightpin)
          {
            client.println(Anzeigetext);         
          }
          else
          {
            client.println("Falsche PIN");                 
          }

          client.println("</body></html>");           
          break;
        }
        if (c == '\n') {
          current_line_is_blank = true;
        } 
        else if (c != '\r') {
          current_line_is_blank = false;
        }
      }
    }
    delay(1);
    inString = "";
    client.stop();
  } 
}

If I was debugging this with you, the first thing I would want to see is what the actual page source looked like in the two different situations.

Perhaps comparing the two page source data files would give you a clue what is wrong.

Using the LiquidCrystal library adds to the code size, as I'm sure you've noticed. What may not be as obvious is that it adds to the sram, too. It's possible that you are running out of sram without knowing it.

This thread discussed the topic of memory, and the various kinds used, with some code to measure each.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1236343710

Have you patched the string library?

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1241618944/11

I have the same problem: I have written a sketch with ethernet and LCD-functionality. The sketch works perfectly with either the ethernet shield OR the LCD-shield plugged in. However, when both are plugged in, the ethernetshield sends garbish on the network: ie with the ARP-protocol it nulls some bytes in his own ipaddress and MAC-address. I have tried to power with external power supply, with same problems. So, the only explication I can imagine at this moment is that the LCD-shield uses (one of) the D10-13 pins. Or could it be capacitive coupling? Any ideas?

First thing to do would be to verify which pins each shield uses. You may find there is a pin conflict.

It appears that the LCD shield is doing something with data pin 10 (altough no connection is shown on the schematics), witch is also used by the ethernet shield. I disconnected the pin on the LCD-shield and everything is working great (including the LCD)-shield!