Ethernet & LCD Shield project

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.

Yes, I get the initial "Web Client:" then it writes the connecting / disconnected lines over and over.

add: though i notice you have a clear() in there.. the LCD does not clear, it just continues from where the cursor stopped.

Now bend digital 4 so it does not insert into the Arduino, and put the jumper on the shield from 4 to 3.

Change to this again:

LiquidCrystal lcd(8, 9, 3, 5, 6, 7);

Still no LCD output?

Changed, pin 4 removed from the arduino, jumper between 3 and 4 on the LCD - no joy.. code runs i can see on the serial monitor.
But no text on the LCD.

I only have one more try left, then we are out of pins. Try digital 2 instead of digital 3. Move the jumper one pin over, connecting digital 4 to digital 2 , and change to this:

LiquidCrystal lcd(8, 9, 2, 5, 6, 7);

If that doesn't do it, I have run out of pins and ideas at the same time. :frowning:

edit: I lied. I have one more idea.
Bend digital 4 on the LCD shield so it does not connect to the ethernet shield.
Bend digital pin 4 on the ethernet shield so it does not connect to digital pin 4 on the Arduino.
Put the jumper from digital 4 on the LCD shield to the Arduino digital 4.
Put another jumper from the ethernet shield digital 4 to +5v.
Then back to this:

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

But that is it for my ideas. With that setup, the microSD card is not useable. You might be able to jumper that pin on the ethernet shield to digital 3.

Thanks for your help Tim,

It's late and I'm going to pack it in for tonight.

One thing I have notice.. on the LCD Shield where the digital pins are.. their neighboring counterparts are not connected.
This is an almost identical board to the LCD board im using, only visual difference is the drive the future logo, which is not present on my board.

I noticed that using pin 4 and connecting from 4 on the arduino to the outer 4 on the LCD board did not produce an output, but connecting 4 on the
arduino board to pin 4 on the factory header with no code changes - works.. :~

I will have to wait until morning before I can dig my tester out the garage and confirm this, but it looks like I'm skuppered :frowning:

I'm packing it in for tonight also.

The "outer 4" is the digital 4 in the red rectangle, and the "factory header" is in the blue rectangle? And you think they may not be connected? And if you use digital 4 in the blue, it works?

SurferTim:
The "outer 4" is the digital 4 in the red rectangle, and the "factory header" is in the blue rectangle? And you think they may not be connected? And if you use digital 4 in the blue, it works?

Yes.. I had assumed from previous shields that each pin red to blue were connected, but apparently not.
I'm also getting that dimming of the LCD characters again.

Add:
OK I've had a little success :slight_smile:

I have both the Ethernet and LCD shields connected, I'm getting a good response from the webserver which is feeding through in the serial monitor,
and I'm getting output (if a bit dim as described above) on the LCD..

I changed the code ever so slightly, no pin changes.. just to structure the LCD output so it didn't just keep overwriting the last string of chars.

here it is;

#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;
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  
void setup() {
  
  Serial.begin(9600);
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);
  
  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.setCursor(0,1);
  lcd.print("Connecting...   ");
  Serial.println("Connecting...");

  delay(1000);

  if (client.connect(server, 80)) {
    
    lcd.setCursor(0,1);
    lcd.print("Connected       ");
    
    Serial.println("Connected to server.");
    client.println("GET / HTTP/1.0");
    client.println();

    while(client.connected()) {
      while(client.available()) {
        Serial.write(client.read());
      }
    }
    
    delay(3000);
    
    client.stop();
    Serial.println("Disconnected from server.");
  } 
  else {
    Serial.println("Connection to server Failed.");
  }
  
  
  lcd.setCursor(0,1);
  lcd.print("Disconnected    ");

 delay(2000);
}

Add also: Digital Pin 4 is connected to all boards and pin 10 on the LCD board is not connected to anything.

Are both shields powered by the Arduino +5v? Maybe not enough power? My first check would be the voltage on the +5v pin.

edit: Personally, I do my best to keep devices available. I would try to move digital pin 4 on the LCD to digital 3 and use that pin instead. Then I could use the microSD card. Otherwise, the best storage for large amounts of data is not available.

Yes, both are stacked directly with the Arduino and powered through the USB.
Adding a 9v battery to the power socket does seem to rectify the dimming, but only a little.

My multimeter shows the +5v pin at +4.4v without the battery and +4.7v (though I think the battery is on it's way out anyway..
Will have to either knock together a mains supply or buy one if I don't have the parts, and test running only on the mains supply.

You are running out of power. I'll bet your regulator on the Arduino is getting a bit warm.

edit: If you are using the USB power, the resettable fuse is just about to shut down the power.

I do feel a little bit of warmth in there - I take it a proper supply such as mains would help that along?

I'm not sure that would help, but you can try. The Arduino has a linear regulator, so the closer you can get the Vin voltage to 7 volts, the better. Otherwise, that much current will cause it to get hot and fail.

There are discussions on the forum on whether it is ok to power the Arduino directly to the +5v rather than Vin. Some boards have been damaged by the attempt. The last I heard, The Arduino crew recommended you not do that.