Nifty esp32 display. Can you help me decrypt this tft code for it?

I bought some 7" 800x480 tft displays with built in esp32s. (i bought the model without touch screen)

aliexpress link

The screen looks great and I was excited to have a cheap way to display some messages all enclosed in one board, but the sample code that comes with the screen is defining things in a way that is confusing me. (I tend to only use screens with libraries/or simple i2c interfaces). I cannot figure out how to move it to an adafruit library so I can use custom (really large) fonts that would look nice at a reasonable size on the 7" screen.

Can somebody please step through this code and help break down what it is doing? Or give me some tips for how to display large custom fonts (already converted to .h) on this display? Thanks!

#include <Arduino_GFX_Library.h>

// is the following defining the pins the esp32 is using to talk to the panel?  How would i define this in another library?
#define TFT_BL 2
Arduino_ESP32RGBPanel *bus = new Arduino_ESP32RGBPanel(
 // if i include this in other code i get errors about *bus
  GFX_NOT_DEFINED /* CS */, GFX_NOT_DEFINED /* SCK */, GFX_NOT_DEFINED /* SDA */,
  41 /* DE */, 40 /* VSYNC */, 39 /* HSYNC */, 42 /* PCLK */,
  14 /* R0 */, 21 /* R1 */, 47 /* R2 */, 48 /* R3 */, 45 /* R4 */,
  9 /* G0 */, 46 /* G1 */, 3 /* G2 */, 8 /* G3 */, 16 /* G4 */, 1 /* G5 */,
  15 /* B0 */, 7 /* B1 */, 6 /* B2 */, 5 /* B3 */, 4 /* B4 */
);

Arduino_RPi_DPI_RGBPanel *gfx = new Arduino_RPi_DPI_RGBPanel(
  bus,
 
  800 /* width */, 0 /* hsync_polarity */, 210 /* hsync_front_porch */, 30 /* hsync_pulse_width */, 16 /* hsync_back_porch */,
  480 /* height */, 0 /* vsync_polarity */, 22 /* vsync_front_porch */, 13 /* vsync_pulse_width */, 10 /* vsync_back_porch */,
  1 /* pclk_active_neg */, 16000000 /* prefer_speed */, true /* auto_flush */);


int32_t w, h, n, n1, cx, cy, cx1, cy1, cn, cn1;
uint8_t tsa, tsb, tsc, ds;

void setup()
{
  gfx->begin();  // why is this "->" rather than gfx.begin?
  // gfx->begin(80000000); /* specify data bus speed */

  w = gfx->width();
  h = gfx->height();
  n = min(w, h);
  n1 = n - 1;
  cx = w / 2;
  cy = h / 2;
  cx1 = cx - 1;
  cy1 = cy - 1;
  cn = min(cx1, cy1);
  cn1 = cn - 1;
  tsa = ((w <= 176) || (h <= 160)) ? 1 : (((w <= 240) || (h <= 240)) ? 2 : 3); // text size A
  tsb = ((w <= 240) || (h <= 220)) ? 1 : 2;                                    // text size B
  tsc = ((w <= 220) || (h <= 220)) ? 1 : 2;                                    // text size C
  ds = (w <= 160) ? 9 : 12;                                                    // digit size

#ifdef TFT_BL
  pinMode(TFT_BL, OUTPUT);
  digitalWrite(TFT_BL, HIGH);
#endif

}


void loop(void)
{
  gfx->setCursor(0, 0); 
//what is the significance of the "->"?  (I've only ever seen tft.setcursor or gfx.setcursor)
  gfx->setTextSize(9);
  gfx->setTextColor(MAGENTA);
  gfx->println(F("This prints to the screen, but obviously all blocky")); 

}

This, your pin designator

GFX_NOT_DEFINED /* CS */, GFX_NOT_DEFINED /* SCK */, GFX_NOT_DEFINED /* SDA */,
  41 /* DE */, 40 /* VSYNC */, 39 /* HSYNC */, 42 /* PCLK */,
  14 /* R0 */, 21 /* R1 */, 47 /* R2 */, 48 /* R3 */, 45 /* R4 */,
  9 /* G0 */, 46 /* G1 */, 3 /* G2 */, 8 /* G3 */, 16 /* G4 */, 1 /* G5 */,
  15 /* B0 */, 7 /* B1 */, 6 /* B2 */, 5 /* B3 */, 4 /* B4 */

is using pins that are NOT available on a WROOM or WROVER development board. That's a thing that ticks me off about the ESP32 that most of portB's and some of portA's pins not used by the ESP32 are not brought out in most developer boards. You'd have to use custom made developer boards to make the thing work.

*bus would be either HSPI or VPSI reference. The ESP32 has 4 SPI busses and the developer boards normally only expose 2 for maker use.

1 Like

Are you sure there is no font selection available? It might be just unused in the demo.

See https://github.com/moononournation/Arduino_GFX/blob/master/README.md

U8g2 Font Support
U8g2 proivided various font type and stored in compressed format. So U8g2 font gives more UI design possibilities and still can fit in the MCU limited storage space. Using U8g2 font in Arduino_GFX simply include U8g2lib.h before Arduino_GFX_Library.h:

#include <U8g2lib.h>
#include <Arduino_GFX_Library.h>
And then setfont file to use:

gfx->setCursor(10, 20);
gfx->setFont(u8g2_font_maniac_tr);
gfx->println("Hello World!");
U8g2 font list can be found at: https://github.com/olikraus/u8g2/wiki/fntlistall

U8g2 Unicode (UTF8) Font Support
Another U8g2 font advantage is the font support Unicode glyphs. Simply enable setUTF8Print:

    gfx->begin();
    gfx->fillScreen(BLACK);
    gfx->setUTF8Print(true);
And then print UTF8 string as usual:

    gfx->setCursor(0, 16);

    gfx->setFont(u8g2_font_unifont_tr);
    gfx->println("Hello World!");

    gfx->setFont(u8g2_font_unifont_t_polish);
    gfx->println("Witaj świecie!");

    gfx->setFont(u8g2_font_unifont_t_vietnamese1);
    gfx->println("Chào thế giới!");

    gfx->setFont(u8g2_font_unifont_t_chinese2);
    gfx->println("世界你好!");

    gfx->setFont(u8g2_font_unifont_t_japanese1);
    gfx->println("こんにちは世界!");

    gfx->setFont(u8g2_font_unifont_t_korean1);
    gfx->println("안녕하세요, 세계입니다!");
U8g2 Unifont list can be found at: https://github.com/olikraus/u8g2/wiki/fntgrpunifont

gfx is a pointer. So -> is used to access members of the class instance it points to.

Thanks, Zinggjm! This got me halfway there. The largest u8g2 alpha fonts are 50 pixels, so I'm still going to have to muck around with creating custom fonts. Cheers!

It also supports GfxFont: HelloWorldGfxfont.
You could use e.g. Font Converter (squix.ch).

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