Printing LCD sensor value with millis - Value stay not on screen

Hi all,

I’m trying to print DHT11 and BMP180 sensor values every 7 seconds on a TFT LCD screen.
I’m using millis for this. Below is my code.

The problem:
My values are only printed and vissible for a split second on the screen, and I can see it every 7 seconds as a blink, just as written in my interval line. After seen it in a blink the part of the screen where it was printed is black again without the value, for 7 seconds.

The goal:
Print the DHT sensor value on the screen, keep it there, and just only refresh it every 7 seconds.

What am I doing wrong?
I will only show the code for the specific page of the LCD screen, the rest is working fine.
This code is also working fine using delay. But I would like to make it work with millis.

Ino file attached. I can’t upload the whole code.

Thanks so much for your help.

//PRE SETUP 
  //== Defining Variables SENSORS   
   
  const long dhtReadIntervalTime = 5000;                //DHT Read Get data every 5 sec
  unsigned long dhtReadPreviousTime = 0;                //DHT Read start with previous time 0
  const long dhtPrintIntervalTime = 7000;               //DHT Print every 7 sec
  unsigned long dhtPrintPreviousTime = 0;               //DHT Print start with previous time 0

  
      //===BMP===SERIAL PRINT
  const long bmpReadTPIntervalTime = 5000;              //BMP Get Temp data every 5 sec
  unsigned long bmpReadTPPreviousTime = 0;              //BMP Get Temp start with previous time 0
  const long bmpPrintIntervalTime = 7000;               //BMP Print every 7 sec
  unsigned long bmpPrintPreviousTime = 0;               //BMP Print start with previous time 0


    //===DHT===TFT PRINT
  const long dhtTempTftIntervalTime = 7000;
  unsigned long dhtTempTftPreviousTime = 0;
  const long dhtHumidTftIntervalTime = 7000;
  unsigned long dhtHumidTftPreviousTime = 0;

    
    //=====BMP=====TFT PRINT
  const long bmpAltitudeTftIntervalTime = 7000;
  unsigned long bmpAltitudeTftPreviousTime = 7000;
  const long bmpTempTftIntervalTime = 7000;
  unsigned long bmpTempTftPreviousTime = 7000;
  const long bmpPressTftIntervalTime = 7000;
  unsigned long bmpPressTftPreviousTime = 7000;




//= Start SETUP
    void setup() {

      
    //=Initial setup
      myGLCD.InitLCD();
      myGLCD.clrScr();
      myTouch.InitTouch();
      myTouch.setPrecision(PREC_MEDIUM);
      
    //=Defining Pin Modes
      drawHomeScreen();                                 // Draws the Home Screen
      currentPage = '0';                                // Indicates that we are at Home Screen
      selectedUnit = '0';                               // Indicates the selected unit for the first example, cms or inches
    }



