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

    M5 touch wakeup read coordinates

    Scheduled Pinned Locked Moved General
    4 Posts 2 Posters 2.1k Views 1 Watching
    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.
    • C Offline
      cthulu
      last edited by

      Hi, I am trying to update my weatherapp (modified from an open source project) to wake up when the screen is touched. I want to read the coordinates after the wakeup, do something, and go back to deep sleep (for 1hr).

      My proto-code is something like this

      #include <M5EPD.h>
      
      M5EPD_Canvas canvas(&M5.EPD);
      
      int x, y= 0;
      void setup()
      {
         M5.begin();
         M5.EPD.SetRotation(0);
         M5.EPD.Clear(true);
         canvas.createCanvas(960, 540);
         canvas.setTextSize(5);
         canvas.drawString("Touch The Screen!", 400, 20);
         canvas.pushCanvas(0, 0, UPDATE_MODE_DU4);
      }
      
      void loop()
      {
      
         if (M5.TP.available() || esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_TOUCHPAD)
         {
            M5.TP.update();
            tp_finger_t fingerItem = M5.TP.readFinger(0);
            x = fingerItem.x;
            y = fingerItem.y;
            canvas.setTextSize(5);
            canvas.drawFloat(x, 0, 400, 60);
            canvas.drawFloat(y, 0, 400, 60);
            canvas.pushCanvas(0, 0, UPDATE_MODE_DU4);
         }
        
         // Clear out all previous touch screen interrupts
         while(digitalRead(GPIO_NUM_36) == LOW)
         {
            M5.TP.flush();
            delay(10);
         }
      
         Serial.println("before sleep");
         Serial.flush();
         delay(1000);
      
         // Enable timer (3600 s)
         esp_sleep_enable_timer_wakeup(3600 * 1000000UL);
         esp_sleep_enable_ext0_wakeup(GPIO_NUM_36, LOW);
      
         gpio_hold_en((gpio_num_t) M5EPD_MAIN_PWR_PIN);
         gpio_deep_sleep_hold_en();
         esp_deep_sleep_start();
      
         // Only reached after light sleep
         Serial.println("after sleep");
         delay(1000);
      }
      

      Not sure this is the right way as I could not find any specific way to read the touch coordinates.

      felmueF 1 Reply Last reply Reply Quote 0
      • felmueF Online
        felmue @cthulu
        last edited by felmue

        Hello @cthulu

        you want to check against ESP_SLEEP_WAKEUP_EXT0 as wake-up cause since the touch interrupt line (GPIO36) is setup using esp_sleep_enable_ext0_wakeup().

        BTW: ESP_SLEEP_WAKEUP_TOUCHPAD is meant for an ESP32 feature where a GPIO can act as a touch sensor. See here (Which is different from the touch screen).

        Thanks
        Felix

        GPIO translation table M5Stack / M5Core2
        Information about various M5Stack products.
        Code examples

        C 1 Reply Last reply Reply Quote 0
        • C Offline
          cthulu @felmue
          last edited by

          Thanks @felmue!

          I will change that. Regarding reading the touch location, is that the proper way? First M5.TP.update() and then trying to clear the interrupt using M5.TP.flush()?

          I am trying render some buttons on the screen and then go to deep sleep, waiting for the touch push.

          C 1 Reply Last reply Reply Quote 0
          • C Offline
            cthulu @cthulu
            last edited by

            Looks like the code, with the modification you've suggested works! I can get the coordinates of the touch that lead to the wake up of the M5. Thanks!

            1 Reply Last reply Reply Quote 1

            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