ESP32 tft screen bug

So, trying to put the text from sensors on the tft screen of ESP32 reverse tft. It shows me the part of the.

#include <Arduino.h>
#include <Adafruit_AHTX0.h>
#include <SPI.h>
#include <Adafruit_NeoPixel.h>
#include <Adafruit_ST7789.h>
#include <Adafruit_BMP280.h>
#include <Adafruit_GFX.h>
Adafruit_BMP280 bmp; 
Adafruit_AHTX0 aht;
Adafruit_ST7789 tftscreen = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

void setup() {
  pinMode(13, OUTPUT);
  pinMode(TFT_BACKLITE, OUTPUT);
  pinMode(TFT_I2C_POWER, OUTPUT);
  digitalWrite(TFT_BACKLITE, HIGH);
  digitalWrite(TFT_I2C_POWER, HIGH);
  delay(10);
  tftscreen.init(135,240);
  tftscreen.setRotation(3);
  tftscreen.fillScreen(ST77XX_BLACK);

  Serial.begin(115200);
  while (!Serial) {
    delay(10); 
  }
  if (!bmp.begin()) {
    Serial.println("Could not find BMP280? Check wiring");
    while (1) delay(10);
  }
   bmp.setSampling(Adafruit_BMP280::MODE_FORCED);
  if (! aht.begin()) {
    Serial.println("Could not find AHT? Check wiring");
    while (1) delay(10);
  }
  Serial.println("AHT10 or AHT20 found");


}

void loop() {
  sensors_event_t humidity, temp;
  aht.getEvent(&humidity, &temp);
  Serial.print("Temperature: "); Serial.print(temp.temperature); Serial.println(" degrees C");
  Serial.print("Humidity: "); Serial.print(humidity.relative_humidity); Serial.println("% rH");
  delay(500);
  if (bmp.takeForcedMeasurement()) {

     Serial.print(F("Pressure = "));
    Serial.print(bmp.readPressure());
    Serial.println(" Pa");
    
     Serial.println();
    delay(2000);
  } else {
    Serial.println("Forced measurement failed!");
}
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(1000);
  tftscreen.setTextColor(ST77XX_WHITE);
  tftscreen.setCursor(0, 0);
  tftscreen.setTextSize(2.35);
  tftscreen.println("Temperature: " + String(temp.temperature) + " C");
  tftscreen.println("Humidity: " + String(humidity.relative_humidity) + " % rH");
  tftscreen.println("Pressure: " + String(bmp.readPressure()) + " Pa");
  delay(2000);
}
; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:adafruit_feather_esp32s3_reversetft]
platform = espressif32
board = adafruit_feather_esp32s3_reversetft
framework = arduino
lib_deps = 
	adafruit/Adafruit AHTX0@^2.0.5
	bodmer/TFT_eSPI@^2.5.43
	adafruit/Adafruit NeoPixel@^1.13.0
	adafruit/Adafruit ST7735 and ST7789 Library@^1.11.0
	adafruit/Adafruit BMP280 Library@^2.6.8
build_flags = 
	-DARDUINO_USB_MODE=1
	-DARDUINO_USB_CDC_ON_BOOT=1
monitor_speed = 115200
monitor_rts = 0
monitor_dtr = 0


I thing the problem in code. I would be really happy if someone can help me

I really dont like the symbols it give to me

You’re writing on the same spot different numbers over and over again.

Instead of println use the drawstring method - See TFT_eSPI::drawString - TFT_eSPI library
This method clears the area first before writing the characters.

Take a look at Volos Project’s YouTube channel. He explain TFT_eSPI very well. See How to use TFT_eSPI library Video.

I am not really good at coding and i think i have done something wrong with the library you recommended

#include <Arduino.h>
#include <Adafruit_AHTX0.h>
#include <SPI.h>
#include <Adafruit_NeoPixel.h>
#include <Adafruit_ST7789.h>
#include <Adafruit_BMP280.h>
#include <Adafruit_GFX.h>
#include <TFT_eSPI.h>
Adafruit_BMP280 bmp; 
Adafruit_AHTX0 aht;
//Adafruit_ST7789 tftscreen = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
TFT_eSPI tftscreen = TFT_eSPI();
void setup() {
  pinMode(13, OUTPUT);
  pinMode(TFT_BACKLITE, OUTPUT);
  pinMode(TFT_I2C_POWER, OUTPUT);
  digitalWrite(TFT_BACKLITE, HIGH);
  digitalWrite(TFT_I2C_POWER, HIGH);
  delay(10);
  tftscreen.init();
  tftscreen.setRotation(0);
  tftscreen.fillScreen(ST77XX_BLACK);

  Serial.begin(115200);
  while (!Serial) {
    delay(10); 
  }
  if (!bmp.begin()) {
    Serial.println("Could not find BMP280? Check wiring");
    while (1) delay(10);
  }
   bmp.setSampling(Adafruit_BMP280::MODE_FORCED);
  if (! aht.begin()) {
    Serial.println("Could not find AHT? Check wiring");
    while (1) delay(10);
  }
  Serial.println("AHT10 or AHT20 found");


}

void loop() {
  sensors_event_t humidity, temp;
  aht.getEvent(&humidity, &temp);
  Serial.print("Temperature: "); Serial.print(temp.temperature); Serial.println(" degrees C");
  Serial.print("Humidity: "); Serial.print(humidity.relative_humidity); Serial.println("% rH");
  delay(500);
  if (bmp.takeForcedMeasurement()) {

     Serial.print(F("Pressure = "));
    Serial.print(bmp.readPressure());
    Serial.println(" Pa");
    
     Serial.println();
    delay(2000);
  } else {
    Serial.println("Forced measurement failed!");
}
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(1000);
  tftscreen.setTextColor(ST77XX_WHITE);
  tftscreen.fillScreen(ST77XX_BLACK);
  tftscreen.loadFont("AA_FONT_SMALL");
  tftscreen.drawString("Temperature: " + String(temp.temperature) + " C", 0, 0);	
  tftscreen.drawString("Humidity: " + String(humidity.relative_humidity) + " % rH", 0, 30);
  tftscreen.drawString("Pressure: " + String(bmp.readPressure()) + " Pa", 0, 60); 
  delay(2000);
}  

It doesnt show me anything right now, serial monitor included

I have found this instructables useful to configure TFT_eSPI

1 Like

It’s the same library “TFT_eSPI” which you where already using.
Just use another function “drawString” instead of “println” from the TFT_eSPI library because drawString clears the area youre writing to. This avoids printing different characters over and over again.