🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    ⚠️ HELP: LVGL on M5Stack CoreS3 not detecting touch events ⚠️

    Scheduled Pinned Locked Moved Arduino
    2 Posts 2 Posters 1.3k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R Offline
      Robertof
      last edited by Robertof

      Hello community,

      I'm trying to integrate LVGL 9.3.0 with the touch screen on M5Stack CoreS3, but I'm facing an issue: touch events are not being registered correctly in LVGL, even though the touch screen works fine when tested using M5Stack's official example code.

      📌 Software versions I'm using: ✅ M5Stack CoreS3 (ESP32-S3-based hardware) ✅ LVGL version: 9.3.0 ✅ M5Unified library version: Latest available version (checked via Arduino IDE) ✅ LovyanGFX library version: Latest available version ✅ Arduino IDE version: 1.8.19 ✅ ESP32 Board Support Package: Latest version installed via Board Manager

      📌 What I’ve tested so far: ✅ The touch screen works correctly using CoreS3.Touch.getDetail(). ✅ LVGL is not detecting touches, suggesting a possible misconfiguration in lv_indev_t. ✅ I've implemented synchronization with CoreS3.update(), but LVGL still does not process touch events.

      📜 Current code I'm using:

      #include <M5CoreS3.h>
      #include <lvgl.h>
      
      // 🛠 Screen instance
      M5GFX display;
      
      // 🛠 Callback function for display update in LVGL
      void flush_cb(lv_display_t *disp_drv, const lv_area_t *area, uint8_t *color_p) {
          display.pushImage(area->x1, area->y1, area->x2 - area->x1 + 1, area->y2 - area->y1 + 1, (uint16_t*)color_p);
          lv_display_flush_ready(disp_drv);
      }
      
      // 🛠 Touch event handling using CoreS3 and advanced debugging
      void my_input_read(lv_indev_t *indev, lv_indev_data_t *data) {
          CoreS3.update();
          auto t = CoreS3.Touch.getDetail();
      
          data->point.x = t.x;
          data->point.y = t.y;
      
          Serial.print("📍 Touch state: "); Serial.println((int)t.state);
          Serial.print("📍 Coordinates → X: "); Serial.print(t.x);
          Serial.print(" Y: "); Serial.println(t.y);
      
          if (t.state == m5::touch_state_t::touch_begin || t.state == m5::touch_state_t::hold_begin || t.state == m5::touch_state_t::drag_begin) {
              data->state = LV_INDEV_STATE_PR;
              Serial.println("✅ LVGL has detected the touch!");
          } else {
              data->state = LV_INDEV_STATE_REL;
          }
      }
      
      // 🛠 Creating a test button in LVGL
      void create_button(lv_obj_t *parent) {
          lv_obj_t *btn = lv_btn_create(parent);
          lv_obj_set_size(btn, 100, 50);
          lv_obj_align(btn, LV_ALIGN_CENTER, 0, 0);
      
          lv_obj_t *label = lv_label_create(btn);
          lv_label_set_text(label, "Press");
          lv_obj_center(label);
      
          lv_obj_add_flag(btn, LV_OBJ_FLAG_CLICKABLE);
      }
      
      // 🛠 System initial setup
      void setup() {
          auto cfg = M5.config();
          CoreS3.begin(cfg);
          Serial.begin(115200);
          Serial.println("\n🚀 M5Stack CoreS3 initialized with LVGL 9.3.0 🚀\n");
      
          display.init();
          lv_init();
          display.begin();
          display.setColorDepth(16);
      
          static lv_display_t *disp_drv = lv_display_create(320, 240);
          lv_display_set_flush_cb(disp_drv, flush_cb);
      
          // 🚀 Dynamic memory allocation to optimize RAM usage
          static lv_color_t *buf1 = (lv_color_t*)malloc(320 * 50 * sizeof(lv_color_t));
          if (buf1 == NULL) {
              Serial.println("❌ Error: Failed to allocate memory.");
              return;
          }
          lv_display_set_buffers(disp_drv, buf1, NULL, 320 * 50 * sizeof(lv_color_t), LV_DISPLAY_RENDER_MODE_PARTIAL);
      
          // 🛠 Properly initialize the touch input handler in LVGL
          lv_indev_t *indev = lv_indev_create();
          lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
          lv_indev_set_read_cb(indev, my_input_read);
      
          // 🛠 Create a test button in LVGL
          create_button(lv_scr_act());
      
          Serial.println("✅ LVGL initialized correctly, waiting for interaction...");
      }
      
      // 🛠 Main loop for touch updates and LVGL handling
      void loop() {
          CoreS3.update();
          lv_timer_handler();
          delay(5);
      }
      

      💡 Has anyone successfully enabled touch detection in LVGL with M5Stack CoreS3? If you have any suggestions, insights, or working code examples, I’d really appreciate your help. 🙏

      Thanks in advance for any assistance! 🚀 Let’s get this working! 💪🔥

      1 Reply Last reply Reply Quote 0
      • A Offline
        andremp
        last edited by

        This post is deleted!
        1 Reply Last reply Reply Quote 0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • First post
          Last post