M5 touch wakeup read coordinates
-
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.
-
Hello @cthulu
you want to check against
ESP_SLEEP_WAKEUP_EXT0
as wake-up cause since the touch interrupt line (GPIO36) is setup usingesp_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 -
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 usingM5.TP.flush()
?I am trying render some buttons on the screen and then go to deep sleep, waiting for the touch push.
-
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!