//==== Start LOOP
    void loop() { 



    //===SENSOR CONTROL
    void drawSensorControl() {
         
      myGLCD.setBackColor(0, 0, 0);                     
      myGLCD.setColor(100, 155, 203);                   
      myGLCD.fillRoundRect (5, 5, 55, 30);
      myGLCD.setColor(255, 255, 255);
      myGLCD.drawRoundRect (5, 5, 55, 30);
      myGLCD.setFont(BigFont);
      myGLCD.setBackColor(100, 155, 203);
      myGLCD.print("<-", 10, 10);
      
      myGLCD.setBackColor(0, 0, 0);                     
      myGLCD.setFont(BigFont);
      myGLCD.print("WEATHER STATION", 70, 5);

      myGLCD.setColor(255, 0, 0);
      myGLCD.drawLine(0,40,319,40);
      myGLCD.setBackColor(0, 0, 0);



      //==BMP ALTITUDE BOX CODE==
 
      myGLCD.setColor(223, 77, 55);                     //ALTITUDE 
      myGLCD.fillRoundRect (10, 50, 165, 75);
      myGLCD.setColor(225, 255, 255);
      myGLCD.drawRoundRect (10, 50, 165, 75);
      myGLCD.setBackColor(223, 77, 55);
      
      myGLCD.setColor(255, 255, 255);                   //Altitude 
      myGLCD.print("Altitude:", 15, 55);


      //==DHT TEMP BOX CODE==
 
      myGLCD.setColor(223, 77, 55);                     //TEMP 
      myGLCD.fillRoundRect (10, 85, 165, 110);
      myGLCD.setColor(225, 255, 255);
      myGLCD.drawRoundRect (10, 85, 165, 110);
      myGLCD.setBackColor(223, 77, 55);
      
      myGLCD.setColor(255, 255, 255);                   //Temp 
      myGLCD.print("Temp Dht:", 15, 90);


      //==DHT HUMID BOX CODE==
      
      myGLCD.setColor(223, 77, 55);                     //HUMID
      myGLCD.fillRoundRect (10, 120, 165, 145);
      myGLCD.setColor(255, 255, 255);
      myGLCD.drawRoundRect (10, 120, 165, 145);
      myGLCD.setBackColor(223, 77, 55);
      
      myGLCD.setColor(255, 255, 255);                   //Humid Text
      myGLCD.print("Humid:", 15, 125);


      //==BMP TEMP BOX CODE==
      
      myGLCD.setColor(223, 77, 55);                     //TEMP BMP 
      myGLCD.fillRoundRect (10, 155, 165, 180);
      myGLCD.setColor(255, 255, 255);
      myGLCD.drawRoundRect (10, 155, 165, 180);
      myGLCD.setBackColor(223, 77, 55);
      
      myGLCD.setColor(255, 255, 255);                   //TEMP BMP 
      myGLCD.print("Temp Bmp:", 15, 160);


      //==BMP PRESSURE BOX CODE==
      
      myGLCD.setColor(223, 77, 55);                     //PRESSURE BMP 
      myGLCD.fillRoundRect (10, 190, 165, 215);
      myGLCD.setColor(255, 255, 255);
      myGLCD.drawRoundRect (10, 190, 165, 215);
      myGLCD.setBackColor(223, 77, 55);
      
      myGLCD.setColor(255, 255, 255);                   //PRESSURE BMP 
      myGLCD.print("Pressure:", 15, 195);



      //==FOOTER==
      
      myGLCD.setBackColor(0, 0, 0);
      myGLCD.setFont(SmallFont);
      myGLCD.print("By Snake Dr.", CENTER, 220);  

    }



//=BMP - ALTITUDE=
      myGLCD.setBackColor(0, 0, 0);                     //BMP BOX Print actual altitude
      myGLCD.setColor(0, 0, 0);                 
      myGLCD.fillRoundRect (180, 50, 215, 75);          //Imaginairy location
      myGLCD.setColor(255, 255, 255);               
      myGLCD.print("Meter", 225, 60);

unsigned long bmpAltitudeTftCurrentTime = millis();
if ( bmpAltitudeTftCurrentTime - bmpAltitudeTftPreviousTime >= bmpAltitudeTftIntervalTime ) {
      myGLCD.printNumI(ALTITUDE, 185, 60);              //Print actual ALTITUDE in white

      bmpAltitudeTftPreviousTime = bmpAltitudeTftCurrentTime; //UPDATE TIMER
}



//=DHT - TEMP=
      myGLCD.setBackColor(0, 0, 0);                     //DHT BOX Print actual temp
      myGLCD.setColor(0, 0, 0);                  
      myGLCD.fillRoundRect (180, 85, 215, 130);         //Imaginairy location
      myGLCD.setColor(255, 255, 255);               
      myGLCD.print("Celcius", 225, 90);

unsigned long dhtTempTftCurrentTime = millis();
if (dhtTempTftCurrentTime - dhtTempTftPreviousTime >= dhtTempTftIntervalTime) {
      myGLCD.printNumI(DHT.temperature, 185, 90);       //Print actual temp in white

dhtTempTftPreviousTime = dhtTempTftCurrentTime; //UPDT TIMER
}



//=DHT - HUMIDITY=
      myGLCD.setBackColor(0, 0, 0);                     ///DHT BOX Print actual humid
      myGLCD.setColor(0, 0, 0);                 
      myGLCD.fillRoundRect (180, 120, 215, 145);        //Imaginairy location
      myGLCD.setColor(255, 255, 255);               
      myGLCD.print("%", 225, 125);

unsigned long dhtHumidTftCurrentTime = millis();
if (dhtHumidTftCurrentTime - dhtHumidTftPreviousTime >= dhtHumidTftIntervalTime) {
      myGLCD.printNumI(DHT.humidity, 185, 125);         //Print actual humid in white   

dhtHumidTftPreviousTime = dhtHumidTftCurrentTime; //UPDATE TIMER
}



//=BMP - TEMP=
      myGLCD.setBackColor(0, 0, 0);                     //BMP BOX Print temp
      myGLCD.setColor(0, 0, 0);                 
      myGLCD.fillRoundRect (180, 155, 215, 180);        //Imaginairy location
      myGLCD.setColor(255, 255, 255);               
      myGLCD.print("Celcius:", 225, 160);

unsigned long bmpTempTftCurrentTime = millis();
if ( bmpTempTftCurrentTime - bmpTempTftPreviousTime >= bmpTempTftIntervalTime ) {
      myGLCD.printNumI(T, 185, 160);                    //Print actual TEMP in white

      bmpTempTftPreviousTime = bmpTempTftCurrentTime; //UPDATE TIMER
}



//=BMP - PRESSURE=
      myGLCD.setBackColor(0, 0, 0);                     //BMP BOX Print actual Pressure
      myGLCD.setColor(0, 0, 0);                 
      myGLCD.fillRoundRect (180, 190, 215, 215);        //Imaginairy location
      myGLCD.setColor(255, 255, 255);               
      myGLCD.print("millibar:", 225, 195);

unsigned long bmpPressTftCurrentTime = millis();
if ( bmpPressTftCurrentTime - bmpPressTftPreviousTime >= bmpPressTftIntervalTime ) {
      myGLCD.printNumI(P, 185, 195);                    //Print actual PRESSURE in white

bmpPressTftPreviousTime = bmpPressTftCurrentTime; //UPDT TIMER

}
    } //END LOOP

