Learn MicroPython #4 - Interrupts (event-driven code)

preview_player
Показать описание
Full code available on Github!
In the last video, we made a program that would turn an LED on whenever a button is pressed. However, we found that as long as the program is running, the Python REPL console is blocked from starting. At the end of this video, we will have a program that does the same thing with the LED and button, but will also allow the REPL to start. This will be accomplished by using a feature of MicroPython called "interrupts" that allows us to build the program in an event-driven way. Hope you have fun with this one!

**************************************************
We use FREE open source software with the following machines:
(ALL open source software is free so YOU can try it too) **************************************************

CNC ROUTER / MILLING MACHINE

(As an Amazon Associate I earn from qualifying purchases.)

**************************************************
FREE VIDEO DEMOS:
Laser Cutting TIPS & TRICKS
Vinyl Cutting TIPS & TRICKS
Wood Lathing TIPS & TRICKS
Milling / CNC Router TIPS & TRICKS
Metal Lathing TIPS & TRICKS
**************************************************

We have entire playlists on learning open source software so have fun learning! The solution is right around the corner... InventBoxTutorials.
Great tutorials. Free software. Open to the world.
Рекомендации по теме
Комментарии
Автор

Thanks for this set of M/P tutorials, very useful stuff indeed. This one caught my eye initially but i have since been back and watched the whole set. Well presented, well paced, clearly explained. Well done, Thanks!

capiberra
Автор

Nicely done, great simple example of IRQ's, ie Interrupt Request Queue, as I know them. Thanks for your work!

bradg
Автор

Igreat tutorial I am really looking forward started today with micropyton. TY

davidmarks
Автор

I just found out about your channel and I love it! Thank you so much

josseman
Автор

Thank you for this series, well explained! While this video shortly touches the possibility of having several interrupt pins, I still don't understand how to actually do this. I have 2 motors and 4 limit switches, so I want each motor to stop moving in a certain direction when it reaches the associated limit switch (movement controlled by a system of 3 relays per motor). Would I need 1 function and 4 irq objects? Or 2 functions? Is there any explanation or tutorial I could follow to understand this better? Thanks a lot!

annasarahkramerfazendeiro
Автор

My guess is that Micropython has a scheduler. Which is how it can make the interrupts' event handlers queue behind each other. The way interrupts work on machine level is much more complicated with priorities etc. Is my guess correct?

Kasslim
Автор

Hey thanks for the video. I found it while trying to troubleshoot my code. I followed your code, and have it just like yours is at 13:05, minus the sleep timer and with a print statement instead of the led output. Even though I have the handler set to IRQ_RISING it reacts for both rising and falling events. I thought it might be a debouncing issue but it still happens with a SPST switch instead of the tactile momentary switch. There is a debouncing issue still, but the it stops printing after about 5 times. But it does this for both states.

I'm running the code on an old Huzzah ESP8266 breakout with micropython v1.17

I'm gonna keep looking but any advice would be appreciated! Thanks!

ThalassTKynn
Автор

Can you make a video on using ESP-CAM with Micropython?!

freddymac
Автор

Interrupt Re Quest idk where you got query from

IRBry
Автор

How do I do long press ? Maybe I want the LED to turn on when I click the button and when I hold the button the LED should turn off.

minecraftteddy
Автор

i have a M5stack board. so, i want to create a event for textbox or create eventhandl, how do you do?

Huynh-Tan-Quoc
Автор

im having an issue.. My code is identical to yours.. but before I run it I get this yellow warning error: "Unresolved attribute reference 'irq' for class 'Pin'"
then when I run it.. I get an error:"TypeError: can't convert 'int' object to str implicitly"

any help? thanks

elliot
Автор

good morning,

I wanted to get the value of the pin that got the interruption.
example:

def callback (pin_irq):
print (pin_irq)

result:
Pin (14)


I need only the value 14 not "Pin (14)"
how can I do it?

tao
Автор

Hi and thanks for the video. I work with a ESP32 and I can't explain why when I press the button, it happen randomly like multiple presses. I tried to add a 10K resistor OR / AND use the Pin.IN.PULL_UP Pin() parameter. Do you have a idea please? Thanks!

thepierced
Автор

Why my led stays On even when i release the btn. ?

sergiomoranavarrete
Автор

Why doesn't this require a while loop?

anthonyanderson
Автор

It's possible to use threadding with MycroPython? To listen interrupts and execute at the same time. Thanks...

mrem
Автор

Nice but almost unwatchable. You have a very annoying fan running through the whole video.

ecy
join shbcf.ru