Thursday, June 15, 2017

1. Introduction
- When interrupt occurs, micro-controller will stop current task immediately to process the event that cause the interrupt. If we do not use interrupt, we have to use loop control statement to always listen on events that we are interested in. In case our program has many tasks to do, we may miss the interested event because micro-controller is busy to process another task.
- The demo for this tutorial is quite simple. We use a button to connect to an interrupt pin. Every time the user press the button, it will cause an interrupt on ESP32 and ESP32 process this interrupt by toggle a LED.2. Hardware

Figure: ESP32 attach external interrupt

Here we set interrupt pin as INPUT_PULLUP, it means there is a resister connect the input pin to Vcc so our circuit is more simple.

Figure: ESP32 connect to button (input_pullup) and LED

Connections:

[ESP32 GIO12 - BUTTON - GND]

[ESP32 GIO14 - LED - GND]3. Software
- In order to use interrupt, we will use the 2 functions: attachInterrupt(digitalPinToInterrupt(pin), ISR, mode)
+ pin: is the pin to attach interrupt.
+ ISR: the function to be invoked when interrupt occurs.
+ mode: which event trigger interrupt (CHANGE: trigger when the pin change value, RISING: when the pin go from LOW to HIGH, ...)
- Create an Arduino project with code: