Skip to content

Installing on PlatformIO

Dracir edited this page Feb 8, 2020 · 5 revisions

Installation: PlatformIO

This guide will setup TFT_eSPI for PlatformIO development platform.

1. Install PlatformIO

Go to PlatformIO page and follow the instructions to install it into your favourite IDE.

We will use VSCode as an example. Install instructions and guides for VSCode can be found here.

2. Create a project

Follow this guide to setup your project. Once you are done open the platformio.ini file. You should see something like this:

imagen

3. Add TFT_eSPI to your project

There are different ways to add libraries in PlatformIO, but the simplest way is to add the line lib_deps = TFT_eSPI. Your file now looks like this:

imagen

More info on lib_depshere.

4. Configure library

We could modify the User_Setup_Select.h file and set our preferences but one cool thig about PlatformIO is that we can modify the library settings without editting the actual library files. This allows us to create different projects with different settings. Also we can update libraries to newer versions without loosing our settings.

We can achieve this by using PlatformIO's build_flags. Just instead of using #define, use the -D prefix.

  • First of all we prevent user settings headers to be loaded by defining USER_SETUP_LOADED.
  • Next include the User_SetupXX_XXXX.h file that maches your configuration. Your code now looks like this:
build_flags =
  -D USER_SETUP_LOADED=1
  -include $PROJECT_LIBDEPS_DIR/$PIOENV/TFT_eSPI_ID1559/User_Setups/Setup1_ILI9341.h
  • Optionally you can create your custom setup by defining the needed settings, here is an example:
  -D ILI9163_DRIVER=1                           ; Select ILI9163 driver
  -D TFT_WIDTH=128                              ; Set TFT size
  -D TFT_HEIGHT=160
  -D TFT_MISO=19                                ; Define SPI pins
  -D TFT_MOSI=23
  -D TFT_SCLK=18
  -D TFT_CS=5
  -D TFT_DC=19                                  ; Data/Comand pin
  -D TFT_RST=-1                                 ; Reset pin
  -D LOAD_GLCD=1                                ; Load Fonts
  -D SPI_FREQUENCY=27000000                     ; Set SPI frequency

The final platformio.ini file may look like this:

  • Using User_Setups:
    [env:esp32dev]
    platform = espressif32
    board = esp32dev
    framework = arduino
    lib_deps = TFT_eSPI
    build_flags =
      ;###############################################################
      ; TFT_eSPI library setting here (no need to edit library files):
      ;###############################################################
      -D USER_SETUP_LOADED=1                        ; Set this settings as valid
      -include $PROJECT_LIBDEPS_DIR/$PIOENV/TFT_eSPI_ID1559/User_Setups/Setup1_ILI9341.h
  • Custom setup:
    [env:esp32dev]
    platform = espressif32
    board = esp32dev
    framework = arduino
    lib_deps = TFT_eSPI
    build_flags =
      ;###############################################################
      ; TFT_eSPI library setting here (no need to edit library files):
      ;###############################################################
      -D USER_SETUP_LOADED=1                        ; Set this settings as valid
      -D ILI9163_DRIVER=1                           ; Select ILI9163 driver
      -D TFT_WIDTH=128                              ; Set TFT size
      -D TFT_HEIGHT=160
      -D TFT_MISO=19                                ; Define SPI pins
      -D TFT_MOSI=23
      -D TFT_SCLK=18
      -D TFT_CS=5
      -D TFT_DC=19                                  ; Data/Comand pin
      -D TFT_RST=-1                                 ; Reset pin
      -D LOAD_GLCD=1                                ; Load Fonts
      -D SPI_FREQUENCY=27000000                     ; Set SPI frequency

5. Include header

Add the line #include <TFT_eSPI.h>at the top of your files.

Enjoy! ;)

Clone this wiki locally