-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Installing on PlatformIO
This guide will setup TFT_eSPI for PlatformIO development platform.
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.
Follow this guide to setup your project. Once you are done open the platformio.ini file. You should see something like this:
There are different ways to include libraries in PlatformIO, but the simplest way is to add the line lib_deps = TFT_eSPI
. Your file now looks like this:
PlatformIO will automatically download and install TFT_eSPI in your project the next time you build. Library files will be stored in .pio/libdeps/env_name/TFT_eSPI_ID1559/
inside the project directory.
More info on lib_deps
here.
Before using the library we have to select the tft driver, SPI pins, SPI frequency and other settings to properly control your screen. There are some pre-made setup files for the most common configurations, which can be found in the User_Setups
folder. This configurations can be included by the User_Setup_Select.h
file located in the root directory of the 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 editing any library files. This allows us to create different projects using the same library, but 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
. 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
All available settings can be found in
User_Setup.h
file. Replace#define
with-D
as shown here:
#define TOUCH_CS 21
->-D TOUCH_CS=21
#define LOAD_GLCD
->-D LOAD_GLCD
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
Add the line #include <TFT_eSPI.h>
at the top of your files.
Enjoy! ;)