ESP32 and 2.4" TFT. Unable to use the full size of the display

Hi all! I'm new here, so i'll be happy for any help given. Let's get to the chase. The hardware that im using is a generic ESP32 Dev Module(pictures included) and a cheap 2.4" tft module from alliexpres which is supposed to have a ILI9341 controller. Im using the Bodmer's TFT_eSPI library which is configured for ESP32 and ILI9341 driver with the following line "#include <User_Setups/Setup42_ILI9341_ESP32.h> " inside User_Setup_Select.h. I ran the Read_User_Setup.ino and got the following results(picture included). Also i had a chance to run the code on another 3.2" tft screen again with ILI9341 and it works like a charm(picture included).
The problem is as it shows on the pictures the screen is not fully used i dont know whats causing it and how to resolve the issue also the colors seem off even tho nothing has changed in the code since the run on the 3.2". If anyone has any idea as to what is causing this malfunction please shoot because im stuck. Cheers!

"Fonts.h" and "Xbm.h" are just files to hold the custom fonts and xbitmap files for the symbols if needed i can provide them too.

Here's the code:



#include <TFT_eSPI.h>
#include "Fonts.h"
#include "Xbm.h"
//#include <Free_Fonts.h>

TFT_eSPI tft = TFT_eSPI();
TFT_eSprite smaint = TFT_eSprite(&tft);   // Sprite object smaint
TFT_eSprite smainp = TFT_eSprite(&tft);   // Sprite object smaint
TFT_eSprite smaini = TFT_eSprite(&tft);   // Sprite object smaint
TFT_eSprite smainw = TFT_eSprite(&tft);   // Sprite object smaint
TFT_eSprite smainpr = TFT_eSprite(&tft);  // Sprite object smaint

int power_percent;
String power_string;
int real_temp;
int o = 14;
float input_voltage = 36.4;
int power = 200;
String voltage_str, power_str;
int presset_temp[] = { 300, 350, 400 };
int screen = 0;
int state = 1;
int set_temp = 350;
int state1 = 1;
String state1_str[] = { "OFF", "Heating", "Standby" };
int iron_type = 0;
String iron_type_str[] = { "T245", "T12" };


//==========================================================================================
void setup() {
  Serial.begin(115200);
  tft.init();
  tft.fillScreen(TFT_BLACK);
  tft.setRotation(0);
  tft.invertDisplay(false);
  tft.color
  
  smaint.createSprite(210, 85);
  smainp.createSprite(52, 225);
  smaini.createSprite(320, 15);
  smainw.createSprite(210, 80);
  smainpr.createSprite(200, 25);

  smaint.fillSprite(TFT_BLACK);
  smaint.setTextColor(TFT_CYAN, TFT_BLACK);

  smainp.fillSprite(TFT_BLACK);
  smainp.setTextColor(TFT_CYAN, TFT_BLACK);

  smaini.fillSprite(TFT_BLACK);
  smaini.setTextColor(TFT_WHITE, TFT_BLACK);

  smainw.fillSprite(TFT_BLACK);
  smainw.setTextColor(TFT_WHITE, TFT_BLACK);

  smainpr.fillSprite(TFT_BLACK);
  smainpr.setTextColor(TFT_WHITE, TFT_BLACK);
Serial.printf("x%d, y%d", tft.height(),tft.width());  
}

//==========================================================================================
long prmillis1, prmillis2, prmillis3;
int i;
String data;
void loop() {
  if (screen == 0) Mainscreen();
}



void Mainscreen_temp() {
  real_temp = 499;//map(analogRead(26), 0, 4096, 0, 500);

  smaint.setTextSize(1);
  smaint.setFreeFont(&DSEG7_Classic_Mini_Regular_80);
  smaint.drawNumber(real_temp, 200, 42);
  if (real_temp < 100) smaint.fillRect(0, 0, 60, 85, TFT_BLACK);
  if (real_temp < 10) smaint.fillRect(60, 0, 80, 85, TFT_BLACK);

  smaint.setFreeFont(&TomThumb);
  smaint.setTextDatum(MR_DATUM);
  smaint.drawString("o", 198, 3, 2);
  smaint.setFreeFont(&FreeMono12pt7b);
  smaint.drawString("C", 210, 9);

  smaint.pushSprite(o + 48, 110);
}

void Mainscreen_power() {
  power_percent = 100; //map(analogRead(26), 0, 4095, 0, 100);
  smainp.setTextColor(TFT_WHITE, TFT_BLACK);
  smainp.setFreeFont(&Roboto_Light_16);
  smainp.setTextDatum(MC_DATUM);
  smainp.drawRect(15, 15, 20, 180, 0x195AFF);
  smainp.fillRect(0, 200, 50, 25, TFT_BLACK);
  power_string = "";
  power_string += power_percent;
  power_string += "%";
  smainp.drawString(power_string, 25, 207);

  smainp.fillRectVGradient(16, 16, 18, 178, TFT_RED, TFT_BLUE);
  smainp.fillRect(16, 16, 18, map(power_percent, 0, 100, 178, 0), TFT_BLACK);

  smainp.pushSprite(0, 16);
}

