Problem with interrupt callback being called all the time without button being pressed

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
User avatar
Roberthh
Posts: 3668
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Problem with interrupt callback being called all the time without button being pressed

Post by Roberthh » Fri Oct 30, 2020 8:58 am

I do not agree that you cannot use IRQ/ISR on ESP32. Many people do. It just does not come easy. And many of the problems like bouncing and picking up noise on high impedance inputs with wires are common to the technology in general. The only ESP32/ESP8266 specific problem I have found was the multiple trigger on slow slopes.

In your case, you either have to use a different I/O pin with pull-up capability or use external pull-up resistor.

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

Re: Problem with interrupt callback being called all the time without button being pressed

Post by pythoncoder » Sun Nov 01, 2020 3:04 pm

@solarjoe It does sound as if you have an M5stack-specific hardware problem. I would write a simple test script, with the ISR just printing a message (perhaps with a timestamp) each time it's called, and a continuously running function which keeps using the WiFi. With no link in code between the ISR and the function, and nobody pressing the button, the ISR should never run.

If it does it's a strong indication that the hardware is broken, although I suppose it could conceivably be a firmware problem if the firmware is M5stack-specific. If it's an official build I guess you or one of us could run your script on the ESP32 reference board. I've never heard of a generic problem like this on standard hardware.
Peter Hinch
Index to my micropython libraries.

danzdiasm
Posts: 1
Joined: Wed Oct 13, 2021 5:57 am

Re: Problem with interrupt callback being called all the time without button being pressed

Post by danzdiasm » Wed Oct 13, 2021 6:03 am

I had the exact same problem, same hardware.

I've tried to fiddle with its electronics, no luck with passives.

I could solve the problem polling the button although, like so:

Code: Select all

lastState = button.value()
while True:
    if button.value() == 0 and lastState == 1:
        toggle_power()
        lastState = button.value()
    
    if button.value() == 1 and lastState == 0:
        lastState = button.value()
    
    time.sleep_ms(50) 
At first I thought about connecting and disconnecting WiFi whenever needed, but there is no sense in that and could cause problems.

Other pins doesn't suffer from this, since they are not right near the WiFi Antenna nor soldered right next to it.

I hope it have helped some way.

Post Reply