Example Code for Arduino - Interrupt (Basic Tutorial)

The interrupt of ESP32-S3 can be freely allocated.

Hardware Preparation

FireBeetle 2 ESP32-S3 AI Board with OV2640 Camera x 1

Software Preparation

When you use the ESP32 for the first time, you need to know the following steps:

  1. Add the ESP32 development board in Arduino IDE (How to add the ESP32 board to Arduino IDE?)

  2. Select the development board and serial port

  3. Burn the program

Basic APIs

  • pinMode(GPIO,INPUT_PULLUP);

    • Description: external interrupt pin definition

    • Parameters:

      • GPIO: the pin that ESP32 S3 is going to use as an interrupt

      • INPUT_PULLINGUP: set as pull-up mode

  • attachInterrupt(digitalPinToInterrupt(pin), ISR, mode)

    • Description: External interrupts

    • Parameters:

      • pin: the Arduino pin number.

      • ISR: the ISR to call when the interrupt occurs; this function must accept no parameters and return nothing. This function is sometimes called an an interrupt handler.

      • mode: defines when the interrupt should be triggered. Three constants are predefined as valid values.

        • CHANGE: trigger the interrupt pin when the pin level changes
        • RISING: trigger the interrupt pin when the pin level changes from low to high
        • FALLING: Trigger the interrupt pin when the pin level changes from high to low
  • detachInterrupt(digitalPinToInterrupt(pin))

    • Description: disable the given interrupt.

    • Parameters:

      • pin: the interrupt pin to be disabled
  • Interrupts ()

    • Description: Re-enables interrupts (after they’ve been disabled by nointerrupts(). Interrupts allow certain important tasks to happen in the background and are enabled by default. Some functions will not work while interrupts are disabled, and incoming communication may be ignored. Interrupts can slightly disrupt the timing of code, however, and may be disabled for particularly critical sections of code.
  • noInterrupts ()

    • Description: Disables interrupts (you can re-enable them with interrupts()). Interrupts allow certain important tasks to happen in the background and are enabled by default. Some functions will not work while interrupts are disabled, and incoming communication may be ignored. Interrupts can slightly disrupt the timing of code, however, and may be disabled for particularly critical sections of code.

Was this article helpful?

TOP