void Mainscreen_info() {
  smaini.setTextDatum(TL_DATUM);
  smaini.setFreeFont(&Roboto_14);
  voltage_str = "";
  voltage_str += input_voltage;
  voltage_str += "V";
  smaini.drawString(voltage_str, 0, 2);
  power_str = "";
  power_str += power;
  power_str += "W";
  smaini.drawString(power_str, 65, 2);
  smaini.setTextDatum(TC_DATUM);
  smaini.drawString("15:45", 160, 2);
  smaini.setTextDatum(TR_DATUM);
  smaini.drawString("v2.0", 320, 2);

  smaini.pushSprite(0, 0);
}

void Mainscreen_presset() {
  tft.drawLine(0, 15, 320, 15, TFT_DARKGREY);
  smainpr.drawRect(0, 0, 50, 25, 0x195AFF);
  smainpr.drawRect(67, 0, 50, 25, 0x195AFF);
  smainpr.drawRect(132, 0, 50, 25, 0x195AFF);
  smainpr.setTextColor(TFT_WHITE, TFT_BLACK);
  smainpr.setFreeFont(&Roboto_Light_16);
  smainpr.setTextDatum(MC_DATUM);
  smainpr.drawNumber(presset_temp[0], 25, 12);
  smainpr.drawNumber(presset_temp[1], 92, 12);
  smainpr.drawNumber(presset_temp[2], 157, 12);
  smainpr.pushSprite(72, 215);
}

void Mainscreen_widgets() {
  smainw.fillRect(100, 10, 2, 7, TFT_LIGHTGREY);
  smainw.fillRect(100, 21, 2, 7, TFT_LIGHTGREY);
  smainw.fillRect(100, 32, 2, 7, TFT_LIGHTGREY);
  smainw.fillRect(100, 43, 2, 7, TFT_LIGHTGREY);
  smainw.fillRect(100, 54, 2, 7, TFT_LIGHTGREY);
  smainw.fillRect(100, 65, 2, 7, TFT_LIGHTGREY);
  if (state == 1) smainw.drawXBitmap(0, 12, temp_high, temp_high_width, temp_high_height, TFT_BLACK, TFT_RED);
  if (state == 0) smainw.drawXBitmap(0, 12, temp_low, temp_low_width, temp_low_height, TFT_BLACK, TFT_BLUE);
  smainw.setTextDatum(MC_DATUM);
  smainw.setFreeFont(&Monospaced_bold_16);
  smainw.drawString("SET", 54, 20);
  smainw.drawRect(30, 40, 50, 25, 0x195AFF);
  smainw.setFreeFont(&Roboto_Light_16);
  smainw.drawNumber(set_temp, 55, 52);
  smainw.setTextDatum(MC_DATUM);
  smainw.setFreeFont(&Monospaced_bold_16);
  if (state1 == 0){smainw.setTextColor(TFT_BLUE); smainw.drawString(state1_str[state1], 160, 20);}
  if (state1 == 1){smainw.setTextColor(TFT_RED); smainw.drawString(state1_str[state1], 160, 20);}
  if (state1 == 2){smainw.setTextColor(TFT_GREEN); smainw.drawString(state1_str[state1], 160, 20);}
  smainw.setFreeFont(&Monospaced_bold_16);smainw.setTextColor(TFT_WHITE);smainw.drawString(iron_type_str[iron_type], 160, 52);
  smainw.pushSprite(60, 20);
}


void Mainscreen() {
  if (millis() - prmillis2 >= 150) {
    prmillis2 = millis();
    Mainscreen_info();
  }
  if (millis() - prmillis1 >= 50) {
    prmillis1 = millis();
    Mainscreen_power();
    Mainscreen_temp();
  }
  if (millis() - prmillis3 >= 500) {
    prmillis3 = millis();
    Mainscreen_presset();
    Mainscreen_widgets();
  }
}


Did you try to set rotation to 1 in setup()?

 tft.setRotation(1);

Hello ec2021. Yes i tried every posible rotation. in some cases the whole screen glitches up or cuts the image as shown above.

No idea ... I guess that you have already tested the display with some standard example sketches to make sure it is not defect ...

If nobody pops up who knows the reason the only way I see is that you clean up your code and try to get a first simple working sketch that fills the whole screen and then build it up step by step.

Good luck!

Thanks! I tried just a simple code to fill the screen in red and guess what... again that square of red and glichy white stripe on the side of the display. i read a similar post back in the days about this kind of a problem but i couldnt resolve it by myself thats why i uploaded the code here. Anyways thanks for the heads up.

I found a German thread where the TO found out that it was not an ILI9341 although AliExpress told it

https://forum.arduino.cc/t/adafruit-gfx-und-illi9341-display/1163500

Maybe that's the case with your display also...

The solution was to use a driver for the ST7789.

1 Like

If you look in the library around line 178 there is a setviewport function

Perhaps try call that with your resolution size

There is another thread where the TO has the same problem.

Have a look here

https://forum.arduino.cc/t/esp8266-wifi-analyzer-using-st7735-2-4-inch-240x320-spi-tft-screen/1185014/20

The solution to it is still not verified but it looks as if it's close....

You probably only have to change the commented line as shown here

//TFT_eSPI tft = TFT_eSPI(); 

// Possibly wrong!! --> TFT_eSPI tft = TFT_eSPI(320, 240);
TFT_eSPI tft = TFT_eSPI(240, 320);       // Could invoke custom library declaring width and height
  

[Edit]: Changed width/height in the call above ...

[Edit2]: Just got the feedback that this line solved the problem in the other thread :wink:

3 Likes

Below actually fixed the issue for me:

TFT_eSPI tft = TFT_eSPI(320, 240);

with

tft.setRotation(1);

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.