RTC, LCD, DHT Problem in void loop()

Hello,

For some reason there is a problem in my void loop section.
I try to display the day, month, clock, date, temp and humidity.
that all worked fine in the past but now wen i wanna change the time to the new
time i get allot of characters flickering over the lcd.
And every second the time is barley visible.

The things that are connected are:

A 20x4 blue LCD on SCL, SDA
A DHT Sensor on pin 2
A RTC DS3231 on SCL, SDA

Can someone help me please.

This is my code:

#include <Wire.h>
#include <DS3231.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"

DS3231 rtc(SDA, SCL); //SDA, SCL
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);


byte newCharHorizontal[] = {
        B00000,
        B11111,
        B00000,
        B00000,
        B00000,
        B00000,
        B00000,
        B00000
};

byte newCharVerticalLeft[] = {
        B01000,
        B01000,
        B01000,
        B01000,
        B01000,
        B01000,
        B01000,
        B01000
};

byte newCharVerticalRight[] = {
        B00010,
        B00010,
        B00010,
        B00010,
        B00010,
        B00010,
        B00010,
        B00010
};

byte newCharLeftCorner[] = {
        B01000,
        B11000,
        B00000,
        B00000,
        B00000,
        B00000,
        B00000,
        B00000
};

byte newCharRightCorner[] = {
        B00010,
        B00011,
        B00000,
        B00000,
        B00000,
        B00000,
        B00000,
        B00000
};

byte newCharLogoTop[] = {
        B00000,
        B00000,
        B00000,
        B00000,
        B00000,
        B00000,
        B11111,
        B00000
};

byte newCharLogoBottom[] = {
        B00000,
        B11111,
        B00000,
        B00000,
        B00000,
        B00000,
        B00000,
        B00000
};

byte newCharLogoBottomLeftCorner[] = {
        B00010,
        B00011,
        B00000,
        B00000,
        B00000,
        B00000,
        B00000,
        B00000
};

byte newCharLogoBottomRightCorner[] = {
        B01000,
        B11000,
        B00000,
        B00000,
        B00000,
        B00000,
        B00000,
        B00000
};

byte newCharLogoTopLeftCorner[] = {
        B00000,
        B00000,
        B00000,
        B00000,
        B00000,
        B00000,
        B00011,
        B00010
};

byte newCharLogoTopRightCorner[] = {
        B00000,
        B00000,
        B00000,
        B00000,
        B00000,
        B00000,
        B11000,
        B01000
};

byte newCharLogoVerticalLeft[] = {
        B01000,
        B01000,
        B01000,
        B01000,
        B01000,
        B01000,
        B01000,
        B01000
};

byte newCharLogoVerticalRight[] = {
        B00010,
        B00010,
        B00010,
        B00010,
        B00010,
        B00010,
        B00010,
        B00010
};

byte newCharDegreesCelcius[] = {
        B01000,
        B10100,
        B01000,
        B00011,
        B00100,
        B00100,
        B00011,
        B00000
};

byte newCharBlock[] = {
        B11111,
        B11111,
        B11111,
        B11111,
        B11111,
        B11111,
        B11111,
        B11111
};

