简体   繁体   中英

LCD doesnt display as desired with Arduino

I have a problem working with the LCD and Arduino.

When i use the example code for LiquidCrystal.h that displays HelloWorld the LCD works perfect. But when I add the same as part of another code, the LCD doesnt display well. it just flickers a few letters and then gradually fades away.

Basically I want to display the data that I get from a computer's browser that is connected to the same network that the Ethernet Shield is connected to. But I am just trying display the basic one so that I can edit accordingly.

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

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

boolean incoming = 0;

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDA, 0x02 };
IPAddress ip(192,168,0,117); 

EthernetServer server(80);

void setup()
{
  lcd.begin(16, 2);
  lcd.print("hello, world!");

  Serial.begin(9600);
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.println("My IP Address is: ");
  Serial.println(Ethernet.localIP());
}

void loop()
{

  lcd.setCursor(0,1);
  lcd.print(millis() / 1000);

  EthernetClient client = server.available();
  if (client) {

    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        if(incoming && c == ' '){ 
          incoming = 0;
        }

        if(incoming == 1){
          Serial.println(c);
        }

        if(c == '$'){ 
          incoming = 1; 
        }



        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } 
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }

    delay(1);
    client.stop();
  }
}

The example code that works is:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  lcd.begin(16, 2);
  lcd.print("hello, world!");
}

void loop() {
  lcd.setCursor(0, 1);
  lcd.print(millis() / 1000);
}

It looks like you have a conflict between the pins used for the LCD and the pins used for the Ethernet shield.

If you're using an Uno, the Ethernet shield uses the SPI bus on pins 11, 12, and 13. This line from your code:

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

says that you're also using pins 11 and 12 for the LCD .

You probably need to use different pins for the display or use a different board like an Arduino Mega, which gives you more choices for the SPI bus.

Which LCD and ethernet hardware are you using? For example, if you use LCD-Display on top of Arduino ethernet-shield, there is a hardware conflict and you actually have to do some modification (in my case, cut pin 10 from the LCD). Pls let us know your hardware setup.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM