How to Wire and Code SK6812 RGBW LED Strips on Raspberry Pi

Are you curious about how to control SK6812 RGBW LED Strips via Raspberry Pi? This passage will introduce to you the wire connection of the controller and LED strip as well as the progamming process. Hope this blog will help you to make the lighting effect you need.

1. Prepare the Materials

Raspberry Pi board

The Raspberry Pi is a small and affordable single-board that is developed by the Raspberry Pi Foundation (UK). It is originally designed to promote computer science. Becasue of its features like low cost, versatility, it is widely used as a full computer and applied to areas like media center and embedded system.
Popular models of the Raspberry include the Raspberry Pi 4 (most powerful) and the Raspberry Pi Zero (smallest/cheapest). It supports operating systems like Raspberry Pi OS (Debian-based) and third-party OSes.

DC5V LED Driver

  • Input voltage: AC220/230V
  • Output volatage: DC5V
  • Current: maximum 80A
  •  

We also provide waterproof power supply. Please check thsi page: Waterprof Power Supply. 

Arduino 5V LED Power Supply
converter

The 4-level way converter is used as a bridge between the Raspberry Pi and the Power Supply since 5V is too large voltage and Raspberry Pi only accept 3.3V, otherwise the board will be burnt.

DA6 5V RGBW SK6812

Parameters of the LED Strip are as folow:

  • Input voltage: DC5V
  • Color: RGBW
  • LED Qty: 60leds/m
  • Pixel Qty: 60pixels/m

Features: SK6812 LED strip has built-in IC, which means it supports single signal transmission and breakpoint resume function. Color options like white, CCT, RGB, RGBW, RGBWW, RGBCW, RGBNW are available for SK6812. 

Each LED of SK6812 pixel LED strip is cindividually controllable. LED Density of 5V SK6812 LED strip could be 60 LEDs/meter, 120 LEDs/meter and 144 LEDs/meter. If you are interested in other 5V SK6812 LED strip, please check this page: SK6812 LED Strip

2. Raspberry Pi 4B Control Board and SK6812 RGBW LED Strip Wiring Diagram

Raspberry Pi SK6812 wire diagram

Addition:
1. Please use an external powersupply to power the light strip to avoid voltage drop;

2. The Dc3.3/5V interface is the voltage output port of the control board andcannot be connected to the power supply;

3. The control board is powered by a dedicated power supply, and the lightstrip is powered by DC5V, Please note that the GND is shared;

4. The wiring connections for RGB match those for RGBW, but the programs are not interchangeable.

5. The more points, the lower the refresh rate;

6. Since Raspberry Pi 4B’s GPIO operates at 3.3V logic, its pins must undergo level conversion via 74HCT125 or MOSFET prior to light strip signal connection.

3. Raspberry Pi SK6812 LED Connection Diagram

Raspberry Pi SK6812 connection

Please check the connection diagram. Each PIN on the two sides of the converter are corresponding to each other. Make sure that each wire is connected to the right PIN. 

4. Programming

Raspberry Pi programming
				
					# === RGBW led strip setup ===
LED_COUNT = 60        # LED quantity
LED_PIN = 18          # GPIO
LED_FREQ = 800000     # frequency
LED_DMA = 10          # DMA LED_CHANNEL
LED_BRIGHTNESS = 150  # LED_BRIGHTNESS(0-255)
LED_INVERT = False
LED_CHANNEL = 0
STRIP_TYPE = 0x18100800  # SK6812RGBW code

# format LED strip
strip = PixelStrip(
    LED_COUNT, LED_PIN, LED_FREQ, LED_DMA,
    LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL,
    STRIP_TYPE
)
strip.begin()

# === RGBW color generation(revided)===
def wheel(pos):
    """generate logical RGBW value"""
    pos = 255 - pos
    if pos < 85:
        r, g, b = pos * 3, 255 - pos * 3, 0
    elif pos < 170:
        pos -= 85
        r, g, b = 255 - pos * 3, 0, pos * 3
    else:
        pos -= 170
        r, g, b = 0, pos * 3, 255 - pos * 3
    
    # ensure each channel is within 0-255
    r = max(0, min(255, r))
    g = max(0, min(255, g))
    b = max(0, min(255, b))
    w = 50  # fix white intensity
    
    # go back to logical 32bit value
    return (w << 24) | (r << 16) | (g << 8) | b

# === main effect ===
def rgbw_flow(speed_ms=20):
    """RGBW full color flowing effect(revised)"""
    step = 0
    try:
        while True:
            for i in range(LED_COUNT):
                hue = int((i * 256 / LED_COUNT) + step) % 256
                strip.setPixelColor(i, wheel(hue))
            
            strip.show()
            time.sleep(speed_ms / 1000.0)
            step += 1
    except KeyboardInterrupt:
        pass

# === escape safely ===
def signal_handler(sig, frame):
    print("\n close LED...")
    for i in range(LED_COUNT):
        strip.setPixelColor(i, 0)  # use 0 instead of Color(0,0,0,0)
    strip.show()
    sys.exit(0)

signal.signal(signal.SIGINT, signal_handler)

if __name__ == '__main__':
    print("RGBW addressable flowing start (Ctrl+Cstop)")
    rgbw_flow(speed_ms=25)
				
			

5. Video

Below is a video through which you can see the lighting effect after all connection is done.

SK6812 LED Strip could reach multiple color modes because every single LED is controllable. Through the programming of Raspberry Pi, you could create various lighting effects for your projects. 

If you are interested in more details about controlling the SK6812 LED strip with Raspberry Pi, please feel free to contact us.

Feel Free To Contact Us

We will reply your email within 12 hours.

Ask For A Quote