UIFlow digital input interrupt

  • In UIFlow is it possible to use an interrupt on an input? when I get a sub millisecond low signal on an input I would like to run some code.

  • When you say sub millisecond I guess you are not going to use a button to interrupt, if so then how do you intend to interrupt from an input

  • 50hz triac phase control with zero crossing timing synchronization. 100micro second timing tolerance or better. I ended up porting to Arduino/C++, too many limitations with UIFlow for now, python maybe to slow anyway. UIFlow is a good tool for higher level/basic control.

  • Hello,
    try an execute block, look at my code below.

    First i defined the two variables "is_running" and "counter".
    In UIFlow i defined pin0 with GPIO26 as input with pull down resistor.!
    Then i defined the event_interrupt(pin) - procedure. I use it for counting impulses at the GPIO26, therefore it is necessary to declare the variables as globals.

    Every second i read in the main loop the value of the counter variable and reset the is_running variable.

    def event_interrupt(pin):
    global is_running, counter
    is_running = True
    counter += 1

    pin0.irq(trigger=machine.Pin.IRQ_RISING, handler=event_interrupt)


  • @Gaviota
    hello and thank you for your information.
    Would you be so kind to post the full code?
    It doesn't work for me - i always get a syntax error.

    Thanks in advance,


  • @Gaviota
    Hello Gaviota,
    thank you for sharing this information.

    I tried to implement it, but i get an error.
    Would you be so kind to post the whole program?

    Thank you in advance,


  • @Gaviota
    hello Gaviota,
    i tried to run your code, but i always get an error.
    Would you be so kind to post the full program so i can find my mistake.

    Thank yo in advance,

  • @Gaviota post was helpful to me. Thanks.
    Below is an example of a N/O button interrupt, connected between G26 and GND.
    Counter increments multiple times per button push.
    This shows that software debounce could be necessary in many cases.
    Cheers - BillT

  • I've created a custom module to avoid the need to use the "Execute" block. It basically gives you a way to set the pin number, trigger, and callback for the IRQ. You will still create your own function using Blockly.

    1. Create a Variable: example "counter"
    2. Create a Function:
      1. Name it what you like, example: "count_pulses"
      2. Add single step from Variables: change counter by 1
    3. Init PWM0 with your desired pin, freq, and duty
    4. Load the attached file under Custom | Open *.m5b file
    5. Drag "PIN_IRQ" from Custom onto your workspace
      1. Set the pin number (just an integer, 0 for example)
      2. Set your trigger "machine.Pin.IRQ_RISING"
      3. Set the handler to your function from step 2 above "count_pulses"
    6. Add a label if you want and set the loop event to update a label with the current counter value
    7. It sounds more complicated than it actually is, check the screenshot


    Your resulting code should look vaguely like this:

    from m5stack import *
    from m5ui import *
    from uiflow import *
    import machine
    counter = None
    label0 = M5TextBox(146, 187, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
    from numbers import Number
    def count_pulses():
      global counter
      counter = (counter if isinstance(counter, Number) else 0) + 1
    PWM0 = machine.PWM(26, freq=25000, duty=50, timer=0)
    pin0.irq(trigger=machine.Pin.IRQ_RISING, handler=count_pulses)
    while True:

    Have fun storming the castle!

  • @lyledodge I can’t see attached file. Is there any or it problem with my iPhone?