Hey ! I think I have the same issue and none of the answers has worked. #11024
Replies: 3 comments
-
You have the pin object in the interrupt handler. So you should be able to compare like:
and so on. Getting the pin number from the pin object is a known cumbersomeness in Micropython: You have to extract it from the string representation. Like: I see now I repeated old answers/advices. In the headings you state: None of the answers has worked. Please elaborate what you tried and how it didn't work. Perhaps you wanted to urge on this problem (is this correct English?). If you wanted to start a query on that feature (having a pin.id() function) I would support it. But consider: Pins are sometimes numbers, sometimes letters, ... |
Beta Was this translation helpful? Give feedback.
-
I'll convert that to a discussion, which is the better place to deal with it. |
Beta Was this translation helpful? Give feedback.
-
Ok.- So i hooke it up to a board. Two problems with that sample script came along:
Besides that, here a sample script with one of the solutions:
Tested with a Wemos D1 Mini and a signal generator. I do not know your application and what you want to do with the pin, but the basic mechanism works. Alternatively you could define a separate callback for each pin, and call a common handler by these. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am listenning 5 pins. And I try to guess which has raised the interrupt.
p1 = machine.Pin(1, machine.Pin.IN)
p2 = machine.Pin(2, machine.Pin.IN)
p4 = machine.Pin(4, machine.Pin.IN)
p5 = machine.Pin(5, machine.Pin.IN)
p6 = machine.Pin(6, machine.Pin.IN)
def handle_pwm_interrupt(pin):
p1.irq(trigger=machine.Pin.IRQ_FALLING | machine.Pin.IRQ_RISING, handler=handle_pwm_interrupt)
p2.irq(trigger=machine.Pin.IRQ_FALLING | machine.Pin.IRQ_RISING, handler=handle_pwm_interrupt)
p4.irq(trigger=machine.Pin.IRQ_FALLING | machine.Pin.IRQ_RISING, handler=handle_pwm_interrupt)
p5.irq(trigger=machine.Pin.IRQ_FALLING | machine.Pin.IRQ_RISING, handler=handle_pwm_interrupt)
p6.irq(trigger=machine.Pin.IRQ_FALLING | machine.Pin.IRQ_RISING, handler=handle_pwm_interrupt)
when I do this the display is "Pin(GPIO4, mode=IN)".
I tried pin.name(), pin.id(), pin.id and each time i get :"File "", line 16, in handle_pwm_interrupt
AttributeError: 'Pin' object has no attribute 'name'"
And with id(pin) i get "268703464" which doesn't help me much to know which pin it is.
Do you have advices ?
Originally posted by @AlexandreLarribau in #2612 (comment)
Beta Was this translation helpful? Give feedback.
All reactions