Strange DHT22 electrical issue or code error (maybe)

Hi all, I've just set up a system with an arduino uno and a dht22.

Everything run fine, it goes exactly as it is supposed to but there is a weird problem.
After some hours (I don't know how many) the LCD goes completely white (there is no code with this thing) but it seems that it is still working.
If I reset with reset button or replug the power adapter it does start but after some hours again it goes white (it looks like there is "too much data to handle" or something like that).
Are there some noticeable errors in my code? here it is:

#include "DHT.h"
#include <TFT.h>
#include <SPI.h>

#define cs   10
#define dc   9
#define rst  8
#define DHTPIN 2
#define DHTTYPE DHT22
#define RELAY1  3                       
#define RELAY2  5                        
#define RELAY3  6                        
#define RELAY4  7

DHT dht(DHTPIN, DHTTYPE);

TFT TFTscreen = TFT(cs, dc, rst);
char sensorPrintout[4];
char sensorPrintout1[4];

void setup() {

  TFTscreen.begin();
  TFTscreen.background(0, 0, 0);
  TFTscreen.stroke(255, 255, 255);
  TFTscreen.setTextSize(2);
  TFTscreen.text("Temperatura\n     *C", 0, 0);
  TFTscreen.text("Umidita'\n     %", 0, 70);
  TFTscreen.setTextSize(5);
  
  Serial.begin(9600);
  Serial.println("Avvio automazione");
  pinMode(RELAY1, OUTPUT);       
  pinMode(RELAY2, OUTPUT);
  pinMode(RELAY3, OUTPUT);
  pinMode(RELAY4, OUTPUT);
  dht.begin();
  }

void loop() {

 delay(100);
  int h = dht.readHumidity();
  int t = dht.readTemperature();
  int f = dht.readTemperature(true);
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Errore sensore");
    return;
  }
  float hif = dht.computeHeatIndex(f, h);
  float hic = dht.computeHeatIndex(t, h, false);
  Serial.print("Umidita':");
  Serial.print(h);
  Serial.print(" %");
  Serial.print("Temperatura:");
  Serial.print(t);
  Serial.println(" *C");
 
    static boolean running = false;
    
    if(t >=  25 && running == false)
    {
        digitalWrite(RELAY1, LOW);
        running = true;
    }
    else if(t <= 20 && running == true)
    {
        digitalWrite(RELAY1, HIGH);
        running = false;
    }
 if(t < 15)
  {
    digitalWrite(RELAY2, LOW);}
  else
  {
    digitalWrite(RELAY2, HIGH);}
 if(h > 10)
  {
    digitalWrite(RELAY3, LOW);}
  else
  {
    digitalWrite(RELAY3, HIGH); }
 if(t < 15)
  {
    digitalWrite(RELAY4, LOW); }
  else
  {
    digitalWrite(RELAY4, HIGH); }

  String sensorVal = String(t);
  sensorVal.toCharArray(sensorPrintout, 4);
  TFTscreen.stroke(255, 255, 255);
  TFTscreen.text(sensorPrintout, 0, 20);
  String sensorVal1 = String(h);
  sensorVal1.toCharArray(sensorPrintout, 4);
  TFTscreen.text(sensorPrintout, 0, 90);
  delay(2000);
  TFTscreen.stroke(0, 0, 0);
  sensorVal.toCharArray(sensorPrintout, 4);
  TFTscreen.text(sensorPrintout, 0, 20);
  sensorVal1.toCharArray(sensorPrintout, 4);
  TFTscreen.text(sensorPrintout, 0, 90);
}

If the code is correct, then I suppose there is an electrical problem due to the power supply. I'm using a 9V 1a.

Thank you for any support

Using the String class is probably the cause of the weird crashes. Convert the temperature directly to a char array with sprintf instead of converting temperature to a String and then to a char array.

Replace this:

  String sensorVal = String(t);
  sensorVal.toCharArray(sensorPrintout, 4);
  TFTscreen.stroke(255, 255, 255);
  TFTscreen.text(sensorPrintout, 0, 20);
  String sensorVal1 = String(h);
  sensorVal1.toCharArray(sensorPrintout, 4);
  TFTscreen.text(sensorPrintout, 0, 90);
  delay(2000);
  TFTscreen.stroke(0, 0, 0);
  sensorVal.toCharArray(sensorPrintout, 4);
  TFTscreen.text(sensorPrintout, 0, 20);
  sensorVal1.toCharArray(sensorPrintout, 4);
  TFTscreen.text(sensorPrintout, 0, 90);

with this:

  sprintf(sensorPrintout,"%3d",t);
  sprintf(sensorPrintout1,"%3d",h);

  TFTscreen.stroke(255, 255, 255);
  TFTscreen.text(sensorPrintout, 0, 20);
  TFTscreen.text(sensorPrintout, 0, 90);
  
  delay(2000);
  
  TFTscreen.stroke(0, 0, 0);
  TFTscreen.text(sensorPrintout, 0, 20);
  TFTscreen.text(sensorPrintout, 0, 90);

You may have to adjust the "%3d" strings in the sprintf so that they produce the same format as toCharArray (which I've never used). You might need %2d instead. But beware that you've declared those two array as [4] so you can't store more than three chars in them to allow for the null on the end.

Pete

Thank you Pete, I've just uploaded the sketch and it seems ok at the moment. I'll let you know if it goes white again or not.

Thank you again very much