'Long press' changed after firmware upgrade?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
dnoha
Posts: 7
Joined: Sat Jan 11, 2020 11:43 am

'Long press' changed after firmware upgrade?

Post by dnoha » Sat Jan 11, 2020 11:55 am

I had one loop to determine if button at GPIO0 was just pressed or hold for more seconds.

With old firmware, my NodeMCU device reset automatically if button (GPIO0) was hold for more then 8 sec. Therefore I counted 6 seconds (with sound feedback to user after each second), and after that switch AP mode on. Copy of code bellow.

With new firmware same NodeMCU resets after only 2 or 3 seconds. So I can not use this function any more.

Something changed in firmware between those two versions, regarding this issue?

Old firmware used: esp8266-20190125-v1.10
New firmware used: esp8266-20191220-v1.12
(I did erase flush while upgrading)

Code: Select all

def pinBTN_cb(p):
    a=machine.disable_irq()
    if p.value() == 0:
        t0 = time.ticks_ms()-1001
        t1 = t0

        b = 0
        # loop waiting button release
        while p.value() == 0:
            t2 = time.ticks_ms()
            # sound tick every sec
            if (t2-t1)>=1000:
                print('tick: ' + str(int((t2-t0-1000)/1000)) + ' sec')
                sound(0)
                t1=t2
            # sound tick after 6 sec
            if ((t2-t0)-1000>=6000 and b==0):
                sound(1)
                b=1
        # after release, continue program, b = number of seconds while pressed
        d=int((t2-t0-1000)/1000) 
        # short click (less then 1 sec)
        if d==0:
            # send some mqtt message
        # more then 6 sec
        if d>=6:
            print('STARTING AP')
            sound(1)
            do_AP_onoff(True)
    machine.enable_irq(a)

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: 'Long press' changed after firmware upgrade?

Post by jimmo » Mon Feb 03, 2020 5:24 am

dnoha wrote:
Sat Jan 11, 2020 11:55 am
With new firmware same NodeMCU resets after only 2 or 3 seconds.
My guess is that disabling IRQs for that long is going to cause issues. Why do interrupts need to be disabled while this is running?

When it resets, does it give any information about why? (e.g. watchdog timer?)

I'd suggest rewriting it in a more interrupt-driven mode rather than blocking. i.e. have a handler for pin up, pin down, and a tick every 500ms or something.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: 'Long press' changed after firmware upgrade?

Post by pythoncoder » Mon Feb 03, 2020 9:11 am

There is an asynchronous driver for pushbuttons in this repo. You can define callbacks to run on press, release, long press or double-click events.
Peter Hinch
Index to my micropython libraries.

Post Reply