Go Down

Topic: Graphics library for NodeMCU (ESP8266), ESP32 and serial+parallel TFT displays (Read 95309 times) previous topic - next topic


A user manual is on my "to do" list but somehow never moves to the top of the list!


I know where you're coming from.
Until then, I'll keep trawling the examples


Is there a neat way of blinking/flashing some text? I can't find any examples online.


Use a loop with a delay, swap the foreground and background colors and redraw the text


The TFT_eSPI library has been updated to allow the ESP32 to use DMA for SPI transfers to the TFT. The "DMA Test" examples now run on the ESP32 (as well as the STM32 processors).

Using DMA generally only gives modest performance improvements and is actually slower for small pixel block updates of the screen. To update just 1 pixel would be 10x slower because it takes time to setup the DMA transaction parameters and initiate the transfer.

The "Flash_Jpg_DMA" draws the image on a 240x320 screen (40MHz SPI) in 103ms without DMA and 76ms with DMA, this is because the Jpeg decoding can carry on while the image tiles are rendered to the screen.

The functions specific to DMA are:
Code: [Select]

  bool     initDMA(void);     // Initialise the DMA engine and attach to SPI bus - typically used in setup()
  void     deInitDMA(void);   // De-initialise the DMA engine and detach from SPI bus - typically not used
           // Push an image to the TFT using DMA, buffer is optional and grabs (double buffers) a copy of the image
           // Use the buffer if the image data will get over-written or destroyed while DMA is in progress
           // If swapping colour bytes is defined, and the double buffer option is NOT used then the bytes
           // in the original data image will be swapped by the function before DMA is initiated.
           // The function will wait for the last DMA to complete if it is called while a previous DMA is still
           // in progress, this simplifies the sketch and helps avoid "gotchas".
  void     pushImageDMA(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t* data, uint16_t* buffer = nullptr);

           // Push a block of pixels into a window set up using setAddrWindow()
  void     pushPixelsDMA(uint16_t* image, uint32_t len);

           // Check if the DMA is complete - use while(tft.dmaBusy); for a blocking wait
  bool     dmaBusy(void); // returns true if DMA is still in progress
  void     dmaWait(void); // wait until DMA is complete


Good job bodmer, thanks for the time!. In the first ESP32-ILI9341 setup, I got these errors:

Code: [Select]
C:\Users\StarX\Documents\Arduino\libraries\TFT_eSPI\Processors/TFT_eSPI_ESP32.c: In member function 'bool TFT_eSPI::initDMA()':

C:\Users\StarX\Documents\Arduino\libraries\TFT_eSPI\Processors/TFT_eSPI_ESP32.c:674:3: error: 'spi_bus_config_t' has no non-static data member named 'flags'


C:\Users\StarX\Documents\Arduino\libraries\TFT_eSPI\Processors/TFT_eSPI_ESP32.c:690:3: error: 'spi_device_interface_config_t' has no non-static data member named 'input_delay_ns'


Error compilando para la tarjeta DOIT ESP32 DEVKIT V1

In the TFT_eSPI_ESP32.c file, I commented three lines, and the errors disappeared (.flags = 0, .intr_flags = 0 and  .input_delay_ns = 0,):

Code: [Select]
bool TFT_eSPI::initDMA(void)
  if (DMA_Enabled) return false;

  esp_err_t ret;
  spi_bus_config_t buscfg = {
    .mosi_io_num = TFT_MOSI,
    .miso_io_num = TFT_MISO,
    .sclk_io_num = TFT_SCLK,
    .quadwp_io_num = -1,
    .quadhd_io_num = -1,
    .max_transfer_sz = TFT_WIDTH * TFT_HEIGHT * 2 + 8 // TFT screen size
    //.flags = 0,
    //.intr_flags = 0
  spi_device_interface_config_t devcfg = {
    .command_bits = 0,
    .address_bits = 0,
    .dummy_bits = 0,
    .mode = TFT_SPI_MODE,
    .duty_cycle_pos = 0,
    .cs_ena_pretrans = 0,
    .cs_ena_posttrans = 0,
    .clock_speed_hz = SPI_FREQUENCY,
    //.input_delay_ns = 0,
    .spics_io_num = TFT_CS,
    .flags = 0,
    .queue_size = 7,
    .pre_cb = dc_callback, //Callback to handle D/C line
    .post_cb = 0


Code: [Select]
Width = 240, height = 320
86 ms

Is the correction that simple or should an extra configuration line be added in the library?



I do not get those error messages myself.

If I do edit out those lines out that you mention then I do get error messages and the sketch will not compile.

Clearly we have different setups but I am not sure what the difference is.

The parameters you have a problem with are in the ESP32 IDF 3.2 documents for the SPI DMA API.

Incidentally, you will get slightly better performance if you change the sketch line:




As then the byte swapping needed is done while DMA is in progress.


I just upgraded from pre-v2.x to the latest ( 2.2.8 ) and I get the exact same error as @TFTLCDCyg.  I tried with the default user setup as well as my normal custom user setup file.  I will go edit out those lines and try it.

Incidentally, this is with any of the examples or my own projects, so it's something inherent with the new upgrade.

Let me know if there is anything I can do to help you figure out why this error occurs.  I am running v1.8.2. of the Arduino core.


Well, editing those lines also worked for me.  I am using v1.04 of the ESP32 board manager.  I don't use PlatformIO at all.  I guess I could try to set that up and see if that makes a difference.  I am not sure if you have tried this under the Arduino IDE lately.

The new version works flawless once you make those edits!  I am getting 117fps @40MHz, 128fps @50Mhz and @60MHz (no increase at 60MHz) with the Boing ball demo on my ESP32D module.  I can use 80MHz no problem when DMA is not used.  I am guessing the speed restriction must have to do with DMA mode?


@JimDrew @TFTLCDCyg

I tried compiling the library with Arduino IDE 1.8.1 and I get the reported errors.

Arduino IDE 1.8.5 worked fine with no reported errors.

Currently I am using 1.8.11 with no reported errors.

All these were using ESP32 board package 1.0.4

I conclude this problem only occurs on older versions of the IDE that are >~3 years old so I do not propose to change the library.


Ok, thanks for the info.  Unfortunately, I have a slew of libraries that no longer work with 1.8.3 and later so I am stuck back in time.  :)


Just a quickie.

Haven't actually tried much yet with Platform IO, apart from a blink sketch with ESP32, which worked fine.

Installed TFT_eSPI library, but upon compiling got this error:

Code: [Select]
*** [.pio\libdeps\esp32dev\TFT_eSPI\TFT_eSPI.cpp] TypeError : unsupported operand type(s) for -: 'float' and 'NoneType'

In my .ini file I have:

Code: [Select]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200

lib_deps =
  # Using a library name

I've not actually tried to run anythng with it yet, just learning how to play with the IDE.

Is this a potential problem?




Hi Matt,

Typically this error occurs when a function that is supposed to return a variable exits without doing so.

Try the Arduino IDE.


I was playing with the idea of creating some master-slave construction for the esp32.
So that some heavy program can be running on some other device (computer, phone, server, whatever)
and the output (graphics and/or text) is pushed to the TFT of the ESP32.

What would be faster. Let the program output an full 480*320 image and send that to the ESP?
Or create some sort of framework or api that runs on the ESP32 and the program sends only updated portions of the image (Sprites?)to the ESP?

Go Up