004 - ESP32 MicroPython: External Interrupt
ฝัง
- เผยแพร่เมื่อ 27 ส.ค. 2024
- In this video, we will learn 2 ways to read the state of an input device like a button switch. Firstly, is by using a polling method and secondly, by using interrupts. At the last part, I will demonstrate an example of controlling a DC motor with limit switch at both ends using interrupts.
Circuit diagram and source code is available at my blogpost at:
techtotinker.c...
Please COMMENT, LIKE, SHARE and SUBSCRIBE.
Thank you.
#TechToTinker
Nice tutorial. Very clearly explained. I like the clarity of your engineering.
Hi, Im happy to hear that. Thank you.
Thank you sir, this helped me to start with microPython and improve my CV 🙏🙏
Great video !
@Karl Ivares, thank you.
I am coming from JavaScript background. This interrupt callback makes me feel at home.
This is great and wont block other code. Is there a simple example you can use with serial input like to time a question with interrupts such that respose = input('Enter answer: ') if response == None, print('Fail!') but based on a timer?
very easy to understand weldone
Hi @Unique Food Machinery ltd, I am glad that you like it. Thank you.
Great material, would you create a GUI, for instance in Livy to control a motor? Thanks for the video
Hi @NesbyBone, thank you. As of now, I have no experience with Livy. Lets see in the future, I look into it.
Isn't there a problem with the parsing operation in the IRQ handler? As far as I understand it, you're not supposed to do anything that allocates memory. What about the str() conversion?
Very useful tutorial 👍👍
Glad you think so! Thanks.
SIr, how can I disable OTA memory in my esp32E by using Thonny. I need more memory
I don't understand pin parsing. For example for pin 21 ,str(pin) is '21:IN:PULL_UP' then how come str(pin)[4:-1] returns pin number but not ':PULL_U'
.......
Please explain
me too. Don't understand this part.
Try to play with this code and you will understand it :-)
import machine
led = machine.Pin(2, machine.Pin.OUT)
sw = machine.Pin(0, machine.Pin.IN)
def handle_interrupt(pin):
led.value(not led.value())
print("Original string: " + str(pin) + " Parsed string: " + str(pin)[4:-1])
print("Press BOOT button
")
sw.irq(trigger=machine.Pin.IRQ_FALLING, handler=handle_interrupt)
Good explanation
Hi Jan, Im glad that you like it. Thank you.
@@TechToTinker Please can you explain more the code line : irq_pin = int(str(pin)[ 4 : -1]) is the number 4 detrmining the speed and what -1 presents ?
@@alzalame that line of code is use to parse the actual pin number of the interrupt.
What is the meaning of int(str(pin)[4:-1])
where does number 4 and - 1 come from? and what is the symbol : between mean?
I have a question sir.
I realized that the program only runs when I connect the COM port to the computer if I want to do a project on battery power, what should I do sir please answer a question that I am pondering.
Obrigado pelo vídeo! Like e Inscrito! Abraços...
You are welcome @Professor Marcos Carnevali. Cheers and thank you.
@@TechToTinker também estou fazendo vídeos sobre Micropython, estou aprendendo e ensinando também! Compartilhei o seu vídeo com os meus amigos! Parabéns!!! Abraços...
@@ProfessorMarcosCarnevali wow that's cool. Can you share your videos here? I would like to check it out. Thanks
@@TechToTinker são vídeos bem humildes, para pessoas que apenas conhecem o idioma português. Tthese are very humble videos, for people who only know the Portuguese language. My playlist: th-cam.com/play/PLCcdteC1rwSFvJnUoe0DfORHv4p_1EFps.html
@Professor Marcos Carnevali you've got a lot of MicroPython tuts there. Only problem is I can't understand Portuguese :). Anyways I love knowing other people doing similar things as I doing.
Hello is it possible to enable and disable an interrupt?
@Matthias Andreas, I haven't tried it before it says machine.disable_irq() which will disable all esps interrupts. Call machine.enable_irq() to re/enable interrupts. Refer to:docs.micropython.org/en/latest/library/machine.html
@@TechToTinker , hi and thank you yes this way i tried out but on ESP32 i get OSErrors. I will try it again. By the way please can you make a video about Socket Server with ESP32 and micropython?
@@matthiasandreas6549 MicroPython web server: th-cam.com/video/i8b-ZM2VeeU/w-d-xo.html
Esp32 web server: th-cam.com/video/Lqn2J7LesCY/w-d-xo.html
Bro.meaning of led.value(not led.value())
Bro please reply
@@prakashkalvin7678 toggle the status of the led
if it's ON then turn it off
it it's OFF then turn it on.