Question

Problem

I can't get my Arduino Uno's LiquidCrystal library to print to my LCD screen when using the Ethernet library (and shield, of course).

Code

#include <SPI.h>
#include <Ethernet.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};

EthernetClient client;

String text = "Original Text";

void setup() {
  // Set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);

  // Print a message to the LCD.
  lcd.print("Setup Text");

  // We have serial, but no milk!
  Serial.begin(9600);
}

void loop() {
  text = "Altered Text";
  if (Ethernet.begin(mac) != 0) {
      Serial.println("Some Ethernet work...");
  }

  lcd.setCursor(0, 1);
  lcd.print(text);
}

Expected Result

Let represent a blank character.

The screen should print:
Setup▓Text▓▓▓▓▓▓
Altered▓Text▓▓▓▓

While Some Ethernet work... prints to Serial.

Actual Result

The screen prints:
Setup▓Text▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

While Some Ethernet work... prints to Serial.

Notes

If I comment out the Ethernet code in the loop, I get the Expected Result.

My question is similar -- but not identical to -- this question:
Arduino code anomalies - LCD fails with multiple 'if' statements

I don't believe my problem is a shortage of memory. I am using the most up-to-date Ethernet library, which fixes a memory leak bug from a previous version.

Was it helpful?

Solution

I found the answer here: https://electronics.stackexchange.com/questions/29240/arduino-uno-ethernet-shield-16x2-lcd-not-initializing

@ben as per the page here, the comment by user "njohnson" states that the shield uses all the digital pins except 1,2 and 8. based on this i tried hooking up the lcd to the 6 analog pins (as outputs) and its working fine now. Now the question is where/how can i study the shield schematic to be sure what all pins can i use. On a side now, it seems an unusual design decision since using the shield means sacrificing 13 of the digital pins ! – Ankit Apr 3 '12 at 21:14

Solution

I moved the LCD pins to analog pins (14-19).

Code Modifications

Change LiquidCrystal lcd(7, 8, 9, 10, 11, 12); to LiquidCrystal lcd(19, 18, 17, 16, 15, 14); and move the LCD screen pins accordingly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top