Skip to content

Example 14: RGB NeoPixel (WS2812B) ​

Experiment Overview ​

Drive WS2812B (NeoPixel) RGB LEDs via single-wire protocol for full-color control. FastBee has a built-in NEO_PIXEL peripheral type (type: 45), supporting color, brightness and LED count settings.

Hardware Wiring ​

Board LabelGPIO PinConnected Device
DATAGPIO4WS2812B data pin (DIN)

WS2812B power supply recommends 5V, data line can connect directly to 3.3V GPIO (most WS2812B are compatible).

JSON Configuration Example ​

json
{
  "peripherals": [
    {
      "id": "ws2812b",
      "name": "WS2812B RGB LED",
      "type": 45,
      "enabled": false,
      "pins": [4],
      "params": {
        "count": 8,
        "brightness": 64
      }
    }
  ]
}

Parameter Description ​

ParameterDescriptionRange
countNumber of LEDs1~255
brightnessGlobal brightness0~255

Peripheral Execution Linkage ​

Scenario 1: Set Single LED Color (Platform Trigger) ​

Function: Set LED #0 to red via cloud platform command

Web Interface Configuration Steps ​

Step 1: Create Rule

  1. Click Peripheral Execution in the left menu
  2. Click New Rule button
  3. Fill in basic configuration:
    • Rule Name: Set RGB Color
    • Report Data: ✅ Enable
    • Enabled: ✅ Enable

Step 2: Configure Trigger

  1. Click Add Trigger button

  2. Fill in trigger configuration:

    FieldValueDescription
    Trigger TypeSelect Platform TriggerReceive cloud platform commands
    OperatorSelect Match PatternMatch command
    Comparison Value{"cmd":"color"}Color control command

Step 3: Configure Action

  1. Click Add Action button

  2. Fill in:

    • Action Type: Select Set RGB
    • Target Peripheral: Select ws2812b
    • LED Index: 0 (LED #0)
    • R Value: 255
    • G Value: 0
    • B Value: 0
  3. Click Save button


Scenario 2: Set All to Same Color (Platform Trigger) ​

Function: Set all LEDs to green via cloud platform command

Web Interface Configuration Steps ​

  1. Create rule, name: All Green
  2. Trigger configuration:
    • Trigger Type: Select Platform Trigger
    • Operator: Select Match Pattern
    • Comparison Value: {"cmd":"all_green"}
  3. Action configuration:
    • Action Type: Select Fill RGB
    • Target Peripheral: Select ws2812b
    • R Value: 0
    • G Value: 255
    • B Value: 0
  4. Click Save

Common RGB Color Values ​

ColorRGBDescription
Red25500Pure red
Green02550Pure green
Blue00255Pure blue
White255255255White
Yellow2552550Yellow
Purple2550255Purple
Cyan0255255Cyan

Notes ​

  1. Power: Each WS2812B draws ~60mA at full brightness, multiple LEDs need independent 5V power
  2. Level: Some WS2812B need 5V logic level, add level shifting or 330Ω resistor in series on DIN
  3. Timing Sensitive: WS2812B has strict timing requirements, recommend using RMT peripheral (ESP32 uses it by default)
  4. Refresh Rate: More LEDs = slower refresh, 100 LEDs ~3ms
  5. Data Order: Color order may be GRB instead of RGB, depending on model

FastBee | fastbee.cn