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

8. RGB LED Effects

RGB LED Effects


RGB LED Effects1. RGB Colorful Light Overview2. Core Concepts2.1 WS2812 Communication Protocol2.2 WS2812 Color Format — GRB2.3 Seven-Color Rainbow List2.4 Core API — neopixel3. Hardware Dependencies4. Project Architecture and Flow5. Source Code Details5.1 Parameter Configuration and Color Definition5.2 Initialization and Cycle Switching6. Operation Procedure6.1 Flashing and Running6.2 Normal Phenomenon6.3 Verification Methods7. Common Problems


1. RGB Colorful Light Overview

WS2812 (also known as NeoPixel) is a single-wire addressable RGB LED chip. Each LED has a built-in control IC, and only one data wire is needed to cascade and control hundreds of LEDs. This experiment drives the single onboard WS2812 (GPIO48), cycling through 7 rainbow colors, switching once per second while printing the current color name via serial.

Typical application scenarios:

Application TypeExample
Ambient lightingMusic-reactive lights, gaming ambient lights
Status indicationColor coding (red=fault, green=normal, blue=connecting)
DisplaysLED matrix, digital tubes
WearablesLED clothing, glowing accessories

2. Core Concepts

2.1 WS2812 Communication Protocol

The WS2812 uses a single-wire return-to-zero code: there is only one data wire, and different pulse widths represent 0 and 1.

0 code: ██░░              0.4μs high + 0.85μs low
1 code: ████░░            0.8μs high + 0.45μs low
RESET: ░░░░ > 50μs        low > 50μs = latch signal

Each LED requires 24 bits of data (8 bits each for G-R-B); cascading N LEDs requires 24×N bits. The RESET signal latches the data in the shift register to the output.

2.2 WS2812 Color Format — GRB

The native color order of the WS2812 is GRB (Green-Red-Blue), which differs from the common RGB order:

xxxxxxxxxx
#                  G    R    B
RAINBOW = [
    (150, 0,   0),   # red:   G=0,   R=150, B=0
    (0,   150, 0),   # green: G=150, R=0,   B=0
    (0,   0,   150), # blue:  G=0,   R=0,   B=150
]

(150, 0, 0) in GRB format = G=150, R=0, B=0 → dim green. To write red, use (0, 150, 0): G=0, R=150, B=0.

2.3 Seven-Color Rainbow List

This experiment predefines 7 rainbow colors and cycles through them by array index:

IndexColorGRB ValueVisual Effect
0Red(150, 0, 0)Red
1Orange(150, 60, 0)Orange (red+green)
2Yellow(150, 150, 0)Yellow (red+green equal)
3Green(0, 150, 0)Green
4Cyan(0, 150, 150)Cyan (green+blue)
5Blue(0, 0, 150)Blue
6Purple(120, 0, 150)Purple (red+blue)

2.4 Core API — neopixel

​x
from machine import Pin
from neopixel import NeoPixel

np = NeoPixel(Pin(48), 1)     # GPIO48, 1 LED
np[0] = (150, 0, 0)            # set LED 0 to red (GRB)
np.write()                     # send the color data to the LED

np[0] = (g, r, b) only modifies the buffer in memory; you must call np.write() to actually send it to the LED.


3. Hardware Dependencies

GPIOPeripheralModeDescription
48WS2812Pin.OUT (NeoPixel)Onboard single RGB LED, data input pin

The WS2812 on this board is onboard; no external components are required.


4. Project Architecture and Flow

xxxxxxxxxx
Script execution (single-file .py)
  │
  ├─ Config: LED_PIN=48, INTERVAL=1000ms
  ├─ RAINBOW = [7 GRB colors]                    // predefined color array
  ├─ np = NeoPixel(Pin(48), 1)                   // 1 WS2812
  ├─ color_index = 0                             // color index
  │
  └─ while True:                                 // cycle switching
       ├─ print("Current color: ...")             // print the current color name
       ├─ np[0] = RAINBOW[color_index]           // set the color
       ├─ np.write()                              // send to the LED
       ├─ color_index = (index + 1) % 7          // cycle the index
       └─ sleep_ms(1000)                          // 1s interval

5. Source Code Details

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

5.1 Parameter Configuration and Color Definition

xxxxxxxxxx
from machine import Pin        # Pin class
from neopixel import NeoPixel  # WS2812 driver
import time                    # delay

# Configuration parameters
LED_PIN  = 48                # LED data pin
LED_NUM  = 1                 # number of LEDs
INTERVAL = 1000              # color switch interval (ms)

# Seven rainbow colors (GRB order, WS2812 native format)
RAINBOW = [
    (150, 0,   0),            # Red     (R=150, G=0,   B=0)
    (150, 60,  0),            # Orange  (R=150, G=60,  B=0)
    (150, 150, 0),            # Yellow  (R=150, G=150, B=0)
    (0,   150, 0),            # Green   (R=0,   G=150, B=0)
    (0,   150, 150),          # Cyan    (R=0,   G=150, B=150)
    (0,   0,   150),          # Blue    (R=0,   G=0,   B=150)
    (120, 0,   150),          # Purple  (R=120, G=0,   B=150)
]

COLOR_NAMES = ["Red", "Orange", "Yellow", "Green", "Cyan", "Blue", "Purple"]

5.2 Initialization and Cycle Switching

xxxxxxxxxx
# Init NeoPixel (WS2812, GPIO48)
np = NeoPixel(Pin(LED_PIN), LED_NUM)

color_index = 0

while True:
    print("Current color: %s" % COLOR_NAMES[color_index])  # print color

    np[0] = RAINBOW[color_index]  # write to buffer
    np.write()                    # send to LED

    color_index = (color_index + 1) % len(RAINBOW)  # cycle index
    time.sleep_ms(INTERVAL)

(color_index + 1) % len(RAINBOW) wraps the index back to 0: 6→7→0→1... .


6. Operation Procedure

6.1 Flashing and Running

Thonny IDE steps: See the 1. Before Development → 3.Thonny IDE chapter.

6.2 Normal Phenomenon

  • The RGB LED switches to one color per second: red→orange→yellow→green→cyan→blue→purple→red, repeating

    xxxxxxxxxx
    Current color: Red
    Current color: Orange
    Current color: Yellow
    Current color: Green
    Current color: Cyan
    Current color: Blue
    Current color: Purple
    Current color: Red       ← cycle
    ...

    Serial output

  • The Shell prints the current color name every second

6.3 Verification Methods

OperationExpected Result
Power upLED starts with red, switches every second
Change INTERVAL=1000 to INTERVAL=200Switching speed increases 5 times
Comment out np.write()LED color does not update
Modify a color value in the RAINBOW arrayThe corresponding color changes
Swap G and R in the RAINBOW arrayColors are clearly wrong (GRB vs RGB)

7. Common Problems

SymptomCauseSolution
ImportError: no module named 'neopixel'The firmware does not include the neopixel moduleFlash a MicroPython firmware that includes neopixel
LED does not light upnp.write() not calledConfirm np.write() is called after every color assignment
Color does not match the name (e.g., red becomes green)Data order uses RGB instead of GRBSwap the first and second values in the tuple
Uneven color brightnessThe brightness values of the source colors are not calibratedAdjust the channel values in the RAINBOW array
Serial prints fine but the LED stays whitePowered on before initialization; WS2812 defaults to randomWrite black (0,0,0) once before starting the loop
PWM Breathing LED
Serial UART Communication Experiment

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

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文