Pages: [1]   Go Down
Author Topic: 16x2 LCD clear screen  (Read 977 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey guys,

new to the forum, am doing a project and having problems with the LCD. I have tried searching in the forums for a solution but i couldnt find exactly what i was looking for. I am using an RHT03 sensor a 16x2 lcd and arduino uno board with atmega8-p chip. i used the examples to build a code to display the status of the sensor, the humidity and the temperature. The problem is when i remove the sensor wires to check if the code is working correctly (it will show error messages on LCD) the lcd displays the error messages but when everything is back to original position, part of the error messages remain on the blocks which are not being used.

i am at home and the code is at university computer so i cannot share the full code and uni computers wont let me login to this forum (cookies not enabled), so the part of code is
Code:
...condition code here...
lcd.setCursor (0, 1);
lcd.print("OK");

...second condition code here...
lcd.setCursor(0,1);
lcd.print("CHKSM");

now when the OK condition is fulfilled (everything back to original position) the LCD displays "OKKSM". i tried lcd.clear but it messes up the whole thing. the solution to this problem, which just came to my mind, could be that i change the lcd.print("OK"); to lcd.print("OK   "); three spaces will take care of this. But the same thing happens to humidity and temperature readouts and i cannot do the same to them.

if any one can help me asap i would very much appreciate it.

regards
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12451
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you can put the code on a memeory stick so there is a workaround for posting code.

How is your project powered?

If the power supply has too little power all sort of misbehaviour can happen.
Logged

Rob Tillaart

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

Johannesburg UTC+2
Offline Offline
Faraday Member
**
Karma: 60
Posts: 3242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
the solution to this problem, which just came to my mind, could be that i change the lcd.print("OK"); to lcd.print("OK   ")

I think (but not 100% certain) that that is a common way to get rid of the remnants of previous prints
Logged

Have you looked for answers in the Learning, Reference, Products and Playground tabs on http://arduino.cc/en/ ?
Look here http://electronicsclub.info/ for basic electronics

United Kingdom
Offline Offline
Tesla Member
***
Karma: 220
Posts: 6587
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is one way:

Code:
// Clear the whole of line 1
lcd.setCursor (0, 1);
for (int i = 0; i < 16; ++i)
{
  lcd.write(' ');
}
// Now write a message to line 1
lcd.setCursor (0, 1);
lcd.print("OK");
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you can put the code on a memeory stick so there is a workaround for posting code.

How is your project powered?

If the power supply has too little power all sort of misbehaviour can happen.


it is powered via a usb so i am guessing +5V which should be enough as the LCD is the only big thing.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is one way:

Code:
// Clear the whole of line 1
lcd.setCursor (0, 1);
for (int i = 0; i < 16; ++i)
{
  lcd.write(' ');
}
// Now write a message to line 1
lcd.setCursor (0, 1);
lcd.print("OK");

will try this code tomorrow, i am thinking i will insert these lines of code only in the OK case and not the other conditions. Am i approaching this right.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i am just going to connect to the anywhere desktop so i can copy the code to give a better picture of my code and maybe improve it a bit. smiley-grin
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i am just going to connect to the anywhere desktop so i can copy the code to give a better picture of my code and maybe improve it a bit. smiley-grin

Code:
#include <dht.h>

#include <LiquidCrystal.h>


dht DHT;



#define DHT22_PIN 6



// initialize the library with the numbers of the interface pins

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

// variables:


void setup() {

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

  // Print a message to the LCD.

  lcd.print("DHT");

 
  lcd.setCursor(5, 0);

  lcd.print("H/%");

  lcd.setCursor(11, 0);

  lcd.print("T/oC");

}



void loop()
 {
 

    // READ DATA

    int chk = DHT.read22(DHT22_PIN);

    switch (chk)

    {

        case DHTLIB_OK:


            lcd.setCursor(0, 1);

            lcd.print("OK");
 
            break;


        case DHTLIB_ERROR_CHECKSUM:

            lcd.setCursor(0, 1);

            lcd.print("CHKSM");
 
            break;


        case DHTLIB_ERROR_TIMEOUT:

            lcd.setCursor(0, 1);

            lcd.print("TMOUT");
 
            break;


        default:

            lcd.setCursor(0, 1);

            lcd.print("UKOWN");
 
            break;

    }

    // DISPLAY DATA

    lcd.setCursor(5, 1);

    lcd.print(DHT.humidity, 1); //displays humidity to 1 decimal place
    lcd.setCursor(11, 1);

    lcd.print(DHT.temperature, 1); //displays temperature to 1 decimal place
    delay(1000);
 


}

the DHT part of the code was taken from a tutorial online but modified according to requirement.
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 220
Posts: 6587
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

will try this code tomorrow, i am thinking i will insert these lines of code only in the OK case and not the other conditions. Am i approaching this right.

Use that code wherever you are about to write a line of text that might be shorter than the one already displayed.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Pages: [1]   Go Up
Jump to: