Wake M5 Tough from Light Sleep with GPIO Input???

  • Hi all.

    I'm totally new to the whole M5 world. I have a M5 Tough that I have been playing with, initially coding it with UiFlow, but now using PlatformIO in VSC with arduino based libraries.

    I've pretty much run into a wall straight away with my tinkering and I hope someone can help me out.

    What I would like to do is, place the Tough into a LightSleep mode and then wake it up from either a GPIO Input interrupt and also if the screen is touched.

    I stared playing with the sleep example in the M5Tough library, hacking it up a bit (Listed below) to introduce an Input on Pin 19 and associate it with an input interrupt. I've attached a simple push button circuit and proved it worked with a simple input pin read before trying to use it as the wake interrupt trigger.
    And I've tried all sorts of things with the interrupt handler code, but I just cant find a way to wake the Tough out of sleep. The only way the controller wakes in my test code is that the sleep timer expires. In fact I'm at the point of thinking the interrupt is not being seen at all when I push the button while the Tough is asleep.

    It would be greatly appreciated if anyone help me out with ideas, or better still, a piece of sample code?


    For ref here is the latest hack code I've been playing with:


    #include <M5Tough.h>

    void wakeUp() {
    // Wake-up interrupt handler
    // M5.Power.wakeUp();
    Serial.println("Interupt Wake Up.");
    M5.Lcd.println("Interupt Wake Up.");


    /* After M5Tough is started or reset
    the program in the setUp () function will be run, and this part will only be run once.
    在 M5Tough 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */
    void setup(){
    M5.begin(); //Init M5Tough. 初始化 M5Tough

    // Set GPIO Pin 19 as an input
    pinMode(19, INPUT_PULLUP);

    // Attach the wake-up interrupt to GPIO Pin 19
    attachInterrupt(digitalPinToInterrupt(19), wakeUp, RISING);

    M5.Lcd.setTextFont(2); //Set font size to 19. 设置字体大小为2

    Serial.println("Light / Deep Sleep Test."); //The serial port prints the formatted string with a newline. 串口输出格式化字符串并换行
    M5.Lcd.println("Light / Deep Sleep Test."); //The screen prints the formatted string and wraps it. 屏幕打印格式化字符串并换行


    void loop()
    Serial.println("Going to light sleep for 15 seconds.");
    M5.Lcd.println("Going to light sleep for 15 seconds.");

    delay(2500); //delay 2500ms. 延迟2500ms

    M5.Axp.LightSleep(SLEEP_SEC(15)); //Wake up after 5 seconds of light sleep, the CPU will reboot and the program will start from the beginning. 轻度睡眠10秒后重新启动,程序从下一行继续执行

    Serial.println("Wakeup from light sleep.");
    M5.Lcd.println("Wakeup from light sleep.");

  • Hello @galeap

    please find an example here about how M5Tough can wake up from touch.

    Info: the same code (with a different GPIO) can be use to wake from GPIO.

    Note: attachInterrupt() only works when ESP32 is running so you cannot use it while ESP32 is in light or deep sleep mode.


  • @felmue Thanks very much for the super fast reply and the sample code, it works a treat.

  • Hello @felmue,
    I'd like to check your example, but seems to be no longer online.

    Could you re-upload it?

    Many thanks,

  • Hello @dichi

    thank you for reporting. I've move all my Arduino examples into folders of the same name (since Arduino IDE expects it that way).

    I've fixed above link.


  • Thank you @felmue !