An ESP32 project implementing an interactive UART command-line interface with LED blinking control and I2S audio tone generation.
blink on- Enable LED blinkingblink off- Disable LED blinkingblink freq <ms>- Set blink period in milliseconds
i2s init <channel> <sample_rate> <bit_width> <stereo/mono>- Initialize I2S peripheral- Example:
i2s init 0 44100 16 stereo
- Example:
i2s tone <freq>- Play a tone at specified frequency (100 Hz to 15000 Hz)i2s start- Start I2S transmissioni2s stop- Stop I2S transmission
clock- Display system clock frequenciesreset- Restart the ESP32i2c detect- Scan I2C bus for deviceshelp- Display all available commands
- ESP32 development board
- LED on GPIO2 (built-in on most ESP32 dev boards)
- I2S DAC or amplifier on:
- BCLK: GPIO26
- LRCLK/WS: GPIO25
- DOUT: GPIO22
Developed using ESP-IDF v6.0
-
Set up ESP-IDF environment:
source ~/.espressif/v6.0/esp-idf/export.sh
-
Build the project:
cd blinky idf.py build -
Flash to ESP32 (replace PORT with your serial port):
idf.py -p /dev/cu.SLAB_USBtoUART flash
Connect to the ESP32 via serial terminal at 115200 baud:
screen /dev/cu.SLAB_USBtoUART 115200Type commands and press Enter. Start with help to see available commands.
opencode/
├── blinky/
│ ├── main/
│ │ ├── blinky.c # Main application with UART terminal and I2S
│ │ └── CMakeLists.txt # Component configuration
│ ├── CMakeLists.txt # Project configuration
│ └── sdkconfig.defaults # Default SDK configuration
└── README.md
=== Blinky UART Terminal ===
Type 'help' for commands
> help
Commands:
blink on - Enable blinking
blink off - Disable blinking
blink freq <ms>- Set blink period in ms
i2s init <ch> <sr> <w> <s/m> - Init I2S
i2s tone <freq>- Play tone 100-15000Hz
i2s start - Start I2S
i2s stop - Stop I2S
i2c detect - Scan I2C bus
clock - Show system clocks
reset - Restart ESP32
help - Show this help
> blink off
Blinking disabled
> blink freq 500
Blink frequency set
> blink on
Blinking enabled
> i2s init 0 44100 16 stereo
I2S initialized
> i2s tone 440
Tone playing
> i2s tone 880
Tone playing
> i2s tone 1760
Tone playing
> i2s stop
I2S stopped
> clock
System Clocks:
CPU: 240000000 Hz
> i2c detect
I2C Scan:
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- --
> reset
Resetting ESP32...
=== Blinky UART Terminal ===
Type 'help' for commands
> invalid_command
Unknown command. Type 'help'
> help
Commands:
blink on - Enable blinking
blink off - Disable blinking
blink freq <ms>- Set blink period in ms
i2s init <ch> <sr> <w> <s/m> - Init I2S
i2s tone <freq>- Play tone 100-15000Hz
i2s start - Start I2S
i2s stop - Stop I2S
help - Show this help
>