Go Down

Topic: Problem to erase LCD Screen afer displayed message (Read 743 times) previous topic - next topic

Catskan

Dec 11, 2012, 07:09 pm Last Edit: Dec 12, 2012, 09:31 am by Catskan Reason: 1
Hi,

For a few hours, I'm faced a problem with the LCD screen (LiquidCrystal).

I must, with a socket, send messages and display on the LCD Screen. The problem is that messages are displayed side by side but I would like they are erased for display another messages.

I search so to clear the LCD screen between each messages.

Here is my code (the comments are all my test) :
Code: [Select]
#include <LiquidCrystal.h>
#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network.
// gateway and subnet are optional:
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte mac[] = {
  0x90, 0xA2, 0xDA, 0x0D, 0x02, 0xC7 };
IPAddress ip(192, 168, 1, 17);
//IPAddress gateway(192,168,1, 1);
IPAddress subnet(255, 255, 255, 0);


EthernetServer server(23);
boolean alreadyConnected = false; // whether or not the client was connected previously

void setup() {
  Ethernet.begin(mac, ip, subnet);
  server.begin();
   lcd.clear();
  Serial.begin(9600);
  lcd.begin(16, 2);
}
void loop() {
  //wait for a new client:
int in=0,i;char message[16] = "";
  EthernetClient client = server.available();
  char thisChar;
 
  // when the client sends the first byte, say hello:
/* if (client) {
    if (!alreadyConnected) {
      // clead out the input buffer:
      client.flush();   
     //lcd.print("We have a new client");

      alreadyConnected = true;
     
    } */
  //i=0;

    if (client.available() > 0) {
      //in=1;
 
       thisChar = client.read();
       lcd.print(thisChar);
       delay(300);
       lcd.clear();
     
      /* server.write(thisChar);   
      message[i]=thisChar;
      i++;
      Serial.print("i");
      Serial.println(i);
      //delay(300);
     
      //sprintf(message, "%c", thisChar);
      Serial.print("message");
      Serial.println(message);
     
    }*/
    if(i!=0) message[i]=0;
    if (in==1){
      delay(3000);
      lcd.setCursor(1,0);
    in=0;
  }
}

}


Thanks you in advance for your help.

Cordialy,

(Sorry if my english isn't very good, i'm french).

robtillaart


use lcd.clear() to clear the screen where you want. If that does not work for your particular screen you might consider printing spaces to remove existing text.

And your English is good enough to describe your problem.

(please use CTRL-T before posting code to auto format the layout of the code -> makes it more readable)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Catskan

#2
Dec 12, 2012, 09:07 am Last Edit: Dec 12, 2012, 09:25 am by Catskan Reason: 1
Hi,

The problem is "lcd.clear()" erase totaly of screen. We havn't Time read the message.
But when I set a delay, the LCD screen display the message character by character ( I send a string ).

That's to say, he displays a first letter, The LCD is erased And he display the second letter And thus on.

(When use CTRL-T, i's opens a new tab ).

PS : I modified the code, when instructions is in a "setup" function, nothing display on LCD.

robtillaart

just noticed, you clear the screen before you define how big it is ...
Code: [Select]
void setup() {
  Ethernet.begin(mac, ip, subnet);
  server.begin();
   lcd.clear();
  Serial.begin(9600);
  lcd.begin(16, 2);
}

better swap those lines?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

floresta

Quote
just noticed, you clear the screen before you define how big it is ...

They must be copying this from somewhere - it's the third time I've seen it this week.

It is also totally unnecessary at this point since clearing the screen is part of the initialization routine that is handled by the library.


Quote
better swap those lines?

Just leave it out.

Don

Go Up