• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Learn LVGL 1.9 touch test

Q&A Forum › Category: Other › Learn LVGL 1.9 touch test
0 Vote Up Vote Down
David Fenner asked 6 days ago

Could you please also help me resolve the following problem?
I am trying to use Example 1.9 from your e-book “Learn_LVGL_Build_GUIs_for_ESP32_Projects_V1_5.”
The display momentarily display text presumably “Touch screen to test” and then displays with no interaction with the screen pen.
x=-11
Y=344
Z=4101
Any assistance would be greatly appreciated.
Best Regards
Back ground
The display etc are; –
2.8″ MSP2807 Red board TFT resistive 320 x 240 display using an ili9341
The display is being driven by a 30pin ESP32 Module
The IDE monitor facility repeatedly displays
X = -11 | Y = 344 | Pressure = 4101
[Warn]  (0.600, +30)        indev_pointer_proc: X is 344 which is greater than hor. res lv_indev.c:717
[Warn]  (0.600, +0)          indev_pointer_proc: Y is 250 which is greater than ver. res lv_indev.c:723
The compiler displays.
C:/Users/Me/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2411/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld.exe: warning: C:/Users/Me/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2411/bin/../lib/gcc/xtensa-esp-elf/14.2.0/esp32/no-rtti/crtn.o: missing .note.GNU-stack section implies executable stack
C:/Users/Me/AppData/Local/Arduino15/packages/esp32/tools/esp-x32/2411/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld.exe: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
Sketch uses 638334 bytes (48%) of program storage space. Maximum is 1310720 bytes.
Global variables use 37328 bytes (11%) of dynamic memory, leaving 290352 bytes for local variables. Maximum is 327680 bytes.
A copy of your updated INO file
/*  Rui Santos & Sara Santos – Random Nerd Tutorials – https://RandomNerdTutorials.com/esp32-lvgl-ebook/
    THIS EXAMPLE WAS TESTED WITH THE FOLLOWING HARDWARE:
    1) ESP32-2432S028R 2.8 inch 240×320 also known as the Cheap Yellow Display (CYD): https://makeradvisor.com/tools/cyd-cheap-yellow-display-esp32-2432s028r/
      SET UP INSTRUCTIONS: https://RandomNerdTutorials.com/cyd-lvgl/
    2) REGULAR ESP32 Dev Board + 2.8 inch 240×320 TFT Display: https://makeradvisor.com/tools/2-8-inch-ili9341-tft-240×320/ and https://makeradvisor.com/tools/esp32-dev-board-wi-fi-bluetooth/
      SET UP INSTRUCTIONS: https://RandomNerdTutorials.com/esp32-tft-lvgl/
    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*/
 
/*  Install the “lvgl” library version 9.X by kisvegabor to interface with the TFT Display – https://lvgl.io/
    *** IMPORTANT: lv_conf.h available on the internet will probably NOT work with the examples available at Random Nerd Tutorials ***
    *** YOU MUST USE THE lv_conf.h FILE PROVIDED IN THE LINK BELOW IN ORDER TO USE THE EXAMPLES FROM RANDOM NERD TUTORIALS ***
    FULL INSTRUCTIONS AVAILABLE ON HOW CONFIGURE THE LIBRARY: https://RandomNerdTutorials.com/cyd-lvgl/ or https://RandomNerdTutorials.com/esp32-tft-lvgl/   */
#include <lvgl.h>
 
/*  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 THE User_Setup.h FILE PROVIDED IN THE LINK BELOW IN ORDER TO USE THE EXAMPLES FROM RANDOM NERD TUTORIALS ***
    FULL INSTRUCTIONS AVAILABLE ON HOW CONFIGURE THE LIBRARY: https://RandomNerdTutorials.com/cyd-lvgl/ or https://RandomNerdTutorials.com/esp32-tft-lvgl/   */
#include <TFT_eSPI.h>
 
// Install the “XPT2046_Touchscreen” library by Paul Stoffregen to use the Touchscreen – https://github.com/PaulStoffregen/XPT2046_Touchscreen – Note: this library doesn’t require further configuration
#include <XPT2046_Touchscreen.h>
 
 
// Touchscreen pins
#define XPT2046_IRQ 26   // T_IRQ
#define XPT2046_MOSI 23 // T_DIN
#define XPT2046_MISO 19  // T_OUT
#define XPT2046_CLK 18   // T_CLK
#define XPT2046_CS 5    // T_CS
 
SPIClass touchscreenSPI = SPIClass(VSPI);
XPT2046_Touchscreen touchscreen(XPT2046_CS, XPT2046_IRQ);
 
#define SCREEN_WIDTH 240
#define SCREEN_HEIGHT 320
 
// Touchscreen coordinates: (x, y) and pressure (z)
int x, y, z;
 
#define DRAW_BUF_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT / 10 * (LV_COLOR_DEPTH / 8))
uint32_t draw_buf[DRAW_BUF_SIZE / 4];
 