Arduino_-_LCD_TFT_Test6.ino (22.4 KB)

Your code always wipes out the screen [BMP portion, there are others]

  //-----=====BMP - ALTITUDE=====-----
  myGLCD.setBackColor(0, 0, 0);                     //BMP BOX Print actual altitude
  myGLCD.setColor(0, 0, 0);
  myGLCD.fillRoundRect (180, 50, 215, 75);          //Imaginairy location
  myGLCD.setColor(255, 255, 255);
  myGLCD.print("Meter", 225, 60);

but then you check to see if it is time to redraw

  unsigned long bmpAltitudeTftCurrentTime = millis();
  if ( bmpAltitudeTftCurrentTime - bmpAltitudeTftPreviousTime >= bmpAltitudeTftIntervalTime ) {
    myGLCD.printNumI(ALTITUDE, 185, 60);              //Print actual ALTITUDE in white

    bmpAltitudeTftPreviousTime = bmpAltitudeTftCurrentTime; //UPDATE TIMER
  }

so what do you think happens then it is NOT time to redraw? You have already wiped out the previous value, and then you don't update the screen. All of that code should be inside your if() statement.

This pattern is repeated for all your other data as well

Hi blh64, thanks for your reply.

What do you mean with following?

blh64:
All of that code should be inside your if() statement.

I'm not sure if I understand which parts should be included in the if statement.

Thanks again.

You should check if it is time to update the display [the if() statement] and, if it is, then erase the screen and draw your values. If it is not, do nothing.