$USD
  • EUR€
  • £GBP
  • $USD
TUTORIALS ESP8266 MicroPython

ESP8266 MicroPython - Tutorial 4: How To Interrupt Micropython

DFRobot May 03 2017 23

mode:Pin.IN input
   Pin.OUT output

value:output value

Pin.value ([value]) It means reading input level when it’s without parameter, and setting output level when it’s with parameter, which is 1/0.
Pin.irq(*,trigger, handler=None)


INTERRUPT

trigger
Pin.IRQ_FALLING, falling
Pin.IRQ_RISING, rising
Pin.IN, rising and falling
handler, callback 


Interrupt function program
 
Copy code 
"from machine import Pin[/align]value=1
counter=0
def func(v):
     global value,counter
     counter+=1
    led.value(value)
     if(value == 0):
     value = 1
    else:
    value = 0
    print("IRQ ",counter)
led = Pin(14, Pin.OUT)
led.value(0)
button = Pin(0, Pin.IN)
button.irq(trigger=Pin.IRQ_FALLING, handler=func)
while True:
    pass"
I don’t need the compiling environment of how to find port no. and how to enter esp8266 micropython. Refer to the previously published documents if you don’t understand. As shown below, after entering the compiling environment, paste our interrupt program according to the said method.


Press Ctrl+d to complete pasting and then run the program. Now it output <IRQ>, which means our program is good and is under execution. At this time, we can see that led light is in extinguished state on our esp8266 development board.

We connect a DuPont line to GPIO0 port of the board. Touch other pins with the other end of the DuPont line. There will be result as shown below. Every time of touch, led light will flash for one time, and counter number will increase. Therefore, we realize the effect of interruption.

Reference link: http://www.arduino.cn/thread-42726-1-1.html


REVIEW