What's up with the Signal class?
Posted: Mon Mar 07, 2022 5:46 am
OK, my experience with the Signal class is only with MicroPython 1.18 for the RP2 (Pico Pi). I looked at the Signal class for simplifying a de-bounce circuit that I have made, which currently only works for Pin inputs that are pulled up. I want to integrate the code that I have, which is also integrated with Pin.irq() to handle servicing the Pin with an interrupt.
I'm not that much up on classes in Python, but it appears that the Signal class either "has a" Pin class, or "is a" Pin class. so I constricted a Signal class like this.
At this point, I wanted to execute the following code to associate an IRQ with the Signal so that I could handle it in an IRQ handler:
At this point, the error that I got was that g_k1_signal did not have an attribute 'irq'. As I read the documentation on the Signal class, it was my understanding that the Signal class would "have a" Pin or would "be a" Pin class. When i did the following in REPL, I got the following information:
The only Pin attributes exposed by the Signal class consist of value(), on() and off(). It would have been nice to keep the name of the Signal class 'g_k1_signal' for the name associated with the IRQ handler. As you can see, the underlying PIN of the Signal class does have an attribute of irq().
I just wonder why the Signal class does not handle the irq() attribute of the underlying Pin class. This lack of propagation for the irq() attribute, from what I can see, does a pretty good job of wrecking the utility of the Signal class.
I'm not that much up on classes in Python, but it appears that the Signal class either "has a" Pin class, or "is a" Pin class. so I constricted a Signal class like this.
Code: Select all
g_k1_signal = Signal(15, Pin.IN, Pin.PULL_UP, invert=True)
Code: Select all
g_k1_signal.irq(handler = bouncer_handler, trigger = Pin.IRQ_FALLING
Code: Select all
MicroPython v1.18 on 2022-01-17; Raspberry Pi Pico with RP2040
Type "help()" for more information.
>>> from machine import Pin, Signal
>>> help (Signal)
object <class 'Signal'> is of type type
value -- <function>
on -- <function>
off -- <function>
>>>
Code: Select all
help(Pin)
object <class 'Pin'> is of type type
init -- <function>
value -- <function>
low -- <function>
high -- <function>
off -- <function>
on -- <function>
toggle -- <function>
irq -- <function>
IN -- 0
OUT -- 1
OPEN_DRAIN -- 2
ALT -- 3
PULL_UP -- 1
PULL_DOWN -- 2
IRQ_RISING -- 8
IRQ_FALLING -- 4