Working on LVGL chapter 1.8 – Testing the Display in Learn LVGL: Build GUIs for ESP32 Projects (Version 1.4). I’m using an AZ-Touch ESP32 Devkit C v4 with a TFT 2.8 inch ILI9341 Touchscreen Display.
During compilation no errors are shown, but after the reset (a click can be heard) the screen very shortly shows a white background and immediately turns black.
Installed the libraries (installed in /home/{user}/Arduino/libraries):
- lvgl version 9.2.0
- TFT_eSPI version 2.5.34 (also tried with 2.5.43)
- XPT2046_Touchscreen 1.4.0
Copied:
- lv_conf.h to /home/{user}/Arduino/libraries
- User_Setup.h to /home/{user}/Arduino/libraries/TFT_eSPI
The serial console displays:
15:38:49.517 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
15:38:49.673 -> configsip: 0, SPIWP:0xee
15:38:49.673 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
15:38:49.673 -> mode:DIO, clock div:1
15:38:49.673 -> load:0x3fff0030,len:4916
15:38:49.673 -> load:0x40078000,len:16436
15:38:49.673 -> load:0x40080400,len:4
15:38:49.673 -> ho 8 tail 4 room 4
15:38:49.673 -> load:0x40080404,len:3524
15:38:49.673 -> entry 0x400805b8
15:38:49.827 -> LVGL Library Version: 9.2.0
Most probably this has to do with the different boards. I’ve ordered an DOIT devkit v1 (and ESP32 CYD board) to be sure, but am wondering if I’ve overlooked something or that someone has a solution for my problem.
Final update
Verified settings for best I could. Following are the results and I think these were the relevant changes. Didn’t test all combinations, so some settings might depend on other settings to make it work.
Hardware used:
AZ-Touch mod version 01-03
AZ-Delivery ESP32 DevKit C v4
2,8 inch LCD TFT Touch Display, resistive, 320x240px resolution, ILI9341 driver, SPI-interface
Libraries needed and tested with:
LVGL versie 9.1.0 from Kisvegabor, embeddedt, peter-pjb
TFT_eSPI versie 2.5.43 from Bodmer
XPT2046_Touchscreen versie 1.4.0 from Paul Stoffregen
// The black screen not showing data is solved by the following settings in User_Setup.h
#define TFT_BL 15 // LED back-light control pin
#define TFT_BACKLIGHT_ON LOW // Level to turn ON back-light (HIGH or LOW)
Although later on different pin setting for TFT_BL also works.
Settings used in Arduino/libraries/TFT_eSPI/User_Setup.h
#define USER_SETUP_INFO "User_Setup" // ################################################################################## // // Section 1. Call up the right driver file and any options for it // // ################################################################################## #define ILI9341_2_DRIVER // Alternative ILI9341 driver, see https://github.com/Bodmer/TFT_eSPI/issues/1172 #define TFT_WIDTH 240 // ST7789 240 x 240 and 240 x 320 #define TFT_HEIGHT 320 // ST7789 240 x 320 // ################################################################################## // // Section 2. Define the pins that are used to interface with the display here // // ################################################################################## #define TFT_BL 21 // LED back-light control pin #define TFT_BACKLIGHT_ON HIGH // Level to turn ON back-light (HIGH or LOW) // ###### EDIT THE PIN NUMBERS IN THE LINES FOLLOWING TO SUIT YOUR ESP32 SETUP ###### // For ESP32 Dev board (only tested with ILI9341 display) // The hardware SPI can be mapped to any pins #define TFT_MISO 12 #define TFT_MOSI 13 #define TFT_SCLK 14 #define TFT_CS 15 // Chip select control pin #define TFT_DC 2 // Data Command control pin //#define TFT_RST 4 // Reset pin (could connect to RST pin) #define TFT_RST -1 // Set TFT_RST to -1 if display RESET is connected to ESP32 board RST #define TOUCH_CS 33 // Chip select pin (T_CS) of touch screen // ################################################################################## // // Section 3. Define the fonts that are to be used here // // ################################################################################## #define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH #define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters #define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters #define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm #define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:-. #define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-. //#define LOAD_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT #define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts // Comment out the #define below to stop the SPIFFS filing system and smooth font code being loaded // this will save ~20kbytes of FLASH #define SMOOTH_FONT // ################################################################################## // // Section 4. Other options // // ################################################################################## #define SPI_FREQUENCY 55000000 // STM32 SPI1 only (SPI2 maximum is 27MHz) #define SPI_READ_FREQUENCY 20000000 #define SPI_TOUCH_FREQUENCY 2500000 #define USE_HSPI_PORT
Relevant part from sketch
// Touchscreen pins #define XPT2046_IRQ 27 // T_IRQ #define XPT2046_MOSI 23 // T_DIN #define XPT2046_MISO 19 // T_OUT #define XPT2046_CLK 18 // T_CLK #define XPT2046_CS 14 // T_CS SPIClass touchscreenSPI = SPIClass(VSPI); XPT2046_Touchscreen touchscreen(XPT2046_CS, XPT2046_IRQ); #define SCREEN_WIDTH 240 #define SCREEN_HEIGHT 320
Hi.
The issue is probably something wrong with your connections.
Please double check the wiring. Also make sure you’re powering the display properly.
Regards.
Sara
Received the new board from Ali Express and although at first things did not go well, after some tries and errors the board works with the code. But the sketch 1.8 works now. Version of the board I have is the TS1950W-ESP32-2432S028 with USB-C connector.
So it seems that indeed my earlier hardware (AZ-Delivery ESP32 Devkit C v4 with the AZ-touch mod (https://www.az-delivery.de/nl/products/az-touch-wandgehauseset-mit-2-8-zoll-touchscreen-fur-esp8266-und-esp32) indeed has some differences in pin or lay-out. When I have figured this out, I’ll might publish it in case someone else also uses this combination from AZ-Delivery)
Thank you very much for your help
Will first check if copying the files again is necessary and invert suggestion (page 92 of the book)
Added: copying the files lv_conf.h and User_Setup.h might did solve the problem. The invert of the screen colors was not the problem as the screen was completely black.
But luckily it now works.
Great.
Is everything working as expected now?
In the end, did you need to make any changes?
Regards,
Rui
For the esp32 cyd, I reverted to the original files delivered by rnt. So in the end no changes were made. Excercise 1.8 works as expected now.
For the az-delivery board (stand-alone or as az touch mod kit) it will take some time for me, but I’m planning to try make these work in future also.
Can confirm with a stand-alone ESP32 devkit C v4 from Az-delivery everything works fine without modification. So it seems to be the specific combination of esp32 on Az-touch mod.
When having figured out the differences, I will update this post.
Tested with 12v power supply, but no difference. So not enough power does not seem to be the problem.
Tested some further and starting thinking that the AZ-Touch board used for the LVGL might not be working properly.
Going to solder a spare AZ-Touch mod board and will update this post after testing with that has been done.
Soldered new az-touch mod. No difference. Got hello world test and touch display working now, but touchscreen does not respond to touching. Thinking it might be defined pin or library problem.
Changed user_setup.h with the default gpio pins.
#define TFT_MISO 12 //12
#define TFT_MOSI 13 //13
#define TFT_SCLK 14 //14
#define TFT_CS 15 //15 // Chip select control pin
#define TFT_DC 2 //2 // Data Command control pin
#define TFT_RST 4 // 4 // Reset pin (could connect to RST pin)
//#define TFT_RST -1 // Set TFT_RST to -1 if display RESET is connected to ESP32 board RST
#define TOUCH_CS 21 //33 // Chip select pin (T_CS) of touch screen
The screen touching does now seem to work correctly, but screen is black. If I touch the screen it shortly turns white and returns to black (no output visible). The serial monitor outputs x, y and z and therefore the screen seems to respond properly. I cannot find which specific setting(s) is/are responsible for this behavior.
Hi.
Maybe your display uses different drivers and has the colors inverted??
Check out this discussion and see if it helps: https://rntlab.com/question/colors-inverted-on-cyb-esp32-display/
regards,
Sara
Got it working with a working copy from https://github.com/beabel/AZ_TOUCH_LVGL_DEMO
Most important change I noted is that HSPI instead of VSPI is used (last line in User_Setup.h). **** Update: back to vspi also seems also to work properly now. I’m quite confused why it does work now ****
Be carefull when copying the text to your sketch. The ” (double quote) after copying should be replaced by typing them again on the keyboard directly in the sketch editor. Otherwise errors about invalid type will occur during compiling. Same for indents which have dissapeared in the post. The most important changes are marked bolt.
Start your code here (1.9 - Testing the Touchscreen)
#include <lvgl.h>
#include <TFT_eSPI.h>
#include <XPT2046_Touchscreen.h>
// Touchscreen pins
#define XPT2046_IRQ 27 // T_IRQ
#define XPT2046_MOSI 23 // T_DIN
#define XPT2046_MISO 19 // T_OUT
#define XPT2046_CLK 18 // T_CLK
#define XPT2046_CS 14 // T_CS
#define TOUCH_ROTATION 1
SPIClass touchscreenSPI = SPIClass(HSPI);
XPT2046_Touchscreen touchscreen(XPT2046_CS, XPT2046_IRQ);
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
#define DRAW_BUF_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT / 10 * (LV_COLOR_DEPTH / 8))
uint32_t draw_buf[DRAW_BUF_SIZE / 4];
// Touchscreen coordinates: (x, y) and pressure (z)
int x, y, z;
// If logging is enabled, it will inform the user about what is happening in the library
void log_print(lv_log_level_t level, const char * buf) {
LV_UNUSED(level);
Serial.println(buf);
Serial.flush();
}
static lv_obj_t * text_label_touch;
// Get the Touchscreen data
void touchscreen_read(lv_indev_t * indev, lv_indev_data_t * data) {
// Checks if Touchscreen was touched and prints X, Y and Pressure (Z)
if(touchscreen.tirqTouched() && touchscreen.touched()) {
// Get Touchscreen points
TS_Point p = touchscreen.getPoint();
// Calibrate Touchscreen points with map function to the correct width and height
x = map(p.x, 200, 3700, 1, SCREEN_WIDTH);
y = map(p.y, 240, 3800, 1, SCREEN_HEIGHT);
z = p.z;
data->state = LV_INDEV_STATE_PRESSED;
// Set the coordinates
data->point.x = x;
data->point.y = y;
// Print Touchscreen info about X, Y and Pressure (Z) on the Serial Monitor
Serial.print(“X = “);
Serial.print(x);
Serial.print(” | Y = “);
Serial.print(y);
Serial.print(” | Pressure = “);
Serial.print(z);
Serial.println();
String touch_data = “X = ” + String(x) + “\nY = ” + String(y) + “\nZ = ” + String(z);
lv_label_set_text(text_label_touch, touch_data.c_str());
}
else {
data->state = LV_INDEV_STATE_RELEASED;
}
}
void lv_create_main_gui(void) {
// Create a text label aligned center: https://docs.lvgl.io/master/widgets/label.html
text_label_touch = lv_label_create(lv_screen_active());
lv_label_set_text(text_label_touch, “Touch screen to test”);
lv_obj_align(text_label_touch, LV_ALIGN_CENTER, 0, 0);
// Set font type and font size. More information: https://docs.lvgl.io/master/overview/font.html
static lv_style_t style_text_label;
lv_style_init(&style_text_label);
lv_style_set_text_font(&style_text_label, &lv_font_montserrat_18);
lv_obj_add_style(text_label_touch, &style_text_label, 0);
}
void setup() {
String LVGL_Arduino = String(“LVGL Library Version: “) + lv_version_major() + “.” + lv_version_minor() + “.” + lv_version_patch();
Serial.begin(115200);
Serial.println(LVGL_Arduino);
// Start LVGL
lv_init();
// Register print function for debugging
lv_log_register_print_cb(log_print);
// Start the SPI for the touchscreen and init the touchscreen
touchscreenSPI.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS);
touchscreen.begin(touchscreenSPI);
// Set the Touchscreen rotation in landscape mode
// Note: in some displays, the touchscreen might be upside down
// so you might need to set the rotation to 0: touchscreen.setRotation(0);
touchscreen.setRotation(TOUCH_ROTATION);
// Create a display object
// Initialize the TFT display using the TFT_eSPI library
lv_display_t * disp = lv_tft_espi_create(SCREEN_WIDTH, SCREEN_HEIGHT, draw_buf, sizeof(draw_buf));
// lv_display_set_rotation(disp, LV_DISPLAY_ROTATION_270);
// Initialize an LVGL input device object (touchscreen)
lv_indev_t * indev = lv_indev_create();
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
// Set the calibration function to read Touchscreen input
lv_indev_set_read_cb(indev, touchscreen_read);
// Function to draw the GUI with switches
lv_create_main_gui();
}
void loop() {
lv_task_handler(); // let the GUI do its work
lv_tick_inc(5); // tell LVGL how much time has passed
delay(5); // let this time pass
}
///////////// End of LVGL demo with touch positions and pressure
Start your code here <User_Setup.h>
/*
Rui Santos & Sara Santos – Random Nerd Tutorials
Install the “TFT_eSPI” library by Bodmer to interface with the TFT Display – https://github.com/Bodmer/TFT_eSPI
*** IMPORTANT: User_Setup.h available on the internet will probably NOT work with the examples available at Random Nerd Tutorials ***
*** YOU MUST USE THIS User_Setup.h FILE, CHECK FOR THE LATEST VERSION IN THE LINK BELOW IN ORDER TO USE THE EXAMPLES FROM RANDOM NERD TUTORIALS ***
https://RandomNerdTutorials.com/cyd/
https://RandomNerdTutorials.com/esp32-tft/
FULL INSTRUCTIONS AVAILABLE ON HOW CONFIGURE THE LIBRARY: https://RandomNerdTutorials.com/cyd/ or https://RandomNerdTutorials.com/esp32-tft/
*/
// User defined information reported by “Read_User_Setup” test & diagnostics example
#define USER_SETUP_INFO “User_Setup”
// ##################################################################################
//
// Section 1. Call up the right driver file and any options for it
//
// ##################################################################################
// Only define one driver, the other ones must be commented out
//#define ILI9341_DRIVER // Generic driver for common displays
#define ILI9341_2_DRIVER // Alternative ILI9341 driver, see https://github.com/Bodmer/TFT_eSPI/issues/1172
// For ST7789, ST7735, ILI9163 and GC9A01 ONLY, define the pixel width and height in portrait orientation
#define TFT_WIDTH 240 // ST7789 240 x 240 and 240 x 320
#define TFT_HEIGHT 320 // ST7789 240 x 320
// ##################################################################################
//
// Section 2. Define the pins that are used to interface with the display here
//
// ##################################################################################
// If a backlight control signal is available then define the TFT_BL pin in Section 2
// below. The backlight will be turned ON when tft.begin() is called, but the library
// needs to know if the LEDs are ON with the pin HIGH or LOW. If the LEDs are to be
// driven with a PWM signal or turned OFF/ON then this must be handled by the user
// sketch. e.g. with digitalWrite(TFT_BL, LOW);
#define TFT_BL 15 //21 // LED back-light control pin
#define TFT_BACKLIGHT_ON LOW //HIGH // Level to turn ON back-light (HIGH or LOW)
// ###### EDIT THE PIN NUMBERS IN THE LINES FOLLOWING TO SUIT YOUR ESP32 SETUP ######
// For ESP32 Dev board (only tested with ILI9341 display)
// The hardware SPI can be mapped to any pins
#define TFT_MISO 19 //12
#define TFT_MOSI 23 //13
#define TFT_SCLK 18 //14
#define TFT_CS 5 //15 // Chip select control pin
#define TFT_DC 4 //2 // Data Command control pin
#define TFT_RST 22 // 4 // Reset pin (could connect to RST pin)
//#define TFT_RST -1 // Set TFT_RST to -1 if display RESET is connected to ESP32 board RST
#define TOUCH_CS 14 //33 // Chip select pin (T_CS) of touch screen
// ##################################################################################
//
// Section 3. Define the fonts that are to be used here
//
// ##################################################################################
// Comment out the #defines below with // to stop that font being loaded
// The ESP8366 and ESP32 have plenty of memory so commenting out fonts is not
// normally necessary. If all fonts are loaded the extra FLASH space required is
// about 17Kbytes. To save FLASH space only enable the fonts you need!
#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:-.
#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
//#define LOAD_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT
#define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts
// Comment out the #define below to stop the SPIFFS filing system and smooth font code being loaded
// this will save ~20kbytes of FLASH
#define SMOOTH_FONT
// ##################################################################################
//
// Section 4. Other options
//
// ##################################################################################
// Define the SPI clock frequency, this affects the graphics rendering speed. Too
// fast and the TFT driver will not keep up and display corruption appears.
// With an ILI9341 display 40MHz works OK, 80MHz sometimes fails
// With a ST7735 display more than 27MHz may not work (spurious pixels and lines)
// With an ILI9163 display 27 MHz works OK.
// #define SPI_FREQUENCY 1000000
// #define SPI_FREQUENCY 5000000
// #define SPI_FREQUENCY 10000000
// #define SPI_FREQUENCY 20000000
//#define SPI_FREQUENCY 27000000
// #define SPI_FREQUENCY 40000000
#define SPI_FREQUENCY 55000000 // STM32 SPI1 only (SPI2 maximum is 27MHz)
// #define SPI_FREQUENCY 80000000
// Optional reduced SPI frequency for reading TFT
#define SPI_READ_FREQUENCY 20000000
// The XPT2046 requires a lower SPI clock rate of 2.5MHz so we define that here:
#define SPI_TOUCH_FREQUENCY 2500000
// The ESP32 has 2 free SPI ports i.e. VSPI and HSPI, the VSPI is the default.
// If the VSPI port is in use and pins are not accessible (e.g. TTGO T-Beam)
// then uncomment the following line:
#define USE_HSPI_PORT