Page 1 of 1

Pin Interrupts

Posted: Mon Mar 28, 2016 10:17 am
by nui_de
At the moment I do not get the simplest things running, tried the
sample code for interrupts from the documentation:
http://micropython.org/resources/docs/e ... e.Pin.html

Code: Select all

from machine import Pin

def pincb(pin):
    print(pin.id())

pin_int = Pin('GP10', mode=Pin.IN, pull=Pin.PULL_DOWN)
pin_int.irq(mode=Pin.IRQ_RISING, handler=pincb)
This code throws:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: argument num/types mismatch

Shouldn't it be 'trigger=Pin.IRQ_RISING' instead of 'mode=Pin.IRQ_RISING'
However - I can not get the code to run properly. When triggering the Input the Heartbeard LED is
flashing rapidly to signal there was an Error - but I do not get any traceback, nothing. Please Help...

Re: Pin Interrupts

Posted: Mon Mar 28, 2016 10:44 am
by danicampora
Hello nui_de,

Thanks for reporting the error on the docs, it should indeed be: trigger=Pin.IRQ_RISING as you say. I'll correct the docs ASAP.

With that correction the code works perfectly, bare in mind that you have to test printing on interrupts using the serial terminal, sending data over telnet cannot be done inside ISRs. I think your issue is that you have an old firmware, please make sure to update to the latest one:

https://github.com/wipy/wipy/releases

Cheers,
Daniel