Weird LCD flicker

So, I´m still pretty new to the arduino and C thing, having some issues. I wrote a simple code to display the output from a DHT11 sensor on a 16x2 LCD screen, and it works very well but for a weird issue.

#include <LiquidCrystal.h>
#include <DHT.h>

#define DHTPIN 7

#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(0, 1, 2, 3, 4, 5);

void setup() {
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
}

void loop(){
// Print a message to the LCD.
lcd.setCursor(0,0);
lcd.print("Humi % ");
lcd.setCursor(6,0);
float hum=dht.readHumidity();
lcd.print(hum,1);
lcd.setCursor(0,1);
lcd.print("Temp C ");
lcd.setCursor(6,1);
float temp=dht.readTemperature();
lcd.print(temp,1);
delay(1000);
}

The issue is, the first output print fades in and out every 2s. I tried putting temp first, and it happened. Changed humi to first, and now it happens to humi!! The second output print is stable. And messing with the delay didnt change the 2s fade pattern. Just to be clear, all the text is stable, the only thing that fades is the sensor output on the first line. What could it be??

What could it be??

It sounds like a hardware problem.

Try a simple program that prints text to both LCD rows in setup() and does nothing in loop(). Does the text fade in and out ? If not then move the text printing to loop() and see what happens.

As a matter of interest why are you printing the fixed text over and over again in your original program when only the temperature and humidity change ?

try printing to the screen less frequently, like on a change only.

plus, you don’t have to back up the cursor if you print the three strings subsequently as in my example.

uncompiled, untested:

#include <LiquidCrystal.h>
#include <DHT.h>

#define DHTPIN 7

#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
floar oldHum, oldTemp;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(0, 1, 2, 3, 4, 5);

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

void loop()
{ 
  // Print a message to the LCD.
  float hum = dht.readHumidity();
  if (hum != oldHum)
  {
    lcd.setCursor(0,0);
    lcd.print("Humi: ");
    lcd.print(hum,1);
    lcdprint("%");
    oldHum = hum;
  }
  float temp=dht.readTemperature();
  if (temp != oldTemp)
  {
    lcd.setCursor(0,1);
    lcd.print("Temp: ");
    lcd.print(temp,1);
    lcd.print("C");
    oldTemp = temp;
  }
  delay(1000); 
}

UKHeliBob:

What could it be??

It sounds like a hardware problem.

Try a simple program that prints text to both LCD rows in setup() and does nothing in loop(). Does the text fade in and out ? If not then move the text printing to loop() and see what happens.

As a matter of interest why are you printing the fixed text over and over again in your original program when only the temperature and humidity change ?

I used some examples I found on the web, they all looked like that. But I moved the set texts to setup and left only the sensor readings to the loop and...it worked!! Thanks for the help

I'm glad that you got it working but it does not explain what the problem was.

Does this look a little odd to anyone else:

LiquidCrystal lcd(0, 1, 2, 3, 4, 5);

Doesn't the Serial object use pins 0 and 1 for communication? I can see that he's not using the Serial object, but are there any uses of those pins going on behind the scenes with the IDE? It's more common to see something like:

LiquidCrystal lcd(12, 11, 7, 6, 5, 4);

I try to avoid using pins 2 and 3 since they are often used for external interrupts. You might try rewiring the LCD and use an appropriately modified constructor.

Does this look a little odd to anyone else:

Yes. Well spotted.