This guide will help you set up your development environment and run your first LVGL example on ESP32 with TFT display.
Prerequisites
Hardware Required
- ESP32 development board (ESP32-DevKitC or similar)
- TFT display with SPI interface (e.g., ILI9341, ST7789)
- Jumper wires for connections
- USB cable for ESP32
- Breadboard (optional, for easier connections)
Software Required
- PlatformIO (recommended) or Arduino IDE
- VS Code with PlatformIO extension (if using PlatformIO)
- USB drivers for ESP32 (CP2102 or CH340)
Step 1: Install PlatformIO
Option A: VS Code Extension (Recommended)
- Install Visual Studio Code
- Open VS Code
- Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
- Search for "PlatformIO IDE"
- Click Install
Option B: Standalone PlatformIO Core
- Visit: https://platformio.org/install/cli
- Follow installation instructions for your OS
Verify Installation
Open terminal/command prompt and run:
pio --version
Step 2: Configure TFT_eSPI Library
IMPORTANT: This step is required before compiling any code!
Find TFT_eSPI Library Location
- Open terminal in your project directory
- Run:
pio pkg listto see installed packages - Or navigate to PlatformIO packages directory:
- Windows:
%USERPROFILE%\.platformio\packages\framework-arduinoespressif32\libraries\TFT_eSPI- macOS/Linux:~/.platformio/packages/framework-arduinoespressif32/libraries/TFT_eSPI
Configure User_Setup.h
- Navigate to the TFT_eSPI library folder
- Open
User_Setup.h(or createUser_Setup_Select.h) - Uncomment your display driver, for example:
// For ILI9341 display:
#define ILI9341_DRIVER
// For ST7789 display:
// #define ST7789_DRIVER
// Pin definitions (adjust to match your wiring):
#define TFT_MOSI 23
#define TFT_SCLK 18
#define TFT_CS 5
#define TFT_DC 2
#define TFT_RST 4
#define TFT_BL 15
// Display orientation
#define TFT_ROTATION 0 // 0=portrait, 1=landscape
Common Display Drivers
ILI9341_DRIVER- Common 2.8" displaysST7789_DRIVER- Common 1.3" and 1.54" displaysST7735_DRIVER- Common 1.8" displays- Check your display's datasheet for the correct driver
Step 3: Wire Your Display
Connect your TFT display to ESP32 according to the pin definitions in display_config.h:
| Display Pin | ESP32 GPIO | Description |
|---|---|---|
| VCC | 3.3V | Power (3.3V, NOT 5V!) |
| GND | GND | Ground |
| MOSI/SDA | GPIO 23 | SPI Data |
| SCLK/SCL | GPIO 18 | SPI Clock |
| CS | GPIO 5 | Chip Select |
| DC/A0 | GPIO 2 | Data/Command |
| RST | GPIO 4 | Reset |
| BL | GPIO 15 | Backlight (optional) |
⚠️ Warning: - Use 3.3V for VCC, NOT 5V! - Double-check your display's pinout - they vary by manufacturer - Some displays have different pin names (MOSI vs SDA, etc.)
Step 4: Open the Project
Using PlatformIO in VS Code:
- Open VS Code
- File → Open Folder
- Navigate to the
lvgl_ttf_spi_demofolder - PlatformIO should detect the project automatically
Using PlatformIO CLI:
cd lvgl_ttf_spi_demo
pio run
Step 5: Select Your Example
The project contains multiple example files. To use one:
- Rename the example file to
main.cppormain.ino - Or create a
srcfolder and copy the example there - Or use PlatformIO's multiple source files feature
Quick Method (PlatformIO):
- Copy the example code you want to try
- Create
src/main.cppand paste the code - Compile and upload
Example: Using 01_basic_setup.ino
# Copy example to src folder
cp 01_basic_setup.ino src/main.cpp
# Compile
pio run
# Upload
pio run -t upload
# Monitor serial output
pio device monitor
Step 6: Compile and Upload
Using PlatformIO Toolbar (VS Code):
- Click the checkmark icon (✓) to compile
- Click the arrow icon (→) to upload
- Click the plug icon (🔌) to open serial monitor
Using PlatformIO CLI:
# Compile
pio run
# Upload
pio run -t upload
# Monitor serial output
pio device monitor
Using Arduino IDE:
- Install ESP32 board support (if not already installed)
- Install LVGL and TFT_eSPI libraries via Library Manager
- Open the .ino file
- Select Tools → Board → ESP32 Dev Module
- Select Tools → Port → (your ESP32 port)
- Click Upload
Step 7: Verify It Works
After uploading:
-
Check Serial Monitor: - Open serial monitor (115200 baud) - You should see initialization messages - Look for "[DISPLAY] Display initialization complete"
-
Check Display: - Display should show the example UI - If blank, check:
- Power connections (3.3V and GND)
- SPI connections (MOSI, SCLK, CS, DC, RST)
- Backlight connection (if applicable)
- TFT_eSPI User_Setup.h configuration
-
Common Issues: - Blank screen: Check wiring and User_Setup.h - Garbled colors: Enable
tft.setSwapBytes(true)- Nothing happens: Check serial monitor for errors - Compilation errors: Verify TFT_eSPI is configured correctly
Step 8: Try Different Examples
Work through the examples in order:
- 01_basic_setup.ino - Minimal setup, verify display works
- 02_display_text.ino - Learn to display text and information
- 03_create_buttons.ino - Learn button creation and event handling
- 04_complete_ui.ino - Complete application with multiple screens
Each example builds on the previous one, teaching new concepts.
Troubleshooting
Display Shows Nothing
- ✅ Check all connections (especially power and ground)
- ✅ Verify TFT_eSPI User_Setup.h matches your display
- ✅ Check backlight connection (if your display has one)
- ✅ Try different rotation:
tft.setRotation(0-3) - ✅ Verify display is powered (3.3V, not 5V!)
Compilation Errors
- ✅ Ensure TFT_eSPI User_Setup.h is configured
- ✅ Check that LVGL and TFT_eSPI libraries are installed
- ✅ Verify platformio.ini has correct library versions
- ✅ Try cleaning build:
pio run -t clean
Display Shows Garbled Colors
- ✅ Enable byte swapping:
tft.setSwapBytes(true) - ✅ Check color format in LVGL configuration
- ✅ Verify display driver in User_Setup.h
Buttons Don't Respond
- ✅ Ensure
lv_timer_handler()is called inloop() - ✅ Check touch input configuration (if using touch)
- ✅ Verify event callbacks are registered correctly
Memory Issues
- ✅ Reduce display buffer size
- ✅ Enable PSRAM if available:
-DBOARD_HAS_PSRAM - ✅ Check free heap:
Serial.println(ESP.getFreeHeap());
Serial Monitor Shows Errors
- ✅ Check baud rate (115200)
- ✅ Verify USB cable connection
- ✅ Try different USB port
- ✅ Install correct USB drivers (CP2102 or CH340)
Next Steps
Once you have the basic example working:
- Read the README.md - Comprehensive guide to all concepts
- Study the examples - Each one teaches specific concepts
- Try modifications - Change colors, sizes, positions
- Read QUICK_REFERENCE.md - Quick lookup for common operations
- Build your own UI - Combine what you've learned
Learning Path
Beginner
- ✅ Get basic setup working (01_basic_setup.ino)
- ✅ Display text (02_display_text.ino)
- ✅ Create buttons (03_create_buttons.ino)
Intermediate
- ✅ Complete UI (04_complete_ui.ino)
- ✅ Experiment with styling
- ✅ Add more widgets (sliders, charts, etc.)
Advanced
- ✅ Multiple screens with navigation
- ✅ Custom themes
- ✅ Animations
- ✅ Touch gestures
- ✅ Data visualization
Additional Resources
- LVGL Documentation: https://docs.lvgl.io/
- TFT_eSPI GitHub: https://github.com/Bodmer/TFT_eSPI
- ESP32 Documentation: https://docs.espressif.com/
- PlatformIO Documentation: https://docs.platformio.org/
Getting Help
If you're stuck:
- Check Serial Output - Often contains helpful error messages
- Review Examples - Compare your code with working examples
- Read Documentation - LVGL and TFT_eSPI have excellent docs
- Search Forums - ESP32 and LVGL communities are very helpful
- Simplify - Start with minimal code and add features gradually
Summary Checklist
Before starting: - [ ] PlatformIO installed - [ ] TFT_eSPI User_Setup.h configured - [ ] Display wired correctly - [ ] USB drivers installed - [ ] Project opened in PlatformIO
First example: - [ ] 01_basic_setup.ino compiles - [ ] Code uploaded to ESP32 - [ ] Display shows blue rectangle - [ ] Serial monitor shows initialization messages
Ready to learn: - [ ] Understand basic setup - [ ] Can modify example code - [ ] Ready to try next example
You're ready to start building embedded GUIs! 🎉