GPIO Digital Output
GPIO Digital Output
Overview
GPIO digital output is used to control relays, LEDs, buzzers, DC motors, and other actuators. Outputs high/low levels to drive external loads.
Supported Peripheral Types
| Type | type Value | Description |
|---|---|---|
| GPIO_DIGITAL_OUTPUT | 12 | Standard digital output |
Pin Description
- ESP32: GPIO 0-5, 12-33 (some pins have limitations)
- ESP32-C3: GPIO 0-10, 18-21
- ESP32-S3: GPIO 0-21, 35-48
Note: GPIO 6-11 (ESP32) are reserved for internal Flash use and cannot be configured as outputs.
Typical Applications
| Application | Wiring | Description |
|---|---|---|
| LED | GPIO → Resistor(220Ω) → LED → GND | High level to light up |
| Relay | GPIO → Relay Module IN | Most modules trigger on low level |
| Buzzer | GPIO → Active Buzzer+ | High level to sound |
| DC Motor | GPIO → Motor Driver Module | Requires external driver circuit |
Digital output directly drives physical loads. When configuring, keep the peripheral disabled first, confirm the trigger level of the relay or motor driver module, then verify with individual actions.
Configuration
Method 1: Web Interface Configuration (Recommended)
Different peripheral types will display different parameters. Before saving, verify peripheral ID, type, pins, and enable status.
Step 1: Navigate to Peripheral Management Page
- Open a browser and navigate to the ESP32 IP address
- After logging in, click Peripheral Configuration in the left menu
Step 2: Add GPIO Digital Output Peripheral
Click the Add Peripheral button
Fill in the configuration:
Field Value Description Peripheral ID led1orrelay1Unique identifier Name Status LEDorFan RelayDisplay name Peripheral Type GPIO Digital Output (type: 12) Standard digital output Pin Configuration 2or15Fill according to actual wiring Initial State 00=Low level, 1=High level Click Save
Step 3: Verify Configuration
- Find the newly added peripheral in the peripheral list
- Click the Enable toggle
- Use the control panel to test output state
Method 2: JSON Configuration File Import
Add the following configuration to the peripherals array in data/config/peripherals.json:
LED Output
{
"id": "led1",
"name": "Status LED",
"type": 12,
"enabled": false,
"pins": [2],
"params": {
"initialState": 0,
"pwmChannel": 0,
"pwmFrequency": 1000,
"pwmResolution": 8,
"defaultDuty": 0
}
}Relay Output (Low Level Trigger)
{
"id": "relay1",
"name": "Relay-Fan",
"type": 12,
"enabled": false,
"pins": [15],
"params": {
"initialState": 0,
"pwmChannel": 0,
"pwmFrequency": 1000,
"pwmResolution": 8,
"defaultDuty": 0
}
}Buzzer
{
"id": "buzzer",
"name": "Alarm Buzzer",
"type": 12,
"enabled": false,
"pins": [4],
"params": {
"initialState": 0,
"pwmChannel": 0,
"pwmFrequency": 1000,
"pwmResolution": 8,
"defaultDuty": 0
}
}Peripheral Execution Integration
GPIO digital output can serve as the action target of peripheral execution rules:
| Action Type | actionType | Description |
|---|---|---|
| ACTION_HIGH | 0 | Output high level |
| ACTION_LOW | 1 | Output low level |
| ACTION_HIGH_INVERTED | 13 | Logic high (physical low level) |
| ACTION_LOW_INVERTED | 14 | Logic low (physical high level) |
| ACTION_BLINK | 2 | Blink (actionValue=interval ms) |
| ACTION_BREATHE | 3 | Breathing light effect |
Web Interface Configuration Steps
Step 1: Create Execution Rule
- Switch to the Peripheral Execution Management tab
- Click the Add Rule button
- Fill in basic configuration and configure triggers
Step 2: Add GPIO Action
Click the Add Action button
Fill in action configuration:
Field Value Description Action Type Select High Level or Low Level Choose based on requirements Target Peripheral Select relay1GPIO output peripheral Execution Delay 0Execute immediately Click Save
💡 Tip: For low-level trigger relay modules, use "Logic High (Inverted)" or "Logic Low (Inverted)"
JSON Configuration Example
{
"targetPeriphId": "relay1",
"actionType": 0,
"actionValue": "",
"useReceivedValue": false,
"syncDelayMs": 0,
"execMode": 0
}Notes
- Initial State:
initialStateof 0 means default low level on power-up, 1 means high level - Low-Level Trigger Relay: Use
ACTION_HIGH_INVERTED(13)/ACTION_LOW_INVERTED(14)for logic inversion - Current Limit: ESP32 single pin maximum output current is 40mA; external driver circuit needed for high-power loads
- PWM Parameters: Even for digital output type, PWM parameters in params must be retained (framework compatibility design), but they do not affect digital output behavior
- Platform Downlink Control: Platform can control output state via MQTT:
[{"id":"relay1","value":"1"}]
