GPIO irq callback problem

Questions and discussion about The WiPy 1.0 board and CC3200 boards.
Target audience: Users with a WiPy 1.0 or CC3200 board.
Post Reply
Luit
Posts: 1
Joined: Sat Feb 25, 2017 11:58 am

GPIO irq callback problem

Post by Luit » Sat Feb 25, 2017 12:05 pm

Hi, I have exactly the same problem as described in http://forum.micropython.org/viewtopic.php?f=11&t=2583.

Here is my main.py:

import machine
import urequests
from machine import Pin


def pincb(pin):
url = "(my test url)"
params = { "test": "true" }
urequests.urlopen(url, "GET", params)

p_out = Pin('GP2', mode=Pin.OUT)
p_out.value(1)
pin_int = Pin('GP1', mode=Pin.IN, pull=Pin.PULL_UP
pin_int.irq(trigger=Pin.IRQ_RISING, handler=pincb)


I know that the handler works perfectly, because I tested it with telnet and my website's access logs. But for some reason when I connect GP2 and GP1 the red light starts to blink rapidly for a couple of seconds. After that nothing happens when I connect the two pins until I restart the WiPy.

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

Re: GPIO irq callback problem

Post by pythoncoder » Sun Feb 26, 2017 8:43 am

Testing a function from the REPL doesn't prove it will work as an interrupt handler. I suggest you read http://docs.micropython.org/en/latest/e ... rules.html.

The way to proceed is to have the interrupt handler set a flag which is tested in a main loop which runs forever. When the flag is set the main loop calls your handler and clears it.
Peter Hinch
Index to my micropython libraries.

Post Reply