Go Down

Topic: command lcd.clear() does not work (Read 937 times) previous topic - next topic

tom15

Hi
     I recently purchased the Arduino Mega 2560 R3 and attached it to my HD44780A00 controlled lcd screen.  For some reason the command[  lcd.clear()  ]is not working.  I do not want to post all my code so here is just a sample;

#include <LiquidCrystal.h>
 

LiquidCrystal lcd(0,1,2,3,4,5);
 
void setup(){
 
  lcd.begin(40, 2);
  lcd.clear();     
}
  void loop() {
    lcd.println("hello my friend");
    delay(2000);
   lcd.clear(); // this command does not work
    lcd.println("how are you");
  }
Is this a software or hardware error?  Does anyone know the cause of this?
Thank you

floresta

#1
Feb 25, 2015, 02:25 am Last Edit: Feb 25, 2015, 02:29 am by floresta Reason: Fix typos
Quote
Is this a software or hardware error?  
Probably.

Quote
lcd.clear(); // this command does not work
What do you mean by that?

What did you see on the display during the first delay period?

What did you expect to see during that period?

What did you see on the display during the second delay period?

What did you expect to see during that period?


In general:

(1) You do not need an lcd.clear() statement immediately after lcd.begin() since the display is cleared as part of the initialization.

(2) You should not use the undocumented lcd.println() command.  It is undocumented because it does not do what you expect it to do.

(3) If possible you should try to avoid using lcd.clear() in loop().


ALSO: You should put your code into a code block so that it is more legible.  Highlight the part of your post that is code and use the 'code' button (it looks like a scroll with < > in front).

Don


bperrybap

#2
Feb 26, 2015, 08:06 am Last Edit: Feb 26, 2015, 08:08 am by bperrybap Reason: changed tags for examples
As Don alluded to:
Neither the library nor the display handle end of line processing
so println() won't give you what you are probably expecting/wanting.

Also, depending on what else the sketch is doing, using digital pins 0 and
1 is not a good idea since those are used for the serial port interface.


Based on that code here is what I would expect:

setup:
- lcd.begin()  will initialize the display which clears it.
- lcd.clear() clears the display again.

loop:
lcd.println(...) prints:
hello my friend**
on the top line of the display
(where the * characters are garbage/unpredictable characters)
then a 2 second time delay.
lcd.clear() clears the display
lcd.println(...) prints:
how are you**
(where the * characters are garbage/unpredictable characters)
on the top line, since the clear worked and positioned cursor back to 0,0
Then with no delay this starts over.

So when the loop starts over the display contains:
how are you**
on the top line and this will immediately be added to the top line:
hello my friend**
To make the to line look like this:
how are you**hello my friend**
all on the top line.
Then the 2 second delay,
and the loop continues repeating this.

I'm assuming that this is what you got and is not what you wanted.


--- bill


Go Up