Do you know how to program WS2815 Individually addressable LED strips with Raspberry Pi? This passage will show you everything about it.
1. Something You Need to Prepare
The Raspberry Pi is a single-board computer (SBC) which acts as a microcontroller. Raspberry Pi incorporate key components like the central processing unit (CPU), graphics processing unit (GPU), random-access memory (RAM), USB ports, HDMI interface, SD card reader, operating system and General Purpose Input/Output (GPIO) header onto a minimal footprint. It was used as an educational tool for programming but as time goes by, it has progressed to encompass diverse applications, including smart home integration and deployment as an efficient, low-resource server.
Here is a blog about the difference between the Raspberry Pi and the Arduino: Raspberry Pi vs Arduino.
With stable 5V DC output from either 110V or 220V AC input voltage, this 400W (80A max) power supply operates both the Raspberry Pi and extensive RGB LED strips via their 5V/GND connections and the 5V-to-3V converter. The efficient thermal design of the power supply avoids the overheating and guarantees consistent power delivery for numerous LEDs over long time.
Since the voltage of WS2815 LED Strip is 12V, we need an extra power supply to power the strip separately.
The 4-level way converter mediates between the 5V power source and Raspberry Pi by reducing 5V voltage to the required 3.3V that is compatible with the Raspberry Pi. This converter is used as a critical protection against electrical damage to the Raspberry Pi circuitry.
Specifications:
- IC: WS2815
- LED Qty: 60led/m
- Feature: WS2815 addressable strips use 12V DC chips and this LED strip has enhanced fault tolerance because of backup data lines, which is a critical upgrade from 5V WS2812B technology. This design prevents chain failures during signal disruptions, simplifying large installations. When connected to controllers that send digital commands, each LED’s color and brightness becomes individually programmable, enabling versatile applications in decorative and professional lighting environments.
2. Wire Diagram
Attention:
1. To handle the high current load, add an external power supply for this light strip.
2. Featuring a DC3.3/5V output port, the control board cannot accept power through this interface. Instead, it receives power only from a dedicated PD supply rated at 5.1V-5A.
3. Power the control board with its dedicated supply and the light strip with 12V DC. Ensure their ground connections (GND) are linked.
4. Although RGB and RGBW share identical wiring configurations, their control programs are incompatible.
5. The more points, the lower the refresh rate;6. Note that the GPlO of Raspberry Pi 48 is 3.3V logic level, so the GPlO pin needs to beconverted to a level before connecting to the light strip siqnal pin (74HCT125 Or MOSFETlevel conversion).
3. Connection Diagram
Connect all wires as shown in the diagram and take care to place each PIN in its proper position.
4. Code Program
#!/usr/bin/env python3
from rpi_ws281x import PixelStrip, Color
import time
import math
import signal
import sys
# === LED Strip Configuration ===
LED_COUNT = 100 # Number of LEDs
LED_PIN = 18 # GPIO pin (must support PWM)
LED_FREQ_HZ = 800000 # Signal frequency (Hz)
LED_DMA = 10 # DMA channel
LED_BRIGHTNESS = 150 # Brightness (0-255)
LED_INVERT = False # Signal inversion
LED_CHANNEL = 0 # PWM channel
# Initialize LED strip
strip = PixelStrip(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
strip.begin()
# === Color Generation Functions ===
def wheel(pos):
"""Convert 0-255 value to rainbow color (red→green→blue cycle)"""
pos = 255 - pos # Reverse color direction (optional)
if pos < 85:
return Color(pos * 3, 255 - pos * 3, 0)
elif pos < 170:
pos -= 85
return Color(255 - pos * 3, 0, pos * 3)
else:
pos -= 170
return Color(0, pos * 3, 255 - pos * 3)
def smooth_wheel(pos):
"""Smoother rainbow transition (trigonometric version)"""
r = int(255 * (0.5 + 0.5 * math.sin(pos * 0.0245)))
g = int(255 * (0.5 + 0.5 * math.sin(pos * 0.0245 + 2.094))) # +120°
b = int(255 * (0.5 + 0.5 * math.sin(pos * 0.0245 + 4.188))) # +240°
return Color(r, g, b)
# === Main Effect Function ===
def rainbow_flow(speed_ms=20, smooth=True):
"""Rainbow chasing effect
:param speed_ms: Base animation speed (milliseconds)
:param smooth: Use smooth color transitions
"""
step = 0
try:
while True:
# Dynamic speed control (optional)
dynamic_speed = speed_ms * (0.8 + 0.2 * math.sin(step * 0.01))
for i in range(strip.numPixels()):
# Calculate color hue (creates chasing effect)
hue = int((i * 256 / strip.numPixels()) + step) % 256
color = smooth_wheel(hue) if smooth else wheel(hue)
strip.setPixelColor(i, color)
strip.show()
time.sleep(dynamic_speed / 1000.0)
step += 1
except KeyboardInterrupt:
pass
# === Graceful Exit Handler ===
def signal_handler(sig, frame):
print("\nTurning off LED strip...")
for i in range(strip.numPixels()):
strip.setPixelColor(i, Color(0, 0, 0))
strip.show()
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
# === Main Program ===
if __name__ == '__main__':
print("=== Rainbow Chasing Effect for LED Strip ===")
print("Press Ctrl+C to exit")
# Configuration parameters
USE_SMOOTH_COLOR = True # Enable smooth color transitions
BASE_SPEED_MS = 15 # Base animation speed (milliseconds)
rainbow_flow(speed_ms=BASE_SPEED_MS, smooth=USE_SMOOTH_COLOR)
5. Video
See Raspberry Pi controlling WS2815 LED strips to create multiple lighting effects in this video. Using the right power supply, secure wiring and a compatible code library allows you to easily tailor effects for your strips. For Arduino UNO WS2815 LED strip assistance, feel free to reach out.
If you want to know how to control WS2815 via another microcontroller ESP32, please check this blog: How to Wire and Code WS2815 LED Strips on ESP32.