ExtInt - External Interrupt

This class configures I/O pins to interrupt when external events occur.

Constructor#

machine.ExtInt#

class machine.ExtInt(GPIOn, mode, pull, callback, [filter_time])

Parameter:

  • GPIOn - Integer type. GPIO pin number to be controlled. See Pin Modules for pin definitions (excluding BG95M3). Click here to view pin correspondences of BG95M3 platform.

  • mode - Integer type. Trigger mode.
    IRQ_RISING – Trigger rising edge
    IRQ_FALLING – Trigger falling edge
    IRQ_RISING_FALLING – Trigger rising and falling edge

  • pull - Integer type. Pull selection mode.
    PULL_PU – Pull-up mode
    PULL_PD – Pull-down mode
    PULL_DISABLE – Floating mode

  • callback - Integer type. The interrupt triggers the callback function.
    A tuple with the length of 2 bytes
    args[0]: GPIO number
    args[1]: Trigger edge (0: rising edge 1: falling edge)

  • [filter_time] - Integer type. Filtering time,uint: ms, default value is 0.Allowed input nonzero value is multiple of 10.If the value is not 0, the filtering is performed at the specified time.

    parameter [filter_time] only EG912N/EG915N/EC600M/EC800M/EG810M/EC200A/UC200A series module support

Pin Correspondences of BG95M3 Module
GPIO2 – Pin5
GPIO3 – Pin6
GPIO6 – Pin19
GPIO7 – Pin22
GPIO8 – Pin23
GPIO9 – Pin25
GPIO11 – Pin27
GPIO12 – Pin28
GPIO14 – Pin41
GPIO16 – Pin65
GPIO17 – Pin66
GPIO18 – Pin85
GPIO19 – Pin86
GPIO22 – Pin20
GPIO23 – Pin21
GPIO24 – Pin30
GPIO25 – Pin34
GPIO26 – Pin35
GPIO29 – Pin38
GPIO30 – Pin39

Example:

>>> # Creates an ExtInt object 
>>> from machine import ExtInt
>>> def fun(args):
        print('### interrupt  {} ###'.format(args)) # args[0]: GPIO number args[1]: rising edge or falling edge
>>> extint = ExtInt(ExtInt.GPIO1, ExtInt.IRQ_FALLING, ExtInt.PULL_PU, fun)

Methods#

extint.enable#

extint.enable()

This method enables interrupts that is to enable external interrupt of an extint object. When the interrupt pin receives the rising edge signal or falling edge signal, it will call a callback function to execute the interrupt.

Return Value:

0 - Successful execution

-1 - Failed execution

extint.disable#

extint.disable()

This method disables interrupts associated with extint objects.

Return Value:

0 - Successful execution

-1 - Failed execution

extint.line#

extint.line()

This method reads the line number mapped by the pin.

Return Value:

The line number mapped by the pin.

Example:

>>> extint = ExtInt(ExtInt.GPIO1, ExtInt.IRQ_FALLING, ExtInt.PULL_PU, fun)
>>> extint.line()
1

extint.read_count#

extint.read_count(is_reset)

This method returns number of times an interrupt was triggered.

Parameter:

  • is_reset - Integer type. Whether to reset the count after reading. 0 indicates that the count is not resetted and 1 indicates a count resetting.

Return Value:

The list [rising_count, falling_count]
rising_count: Number of times that the rising edge triggers an interrupt
falling_count: Number of times that the falling edge triggers an interrupt

extint.count_reset#

extint.count_reset()

This method clears number of times an interrupt is triggered.

Return Value:

0 - Successful execution

-1 - Failed execution

extint.read_level#

extint.read_level()

This method reads the current pin level.

Return Value:

Pin level.

0 - low level.

1 - high level.