Example 9: External Interrupt
Example 9: External Interrupt
Experiment Overview
Detect external signal changes (button press, sensor trigger, etc.) via GPIO interrupts, immediately triggering events when rising edge, falling edge or level change is detected. Compared to polling, interrupts respond faster and do not consume CPU resources.
Hardware Wiring
| Board Label | GPIO Pin | Connected Device |
|---|---|---|
| KEY1 | GPIO14 | Button/Sensor (falling edge trigger) |
Any interrupt-capable GPIO pin can be used, almost all ESP32 GPIOs support interrupts.
JSON Configuration Example
{
"peripherals": [
{
"id": "int_falling",
"name": "Falling Edge Interrupt",
"type": 19,
"enabled": false,
"pins": [14],
"params": {}
},
{
"id": "int_rising",
"name": "Rising Edge Interrupt",
"type": 18,
"enabled": false,
"pins": [27],
"params": {}
},
{
"id": "int_change",
"name": "Level Change Interrupt",
"type": 20,
"enabled": false,
"pins": [26],
"params": {}
}
]
}Peripheral Execution Linkage
Scenario: Interrupt Triggered Alarm (Event Trigger)
Function: When falling edge interrupt is detected (button press), buzzer sounds for 0.5 seconds
Web Interface Configuration Steps
Step 1: Ensure buzzer peripheral is configured
- Peripheral ID:
buzzer_gpio - Type: GPIO Output
Step 2: Create Rule
- Click left menu Peripheral Configuration → Switch to Peripheral Execution Management tab
- Click New Rule button
- Fill in basic configuration:
- Rule Name:
Interrupt Alarm - Report Data: ✅ Enable
- Enabled: ✅ Enable
- Rule Name:
Step 3: Configure Trigger (Event Trigger)
Click Add Trigger button
Fill in trigger configuration:
Field Value Description Trigger Type Select Event Trigger Respond to system events Event Type 100GPIO interrupt event Event Source int_fallingFalling edge interrupt peripheral ID
Step 4: Configure Actions (3 actions needed)
Action 1: Buzzer ON
- Click Add Action button
- Fill in:
- Action Type: Select HIGH Level
- Target Peripheral: Select
buzzer_gpio
Action 2: Delay 500ms
- Click Add Action button again
- Fill in:
- Action Type: Select Delay
- Action Params:
500(milliseconds)
Action 3: Buzzer OFF
Click Add Action button a third time
Fill in:
- Action Type: Select LOW Level
- Target Peripheral: Select
buzzer_gpio
Click Save button
Execution Flow:
Button pressed (falling edge)
↓
Trigger interrupt event
↓
Buzzer ON (HIGH)
↓
Delay 500ms
↓
Buzzer OFF (LOW)Interrupt Type Reference
| Interrupt Type | Trigger Condition | Use Case | Type Value |
|---|---|---|---|
| Rising Edge | LOW→HIGH change | Button release, sensor trigger | 18 |
| Falling Edge | HIGH→LOW change | Button press, sensor trigger | 19 |
| Level Change | Any level change | Monitor signal changes | 20 |
Notes
- Debouncing: Mechanical buttons produce bounce, FastBee has built-in 50ms debounce protection
- Interrupt Safety: Time-consuming operations cannot be executed in interrupt callbacks, FastBee uses event queue for async processing
- Pin Restrictions: GPIO6-11 (SPI Flash) cannot be used for interrupts
- Level Requirement: ESP32 GPIO is 3.3V level, 5V signals need voltage division
- Wake-up Feature: Some pins (RTC GPIO) support deep sleep interrupt wake-up
