Why is this ESP-32 code not compiling?

I have bought a T-display esp-32. Tried to use TFT_eSPI example code, but it always gives me this error

In file included from c:\Users\vince\Documents\Arduino\libraries\TFT_eSPI\TFT_eSPI.cpp:24:
c:\Users\vince\Documents\Arduino\libraries\TFT_eSPI\Processors/TFT_eSPI_ESP32.c: In member function 'void TFT_eSPI::begin_SDA_Read()':
c:\Users\vince\Documents\Arduino\libraries\TFT_eSPI\Processors/TFT_eSPI_ESP32.c:72:3: error: 'gpio_set_direction' was not declared in this scope
   72 |   gpio_set_direction((gpio_num_t)TFT_MOSI, GPIO_MODE_INPUT);
      |   ^~~~~~~~~~~~~~~~~~
c:\Users\vince\Documents\Arduino\libraries\TFT_eSPI\Processors/TFT_eSPI_ESP32.c: In member function 'void TFT_eSPI::end_SDA_Read()':
c:\Users\vince\Documents\Arduino\libraries\TFT_eSPI\Processors/TFT_eSPI_ESP32.c:87:3: error: 'gpio_set_direction' was not declared in this scope
   87 |   gpio_set_direction((gpio_num_t)TFT_MOSI, GPIO_MODE_OUTPUT);
      |   ^~~~~~~~~~~~~~~~~~

exit status 1

Compilation error: exit status 1

Hi @Vizo. The bug has been reported to the "TFT_eSPI library developers here:

The problem is that the library is not compatible with the recent versions of the "esp32" boards platform that adds support to Arduino IDE for the ESP32-based boards.

The solution will be to roll back to the last compatible version (2.0.17) of the "esp32 platform. I'll provide instructions you can follow to do that:

  1. Select Tools > Board > Boards Manager... from the Arduino IDE menus.
    The "Boards Manager" dialog will open.
  2. Wait for the updates to finish, as shown by the messages printed at the bottom of the "Boards Manager" dialog.
  3. Scroll down through the list of boards platforms until you find the "esp32" entry. Click on it.
    A "Select version" dropdown will appear in the entry.
  4. Click on the "Select version" dropdown.
    It will expand.
  5. Select "2.0.17" from the menu.
  6. Click the "Install" button in the "esp32" entry.
  7. Wait for the installation to finish.
  8. Click the "Close" button on the "Boards Manager" dialog.
    The "Boards Manager" dialog will close.

Now compile your sketch again. Hopefully this time the error will not occur and the library will work as expected.


Arduino IDE will occasionally notify you that a new version of the boards platform is available, you'll need to refrain from accepting the offer that will cause an update back to the problematic version of the platform. If you find these notifications annoying, you can disable them via the IDE preferences.

I'll provide instructions you can follow to do that:

  1. Select File > Preferences... (or Arduino > Settings... for macOS users) from the Arduino IDE menus.
    The "Preferences" dialog will open.
  2. Uncheck the box next to "Check for updates on startup" in the "Preferences" dialog.
  3. Click the "OK" button.
    The "Preferences" dialog will close.

If you disable the automatic update check, make sure to periodically do a manual check for newer versions of the installed boards platforms and libraries that you want to keep updated. You can check for new versions of Arduino IDE by selecting Help > Check for Arduino IDE Updates from the Arduino IDE menus. You can check for new versions of boards platforms and libraries by selecting "Updatable" from the "Type" menu in the Boards Manager and Library Manager views.

You should keep a watch for an update of the "TFT_eSPI" library. It is likely the compatibility problems will be fixed in the next release of the library. So after you update to a new version of the library, you can also use the Arduino IDE Boards Manager to update the "esp32" boards platform to the latest version again.

2 Likes

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