🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    UIFlow digital input interrupt

    UIFlow
    10
    13
    18.1k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G
      Gaviota
      last edited by Gaviota

      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)

      0_1595778123207_interrupt.jpg

      A lot of nice M5Stack stuff :) ....

      B 1 Reply Last reply Reply Quote 0
      • S
        Schubi
        last edited by

        @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,

        Schubi

        1 Reply Last reply Reply Quote 0
        • S
          Schubi
          last edited by

          @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,

          Schubi

          1 Reply Last reply Reply Quote 0
          • S
            Schubi
            last edited by

            @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,
            Schubi

            1 Reply Last reply Reply Quote 0
            • B
              BT99
              last edited by

              @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
              0_1614130213067_interrupt.PNG

              1 Reply Last reply Reply Quote 2
              • L
                LyleDodge
                last edited by

                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

                0_1622847040214_PWM_IRQ_Demonstration.png

                Your resulting code should look vaguely like this:

                from m5stack import *
                from m5ui import *
                from uiflow import *
                import machine
                
                setScreenColor(0x222222)
                
                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:
                  label0.setText(str(counter))
                  wait_ms(2)
                

                Have fun storming the castle!

                D 1 Reply Last reply Reply Quote 5
                • D
                  Doswiadczalnik @LyleDodge
                  last edited by

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

                  1 Reply Last reply Reply Quote 1
                  • B
                    bozho @Gaviota
                    last edited by

                    Hi @Gaviota.
                    Currently I'm still learning to use UI Flow IDE and I want to crate the same thing- counting pulses and showing them on the screen. Can you send me your Blocky?
                    Thanks,
                    Bozho

                    A 1 Reply Last reply Reply Quote 0
                    • P
                      peolsolutions Banned
                      last edited by

                      A digital input interrupt in UIFlow is used to respond instantly to changes in the state of a pin, such as the pressing or releasing of a button. Instead of constantly checking the pin, you set an interrupt on a chosen GPIO with rising, falling, or changing detection. The callback function is triggered by this event, making your program more efficient and responsive to real-time input without using excessive processing power.

                      1 Reply Last reply Reply Quote 0
                      • A
                        adamm5 @bozho
                        last edited by

                        @bozho did you have any luck. It is clear on Uiflow1 how to detect rising inputs but I don't see this on Uiflow2...or is this is actually what is meant by the 'button press' block on the 'pin button' hardware module?

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post