LCD Time Delayed Updates?

Hello!

First of all, I just want to say that not only am I new to Arduino, but I'm very bad at coding in general. So if you have any suggestions, I would very much appreciate as much detail and how-to info as you can offer.

What I have have is an Arduino UNO with a 20x4 I2C LCD display being fed information from various sensors to operate a automated greenhouse.

What I would like to do is prevent the screen from flashing by updating the LCD every few minutes without using the delay function, or to only update the parts of the screen displaying sensory inputs.

NOTE: I have the <RBD_Timer.h> library installed to control some of the other time-controlled functions such as shutting on/off LED strips, fans, and a water pump.

Here is the LCD function:

int LCD () { 
  
  //Activate & Read moisture sensors
  digitalWrite(sensorVCC, HIGH);
  sensorValue = analogRead(sensorPin); 
  sensorValue1 = analogRead(sensorPin1);
  sensorValue2 = analogRead(sensorPin2);
  sensorValue3 = analogRead(sensorPin3);
  digitalWrite(sensorVCC, LOW);
  
  //Check temp sensor
  int chk = DHT.read11(DHT11_PIN);
  
  //Print info on 20x4 LCD screen with I2C
  lcd.begin (20,4);     
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH); 
  lcd.setCursor (8,0);
  lcd.print ("GAEA");
  lcd.setCursor(0,1); 
  lcd.print("Temp = ");
  lcd.print(DHT.temperature);
  lcd.print ("C");
  lcd.setCursor(0,2);
  lcd.print("Humidity = ");
  lcd.print(DHT.humidity);
  lcd.print ("%");
  lcd.setCursor(0,3);
  lcd.print("AVG. Moisture = ");
  lcd.print((sensorValue1 + sensorValue2 + sensorValue3)/3);
}

Thank you!!

Would you explain what you mean by "prevent the screen from flashing"?

.

You should only be using lcd.begin() once, in setup().

Don

I mean when the code is running, the screen flashes on and off every time it is updated and I am trying to fix that.

. . . What I would like to do is prevent the screen from flashing by updating the LCD every few minutes without using the delay function, or to only update the parts of the screen displaying sensory inputs. . . .

You can't achieve either of these if you first clear the screen which is precisely what lcd.begin() does as part of it's sequence.

Don

The trick is to only update the things that have changed.

lcd.begin, lcd.clear, "Temp = xxxxx C", "Humidity = xxx %", "AVG. Moisture = "
should all be printed ONCE (could be in setup).

to fill in the values:

lcd.setCursor(7,1); // start printing on the eight position
lcd.print(DHT.temperature);
etc.

An if() statement, e.g. if (temp < 10), could add a space to overwrite previous 2.xx digit data.

Leo..

Thank you so much! I'll give these a shot!