yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
ESP32 Core Board📖
1. ESP32 Introduction
  • 1. ESP32S3 Overview
  • 2. Environment Setup Introduction
  • 3. Dev Board Introduction
2. ESP-IDF Development Tutorial
1. Before Development
  • 1. Environment Setup (Windows)
  • 2. Environment Setup (Linux)
  • 3. Build and Flash
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. ESP_TIMER
  • 5. GPTIMER
  • 6. Watchdog Timer
  • 7. DMA
  • 8. ADC
  • 9. PWM Breathing LED
  • 10. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication Experiment
  • 2. I2C_OLED Display Experiment
  • 3. SPI Bus Communication Experiment
  • 4. PSRAM External Memory Experiment
  • 5. Flash Read and Write Experiment
  • 6. USB Emulated Mass Storage Experiment
4. FreeRTOS operating system
  • 1.FreeRTOS Core Concepts Theory
  • 2.Task Creation and Management
  • 3.Queue
  • 4.Binary Semaphore
  • 5.Mutex
  • 6.Event Groups
  • 7.Software Timer
  • 8.Task Scheduler
  • 9.Low Power Mode
  • 10.Deadlock
  • 11.Priority Inversion
5. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Client Experiment
  • 5. UDP Server Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. Socket Programming Basics
  • 9. HTTP Client Experiment
  • 10. HTTP Server Experiment
  • 11. MQTT IoT Communication Protocol
  • 12. WIFI OTA Upgrade
  • 13. Bluetooth Fundamentals
  • 14. Bluetooth Slave Mode
  • 15. Bluetooth Master Mode
6. Audio Applications
  • 1.I2S Microphone Recording and U-Disk Playback
  • 2.I2S Audio Playback Experiment
  • 3.Repeater Experiment
7. Xiaozhi AI Voice
  • 1. Burn Xiaozhi Firmware
  • 2. Network and Configuration
  • 3. AI Agent Settings
  • 4. Program Analysis
  • 5. Free Chat
3. Arduino Development Course
1. Before Development
  • 1. Environment Setup
  • 2. Build and Flash
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. ESP_TIMER
  • 5. GPTIMER
  • 6. Watchdog Timer
  • 7. ADC
  • 8. PWM Breathing LED
  • 9. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication
  • 2. I2C OLED Display
  • 3. SPI Bus Communication
  • 4. Flash Read and Write
  • 5. USB Emulated Mass Storage
4. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Server Experiment
  • 5. UDP Client Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. HTTP Client Experiment
  • 9. HTTP Server Experiment
  • 10. MQTT IoT Communication Protocol
  • 11. WIFI OTA Upgrade
  • 12. Bluetooth Fundamentals
  • 13. Bluetooth Slave Mode
  • 14. Bluetooth Master Mode
5. Audio Applications
  • 1.I2S Microphone Recording and U-Disk Playback
  • 2.I2S Audio Playback Experiment
  • 3.Repeater Experiment
4. MicroPython Development Course
1. Before Development
  • 1. Environment Setup
  • 2. Build and Flash
  • 3. Thonny IDE
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. TIMER_IT
  • 5. Watchdog Timer
  • 6. ADC
  • 7. PWM Breathing LED
  • 8. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication Experiment
  • 2. I2C_OLED Display Experiment
  • 3. SPI Bus Communication Experiment
  • 4. Flash Read and Write Experiment
  • 5. Print Storage
4. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Client Experiment
  • 5. UDP Server Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. HTTP Client Experiment
  • 9. HTTP Server Experiment
  • 10. MQTT
  • 11. Bluetooth Fundamentals
  • 12. Bluetooth Slave Mode
  • 13. Bluetooth Master Mode
5. Audio Applications
  • 1. I2S Audio Playback Experiment
  • 2. Repeater Experiment
Download
  • Code
  • Hardware_Info
  • 3D_Model_File
  • Software_Tools
  • VMware
  • VM_File
Download ZIP

Welcome to ESP32 Core Board repository

1. LED Control

LED Control

LED Control


LED Control1. LED Lighting Overview2. Core Concepts2.1 Common-Anode Connection2.2 Core API — machine.Pin2.3 time.sleep() — Blocking Delay3. Hardware Dependencies3.1 ESP32-S3 GPIO Hardware Features4. Project Architecture and Flow5. Source Code Details5.1 Import Modules5.2 Initialize GPIO5.3 Main Loop — Blink Logic6. Operation Procedure6.1 Flashing and Running6.2 Normal Phenomenon6.3 Verification Methods7. Common Problems


1. LED Lighting Overview

GPIO (General Purpose Input/Output) is the most basic peripheral interface of an MCU. Through software configuration, the chip pins can be set to input mode (reading external signals) or output mode (driving external circuits).

This experiment makes two onboard LEDs blink synchronously at 1Hz, demonstrating the basic usage of the MicroPython machine.Pin module — only 6 lines of core code are needed to complete GPIO output control.

Typical application scenarios:

Application TypeExample
Digital outputLED blinking, relay control, buzzer driving
Digital inputButton detection, switch status reading, sensor digital signals
Bidirectional I/OI2C bus (SDA), single-wire bus protocol
Interrupt inputExternal event triggering
Analog inputADC sampling
Multiplexed functionUART / SPI / I2C / PWM peripheral signals

2. Core Concepts

2.1 Common-Anode Connection

The onboard LEDs use a common-anode connection: the anode is fixed to 3.3V, and the cathode goes to the GPIO through a current-limiting resistor.

VDD(3.3V) → LED anode → LED cathode → current-limiting resistor → GPIO pin
GPIO OutputLED StatePrinciple
0 (Low)OnGPIO internally pulled to GND, current flows through the LED
1 (High)OffGPIO is at the same potential as VDD, no current

led.value(0) = on, which is the opposite of the intuitive "1 = on". Refer to the table above to understand.

2.2 Core API — machine.Pin

MicroPython encapsulates all GPIO operations in the machine.Pin class. Initializing a Pin object completes the pin configuration.

Constructor:

xxxxxxxxxx
from machine import Pin
led = Pin(pin_id, mode, pull=None)
ParameterDescriptionPossible Values
pin_idGPIO numberESP32-S3: 0~48
modePin modePin.OUT output / Pin.IN input / Pin.OPEN_DRAIN open-drain
pullPull-up/down resistorNone (default) / Pin.PULL_UP / Pin.PULL_DOWN

Common methods:

MethodDescriptionExample
value(n)Write/read level. With argument = write, without = readled.value(0) outputs low level
on() / off()Convenience methods. on() = high level, off() = low levelled.on()
toggle()Toggle the output levelled.toggle()

2.3 time.sleep() — Blocking Delay

xxxxxxxxxx
import time
time.sleep(0.5)      # second-level delay, blocks for 0.5s
time.sleep_ms(500)   # millisecond-level delay, blocks for 500ms
time.sleep_us(100)   # microsecond-level delay, blocks for 100μs

Under the hood it is FreeRTOS vTaskDelay(): the task enters the Blocked state and yields the CPU, then wakes up automatically when the time expires. Do not busy-wait with a for loop — it will starve the IDLE task and trigger the watchdog.


3. Hardware Dependencies

GPIOPeripheralModeDescription
43LED0Pin.OUTOnboard LED, common-anode, 0=on
44LED1Pin.OUTSame as above

Both LEDs are onboard; no external components are required.

3.1 ESP32-S3 GPIO Hardware Features

FeatureParameter
Number of available GPIOs~45 (depends on package; some are shared with Flash/PSRAM)
Supply voltage3.3V (not 5V-tolerant)
Maximum output current~40mA/pin (for long-term stable driving, ≤10mA is recommended)
GPIO matrixOn-chip programmable signal routing network; peripheral signals can be mapped to almost any GPIO
RTC GPIOGPIO0~21 can hold level and wake up during Deep Sleep
Interrupt capabilityEvery GPIO can be configured for rising edge / falling edge / both edges / low level / high level interrupts

4. Project Architecture and Flow

xxxxxxxxxx
Script execution (single-file .py)
  │
  ├─ from machine import Pin          // import Pin module
  ├─ import time                      // import delay module
  ├─ led1 = Pin(43, Pin.OUT)          // GPIO43 push-pull output
  ├─ led2 = Pin(44, Pin.OUT)          // GPIO44 push-pull output
  │
  └─ while True:                      // infinite loop
       ├─ led1.value(1), led2.value(1) // off (common-anode: HIGH=off)
       ├─ time.sleep(0.5)              // hold 500ms
       ├─ led1.value(0), led2.value(0) // on (common-anode: LOW=on)
       └─ time.sleep(0.5)              // hold 500ms → back to start

5. Source Code Details

Full source code: 5.Source Code → MicroPython → 1.Basic Peripherals → 1.GPIO_LED → 1.GPIO_LED.py

5.1 Import Modules

xxxxxxxxxx
from machine import Pin  # Pin class: GPIO control
import time              # delay functions
  • machine is the most core hardware abstraction layer module in MicroPython; the Pin class encapsulates all GPIO operations

  • time provides blocking delay functions, which call FreeRTOS vTaskDelay() under the hood

5.2 Initialize GPIO

xxxxxxxxxx
led1 = Pin(43, Pin.OUT)  # GPIO43 push-pull output, onboard LED0
led2 = Pin(44, Pin.OUT)  # GPIO44 push-pull output, onboard LED1

Pin(pin, Pin.OUT) calls gpio_set_direction() under the hood, setting the GPIO to push-pull output mode with a drive capability of about 10mA — more than enough for an LED.

Any GPIO on the ESP32-S3 can be configured as output through the IO MUX, unlike some MCUs that have dedicated "output pins" restrictions.

5.3 Main Loop — Blink Logic

xxxxxxxxxx
while True:
    led1.value(1)    # turn off (common-anode: HIGH=off)
    led2.value(1)    # turn off
    time.sleep(0.5)  # delay 500ms
    led1.value(0)    # turn on (common-anode: LOW=on)
    led2.value(0)    # turn on
    time.sleep(0.5)  # delay 500ms

Execution timing:

Thonny IDE
Button Detection

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文