Refreshing an LCD

Hi there, I'm posting this within the Programming section to see if I get a better response with assistance in coding a TFT LCD to actively update without leaving any pixels hanging.

I'm using a DHT11 sensor to measure temp/humidity and then have the Adafruit ST7735 1.8" TFT LCD shield display the values. Now this is just sample coding I'm using to start a project of mine so I really need to learn how to control this display better before I make the bigger part of the coding. The code I have now displays the temp and humidity readouts from the DHT11 on the TFT LCD, the arduino is set to read the DHT11 every 5 sec, so naturally if the temp or humidity changes I want the TFT LCD to show that. Thing is if I left the fillscreen code out, the sensors new reads will just write over themselves making it unreadable. I know this has been done before because I've seen some peoples projects have smoother refresh rates with the ST7735, or that is they just had the screen refresh only the areas that have changed without using the fillscreen option. Trust me, my coding makes the screen blink every 5 secs and I would rather something smoother. Can anyone help me here with writing some simple code for this to only erase the old values off the screen and write the new ones without refreshing the whole screen?

#define cs   10
#define dc   8
#define rst  -1
#define DHT11PIN 2

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include <dht11.h>

dht11 DHT11;

Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst);

void setup() {
  tft.initR(INITR_REDTAB);
}

void loop() {
  tft.fillScreen(ST7735_BLACK);
  tft.setCursor(35, 0);
  tft.setTextColor(ST7735_RED);
  tft.print("* Farhenheit");
  tft.setTextColor(ST7735_BLUE);
  tft.setCursor(15, 50);
  tft.print("% Humidity");
  int chk = DHT11.read(DHT11PIN);
  tft.setTextColor(ST7735_RED);
  tft.setCursor(0, 0);
  tft.print(Fahrenheit(DHT11.temperature));
  tft.setTextColor(ST7735_BLUE);
  tft.setCursor(0, 50);
  tft.print(DHT11.humidity);
  delay(5000);
}

double Fahrenheit(double celsius)
{
        return 1.8 * celsius + 32;
}

On another note, does anyone know how to eliminate the two extra digits off the Temp read? You know round it up, for example 77.50 º F would be 78 º F instead.

I'm honestly not asking this because I'm lazy, I'm asking this because I can't find any sample coding that does what I need so I could apply it to my project.

Before you refresh a variable on screen write a blank or pace for every character printed that needs to be refreshed, Then print the new value.
I own one of the Adafruit ST7735 displays and that's what I did to refresh time when I reprinted the new seconds, minutes...

Bob

Before you refresh a variable on screen write a blank or pace for every character printed that needs to be refreshed, Then print the new value.
I own one of the Adafruit ST7735 displays and that's what I did to refresh time when I reprinted the new seconds, minutes...

Bob

Yeah, lol I thought of this as soon as I logged for the evening. Something about taking a break help me think a little harder about how I could code this. So I just took a few minutes this afternoon to write in that bit of code and now I can refresh it nicely without having the whole screen blink.

#define cs   10
#define dc   8
#define rst  -1
#define DHT11PIN 2

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include <dht11.h>

dht11 DHT11;
double temp;
int humidity;

Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst);

void setup() {
  tft.initR(INITR_REDTAB);
  tft.fillScreen(ST7735_BLACK);
  tft.setCursor(35, 0);
  tft.setTextColor(ST7735_RED);
  tft.print("o");
  tft.setCursor(45, 2);
  tft.print("Fahrenheit");
  tft.setTextColor(ST7735_BLUE);
  tft.setCursor(15, 50);
  tft.print("% Humidity");
}

void loop() {
  
  int chk = DHT11.read(DHT11PIN);
  tft.setTextColor(ST7735_BLACK);
  tft.setCursor(0, 2);
  tft.print(temp);
  tft.setTextColor(ST7735_RED);
  tft.setCursor(0, 2);
  tft.print(Fahrenheit(DHT11.temperature));
  temp = (Fahrenheit(DHT11.temperature));
  tft.setTextColor(ST7735_BLACK);
  tft.setCursor(0, 50);
  tft.print(humidity);
  tft.setTextColor(ST7735_BLUE);
  tft.setCursor(0, 50);
  tft.print(DHT11.humidity);
  humidity = (DHT11.humidity);
  delay(5000);
}

double Fahrenheit(double celsius)
{
        return 1.8 * celsius + 32;
}

This sample should do just fine to help me code the bigger portion of my project. The next thing I have to work on is interfacing a relay controller that will flip a few low voltage solenoid valves.

Thanks

Docedison:
Before you refresh a variable on screen write a blank or pace for every character printed that needs to be refreshed, Then print the new value.
I own one of the Adafruit ST7735 displays and that's what I did to refresh time when I reprinted the new seconds, minutes...

Bob

I have the 2.2 TFT LCD display (Overview | 2.2" TFT Display | Adafruit Learning System) from Adafruit and this method does not work!
if I print blanks on the same line, the characters are still there!

The library they used is here GitHub - adafruit/Adafruit-HX8340B: Adafruit 2.2" TFT with SPI interface and microSD card holder and I also use the Adafruit_GFX lib.

Any thought?