// 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 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(2);
 
  // Create a display object
  lv_display_t * disp;
  // Initialize the TFT display using the TFT_eSPI library
  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 callback 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
}

3 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 6 days ago

Hi.
Can you try changing the width with the height?
#define SCREEN_WIDTH 240
#define SCREEN_HEIGHT 320

Let me know if you get a different result.
 
Additionally, make sure all connections are correct. Otherwise, you may get false positive touches.
 
Regards,
Sara

0 Vote Up Vote Down
David Fenner answered 5 days ago

Display Wiring
Sara,
Thank you for your fast response. My feedback to your message is as follows:-
 I have swapped over the width and the heights as you suggested the display still acts the same, with an incorrect aspect ratio you would expect. With the following parameters are displayed
X=-11
Y=344
Z=4101
 
The monitor this time repeatedly displays: –
greater than hor. res lv_indev.c:717

[Warn]     (0.360, +0) indev_pointer_proc: Y is 334 which is greater than ver. res lv_indev.c:723

X = -15 | Y = 258 | Pressure = 4101
[Warn]     (0.390, +30)     indev_pointer_proc: X is 258 which is greater than hor. res lv_indev.c:717

I do notice that one of the other forum members posted a very similar issue using a different board. But unfortunately, there is no final conclusion.
https://rntlab.com/question/learn-lvgl-1-9-touch-test/
As you can see, I have included a picture of my wiring setup.
Using the IDE test and diagnostic mode for the TFT_eSPI the monitor displayed streams out random x,y &z coordinates  until I put the pen on the screen where they become more stable and represented, where I was placing the pen, is this how this function works?
As an experiment, I have tested out the following code and this behaves, as I would expect. 4 Call markers that respond to my pen press correctly, the text displayed, and I can draw on the display.
So it looks like the hardware is OK.
// tft_test.ino
#include “TFT_setup.h”
#include “TFT_eSPI.h”

TFT_eSPI tft = TFT_eSPI();
uint16_t cal[5] = { 0, 0, 0, 0, 0 };

void calibrate_touch() {
  if (!cal[1]) {
    tft.fillScreen(TFT_BLACK);
    tft.calibrateTouch(cal, TFT_YELLOW, TFT_BLACK, 20);
    Serial.printf(“cal[5] = {%d, %d, %d, %d, %d};\n”,
                  cal[0], cal[1], cal[2], cal[3], cal[4]);
  }
}

void setup(void) {
  Serial.begin(115200);

  tft.init();
  tft.setRotation(1);
  calibrate_touch();
  tft.setTouch(cal);

  tft.fillScreen(TFT_BLACK);
  tft.setTextFont(1);
  tft.setTextSize(2);
  tft.setTextColor(TFT_WHITE, TFT_BLACK);
  tft.setTextDatum(CC_DATUM);
  tft.drawString(“Makerguides”, TFT_HEIGHT / 2, TFT_WIDTH / 2);
}

void loop() {
  uint16_t x, y;
  if (tft.getTouch(&x, &y)) {
    Serial.printf(“%d %d\n”, x, y);
    tft.fillCircle(x, y, 2, TFT_YELLOW);
  }
}

// tft_setup.h
// 2.8″ TFT Touch Display
// 240x 320, Driver: ILI9341

//#define ILI9341_DRIVER     
#define ILI9341_2_DRIVER 

#define TFT_WIDTH  240
#define TFT_HEIGHT 320
#define TFT_RGB_ORDER TFT_BGR 

// WEMOLS Lolin32 lite
#define TFT_CS    15  
#define TFT_RST   4
#define TFT_DC    2 
#define TFT_MOSI  23  // SDA // HW MOSI
#define TFT_SCLK  18  // SCL // HW SCLK
#define TFT_MISO  19  // HW MISO
//#define TFT_BL    22  // LED back-light
#define TFT_BACKLIGHT_ON HIGH

#define TOUCH_CS 5
#define TOUCH_CLK TFT_SCLK
#define TOUCH_DIN TFT_MOSI
#define TOUCH_DO TFT_MISO

#define LOAD_GLCD  
#define LOAD_FONT2 
#define LOAD_FONT4 
#define LOAD_FONT6 
#define LOAD_FONT7 
#define LOAD_FONT8 
#define LOAD_GFXFF
#define SMOOTH_FONT

#define SPI_FREQUENCY  27000000
#define SPI_READ_FREQUENCY  20000000
#define SPI_TOUCH_FREQUENCY  2500000
 

0 Vote Up Vote Down
Sara Santos Staff answered 3 days ago

Hi.
The image was not uploaded.
Please upload the image to Google Drive or Imgur, or Dropbox, and then, share a link to the file.
 
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn LVGL: Build GUIs for ESP32 Projects – Version 1.5 July 7, 2025
  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.