void setup() {
 dht.begin();
 rtc.begin();
 //rtc.setTime(18, 53, 00);
 //rtc.setDate(16, 02, 2020);
 lcd.begin(20,4);
 lcd.createChar(5, newCharLogoTop);
 lcd.createChar(6, newCharLogoBottom);
 lcd.createChar(7, newCharLogoBottomLeftCorner);
 lcd.createChar(8, newCharLogoBottomRightCorner);
 lcd.createChar(9, newCharLogoTopLeftCorner);
 lcd.createChar(10, newCharLogoTopRightCorner);
 lcd.createChar(11, newCharLogoVerticalLeft);
 lcd.createChar(12, newCharLogoVerticalRight);

 // Top Lines
 lcd.setCursor(3,0);
 lcd.write(byte(5));
 lcd.setCursor(4,0);
 lcd.write(byte(5));
 lcd.setCursor(5,0);
 lcd.write(byte(5));
 lcd.setCursor(6,0);
 lcd.write(byte(5));
 lcd.setCursor(7,0);
 lcd.write(byte(5));
 lcd.setCursor(8,0);
 lcd.write(byte(5));
 lcd.setCursor(9,0);
 lcd.write(byte(5));
 lcd.setCursor(10,0);
 lcd.write(byte(5));
 lcd.setCursor(11,0);
 lcd.write(byte(5));
 lcd.setCursor(12,0);
 lcd.write(byte(5));
 lcd.setCursor(13,0);
 lcd.write(byte(5));
 lcd.setCursor(14,0);
 lcd.write(byte(5));
 lcd.setCursor(15,0);
 lcd.write(byte(5));
 lcd.setCursor(16,0);
 lcd.write(byte(5));

 // Bottom Lines
 lcd.setCursor(3,3);
 lcd.write(byte(6));
 lcd.setCursor(4,3);
 lcd.write(byte(6));
 lcd.setCursor(5,3);
 lcd.write(byte(6));
 lcd.setCursor(6,3);
 lcd.write(byte(6));
 lcd.setCursor(7,3);
 lcd.write(byte(6));
 lcd.setCursor(8,3);
 lcd.write(byte(6));
 lcd.setCursor(9,3);
 lcd.write(byte(6));
 lcd.setCursor(10,3);
 lcd.write(byte(6));
 lcd.setCursor(11,3);
 lcd.write(byte(6));
 lcd.setCursor(12,3);
 lcd.write(byte(6));
 lcd.setCursor(13,3);
 lcd.write(byte(6));
 lcd.setCursor(14,3);
 lcd.write(byte(6));
 lcd.setCursor(15,3);
 lcd.write(byte(6));
 lcd.setCursor(16,3);
 lcd.write(byte(6));

 // Corners
 lcd.setCursor(2,0);
 lcd.write(byte(9));
 lcd.setCursor(2,3);
 lcd.write(byte(7));
 lcd.setCursor(17,0);
 lcd.write(byte(10));
 lcd.setCursor(17,3);
 lcd.write(byte(8));

 // Vertical Lines
 lcd.setCursor(2,1);
 lcd.write(byte(12));
 lcd.setCursor(2,2);
 lcd.write(byte(12));
 lcd.setCursor(17,1);
 lcd.write(byte(11));
 lcd.setCursor(17,2);
 lcd.write(byte(11));

 
 lcd.setCursor(5,1);
 lcd.print("DV Servers");
 lcd.setCursor(3,2);
 lcd.print("Danny Verhaert");

 delay(5000);
 lcd.clear();
 
}

void loop() {
 lcd.createChar(0, newCharHorizontal);
 lcd.createChar(1, newCharVerticalLeft);
 lcd.createChar(2, newCharLeftCorner);
 lcd.createChar(3, newCharRightCorner);
 lcd.createChar(4, newCharVerticalRight);
 lcd.createChar(13, newCharDegreesCelcius);
 lcd.createChar(14, newCharBlock);

 // Left Corner
 lcd.setCursor(3,0);
 lcd.write(byte(1));

 lcd.setCursor(0,1);
 lcd.write(byte(0));

 lcd.setCursor(1,1);
 lcd.write(byte(0));

 lcd.setCursor(2,1);
 lcd.write(byte(0));

 lcd.setCursor(3,1);
 lcd.write(byte(2));

 // Right Corner
 lcd.setCursor(16,0);
 lcd.write(byte(4));

 lcd.setCursor(16,1);
 lcd.write(byte(3));

 lcd.setCursor(18,1);
 lcd.write(byte(0));

 lcd.setCursor(19,1);
 lcd.write(byte(0));

 lcd.setCursor(17,1);
 lcd.write(byte(0));


 float h = dht.readHumidity();
 float t = dht.readTemperature();

  if (isnan(h) || isnan(t)) {

    lcd.setCursor(0,3);
    lcd.println(F("N/A"));
    return;
    
  }

 float hic = dht.computeHeatIndex(t, h, false);
 lcd.setCursor(14,3);
 lcd.print(h);
 lcd.print("%");
 
 lcd.setCursor(0,0);
 lcd.print(rtc.getDOWStr(FORMAT_SHORT ));
 
 lcd.setCursor(17,0);
 lcd.print(rtc.getMonthStr(FORMAT_SHORT));
 
 lcd.setCursor(6,1);
 lcd.print(rtc.getDateStr(FORMAT_SHORT, FORMAT_LITTLEENDIAN, '/'));

 lcd.setCursor(6,2);
 lcd.print(rtc.getTimeStr());
 
 lcd.setCursor(0,3);
 lcd.print(t);
 //lcd.print(rtc.getTemp() - 2);
 lcd.write(byte(13)); //
}

Thank you in advance.
Danny

Most likely You made some little mistake in the last change of the code. Flickering LCD is easily caused by sending characters at too high rate.
As I see loop() is running at really full speed. Can You try and update the display some 2 - 5 times per second? No human eye will properly read changes made at 10 Hz or more.

I would recommend that you create the second set of custom characters at the end of set up, and not each pass through loop.

Hello,

First of all thank you for your help and reply.
Second, i'm sorry for the late response but i have been busy with work.

About the problem.
The strangest thing happened.
Because of my time-consuming job i forgot to unplug the device and after a while it stopped showing the random characters on the display.
The characters stood still on the display, so i performed a reset and now it works almost perfect.
Only the day is not shown correct, while the date is correct.

I'm using this famous script to set the time on the RTC DS3231.

The message is more then 9000 characters long so i put the file on my website.

Click here to see the RTC SET *.ino file