Go Down

Topic: 16x2 LCD clear screen (Read 1 time) previous topic - next topic

AbdulW87

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: [Select]

...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

robtillaart

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.
Rob Tillaart

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

JimboZA

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
Arduino ethernet server here.... http://jimboza.gotdns.com:8085/

No PMs for help please

dc42

Here is one way:

Code: [Select]

// 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");
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.

AbdulW87


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.

AbdulW87


Here is one way:

Code: [Select]

// 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.

AbdulW87

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. :D

AbdulW87


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. :D


Code: [Select]
#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.

dc42


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.
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.

Go Up