• First Steps
  • General
  • Projects
Facebook Twitter YouTube
Tutorials for Raspberry Pi Tutorials for Raspberry Pi
  • Hardware & GPIO
  • Sensors & Components
  • Scale
  • Cases
  • Fingerprint
  • Gas Sensor
  • Heartbeat
  • German
  • French
Tutorials for Raspberry Pi Tutorials for Raspberry Pi
Home»Hardware & GPIO»How to connect and control a Raspberry Pi WS2801 RGB LED Strip

How to connect and control a Raspberry Pi WS2801 RGB LED Strip

Facebook Twitter LinkedIn Tumblr Email Reddit
Raspberry Pi WS2801B RGB LED Streifen anschließen und steuern
Share
Facebook Twitter LinkedIn Email Tumblr Reddit Telegram WhatsApp

One of the many Raspberry Pi projects is the lighting of rooms or objects. LED strips are particularly suitable for this purpose, because many individual LEDs are aligned and each individual LED can display all RGB colors. Thus, some projects such as room lighting, Ambilight or e.g. a Christmas tree lighting can be realized. The effects of the colorful lights are impressive.

This article shows the general usage of the WS2801B on the Raspberry Pi. In doing so, we create an example in which LEDs of the strip are set (rainbow colors) and the brightness is dimmed. In the video at the end of the tutorial you can see the whole thing in action.

 

Equipment

The RGB LED strips require an input voltage of 5V. The most favorable variant with 32 LEDs per meter has a distance between the LEDs of only 2.5 cm:

  • WS2801B LED strip with 32 LEDs per meter (US / UK)

There are also versions available that are dust and water-resistant (IP67). Each of the individual LEDs has a current consumption of about 60 mA. At one meter this is almost 2A. This is quite more than the GPIOs of Raspberry Pi can deliver. We therefore need an external current source that supplies power to the RGB stripe. Depending on how long your strip is, the maximum current must be higher. The power supply should therefore be able to supply 10A at 5 meters.
You have the choice between two possibilities:

DC Steckeradapter
With a plug adapter and power supply, the plus and minus poles can be easily connected to the LED strips.
  • For beginners: Power adapter (US / UK) + plug-in connector (US / UK) (c.f. picture on the right)
  • For experienced: Switching power supply (US / UK) + power cord (US / UK)

The difference is that a power cable has to be disconnected and then connected to the switching power supply. Since working with high voltage is dangerous, this is not recommended for beginners. For a power supply (similar to the laptop chargers) you only need an additional Power Jack adapter, so that you can detach the two voltage poles.

Last but not least jumper cables and a breadboard (US | UK) are required.

 

WS2801B vs. WS2812B

The WS2812 LED strips are often found on the Internet, which are also somewhat cheaper than the WS2801 models. However, these are not all too good for the Raspberry Pi, since the onboard audio output of the Raspberry Pi can not be used anymore. However, I will write another tutorialon how to use the WS2812 LED strips.

WS2801B strips have two data lines (data and clock), whereby individual LEDs can be addressed via the integrated SPI bus of the Raspberry Pi. This is different for the WS2812B models. These strips have only a single data pin, which is why before sending a lot more has to be calculated. For this reason the WS2801B RGB LED strips are preferable to the WS2812 for use on the Raspberry Pi, despite their supposedly smaller “serial number”.

 

Connect the switching power supply to the WS2801

Before we start, we have to connect the current source (only for the plug-in power supply). If you have selected the first variant – a charger-like power supply – you can jump to the next point. You only need to clamp the plug adapter to the power supply and loosen the screws.

Netzkabel für Raspberry Pi WS2801
Ensure that the power cord is compatible with 10A.

First of all: Working with 230V voltage can be deadly! While you make changes, all connections to the socket must be disconnected! Be careful and only work with it if you are sure of your cause. If this is not the case, I recommend the first power supply.

We start by cutting the power cord (e.g. old PC power cable). There are two or three cables inside. These must be carefully separated by about 1cm from the insulation, so that only the wire is visible in the cables. The switching power supply has three connections on the left side. On the one hand, “L” (phase / outer conductor) and “N” (neutral conductor), which are marked with AC (alternating current) and a grounding symbol. If your cable only contains two smaller cables, they will be connected to the AC connectors. If there are three, you must also identify the earth cable and connect it to the earthing symbol / “PE” connector.

Since the colors of the inner cables differ with older power cables, here is a brief overview, what color comes:

  • The black or brown cable comes to the outer conductor “L“.
  • The blue cable is connected to the neutral conductor “N“.
  • The green-yellow cable is connected to the protective conductor “PE” or grounding symbol.
Aufgeschnittenes Netzkabel mit abgetrennter Isolation
Cut-out two-core power cable with separated insulation.

For connecting the cables, the screws of the power supply must be loosened. Then place the wires under the screws. Make sure that they are well screwed and that the cables can not come loose. Normally, these devices still have a small protective flap, so that you don’t touch them accidentally. If you want to be safe, you can also wrap insulation tape around the sensitive spots.

On the other side, there are outgoing 5V voltage (+V) and the ground connections (-V or COM). As a test, you can use a Multimeter to measure the voltage as shown here:

Multimeter am Schaltnetzteil des WS2801 LED Strip
The output voltage of the switching power supply should be about 5V.

 

Wiring between Raspberry Pi, WS2801 and current source

Normally, the LED strips come with soldered plugs, which are intended for connecting several WS2801 strips. In addition, there is usually also a plug, which can be put on a Breadboard (4 connected cables). Furthermore, two additional cables for the external power connection from the LED Strip (red and black) are often used.

Since the color of the cable does not necessarily correspond to the standards, you should pay attention exactly which cable leads to which connection on the strip. Incorrect wiring on the Raspberry Pi could result in overheating or a short-circuit.

WS2801 RGB LED Streifen
The LEDs on one meter are numbered (1 – 32). The WS2801 RGB LED strip has 2 data pins (here: CK and SI) as well as the 5V connector and GND.

If you are aware of which cable leads to which connection, we can connect it. The Raspberry Pi should be switched off and the switching power supply should not be connected to the socket. The cables are connected as follows:

WS2801 LED Stripe Raspberry Pi (Switching-) Power Supply
 5V  —  +V
 CK / CI  Pin 23 (SCKL)  —
 SI / DI  Pin 19 (MOSI)  —
 GND  Pin 6 (GND)  -V or COM

For the connection to the switching power supply you can also use the two additional cables (if available). It is important that GND / ground is connected to both the Raspberry Pi and the external power supply. The structure now looks as follows:

Raspberry Pi WS2801B RGB LED Stripe Schaltplatine

 

 

Installing the Raspberry Pi WS2801 RGB LED Library

To control the LED strip we use a Python library from Adafruit. This special Raspberry Pi WS2801 library includes some functions for controlling the individual LEDs. The good thing is that each LED can be addressed individually and any RGB color is possible.

The library requires the SPI bus, which we have to activate (if not already done). We call the following:

sudo raspi-config

Under “Advanced Option” there is a point for “SPI”. We enable it and exit the configuration menu.

The installation now works quite simply via the Python package manager from the normal console / terminal. Preventively, we are first updating the package sources and installing PIP (this is not included on the Raspbian Lite versions by default):

sudo apt-get update
sudo apt-get install python-pip -y
sudo pip install adafruit-ws2801
Raspberry Pi WS2801B Weihnachtsbaumbeleuchtung
Christmas tree lighting with the WS2801.

If you have a lite version or SpiDev is not installed on your system, please follow this guide to install and activate it. On newer Raspbian versions, however, it should already be pre-installed.

Since the given example of the developers apparently does not work on all (fresh) Raspbian versions, I have changed that and expanded.

 

 

Sample code for brightness dimming of the WS2801 LEDs

The following example can be used and extended for your own projects. Here, a few colors (rainbows) are first switched in series, whereupon the brightness of the individual colors is dimmed. For this, it must be said that the brightness of a color can also be defined with the RGB value (see RGB Color Picker for this).

So let’s create a file:

sudo nano ws2801_example.py

The following content should be inserted:

Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# Simple demo of of the WS2801/SPI-like addressable RGB LED lights.
import time
import RPi.GPIO as GPIO
 
# Import the WS2801 module.
import Adafruit_WS2801
import Adafruit_GPIO.SPI as SPI
 
 
# Configure the count of pixels:
PIXEL_COUNT = 32
 
# Alternatively specify a hardware SPI connection on /dev/spidev0.0:
SPI_PORT   = 0
SPI_DEVICE = 0
pixels = Adafruit_WS2801.WS2801Pixels(PIXEL_COUNT, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE), gpio=GPIO)
 
 
# Define the wheel function to interpolate between different hues.
def wheel(pos):
    if pos < 85:
        return Adafruit_WS2801.RGB_to_color(pos * 3, 255 - pos * 3, 0)
    elif pos < 170:
        pos -= 85
        return Adafruit_WS2801.RGB_to_color(255 - pos * 3, 0, pos * 3)
    else:
        pos -= 170
        return Adafruit_WS2801.RGB_to_color(0, pos * 3, 255 - pos * 3)
 
# Define rainbow cycle function to do a cycle of all hues.
def rainbow_cycle_successive(pixels, wait=0.1):
    for i in range(pixels.count()):
        # tricky math! we use each pixel as a fraction of the full 96-color wheel
        # (thats the i / strip.numPixels() part)
        # Then add in j which makes the colors go around per pixel
        # the % 96 is to make the wheel cycle around
        pixels.set_pixel(i, wheel(((i * 256 // pixels.count())) % 256) )
        pixels.show()
        if wait > 0:
            time.sleep(wait)
 
def rainbow_cycle(pixels, wait=0.005):
    for j in range(256): # one cycle of all 256 colors in the wheel
        for i in range(pixels.count()):
            pixels.set_pixel(i, wheel(((i * 256 // pixels.count()) + j) % 256) )
        pixels.show()
        if wait > 0:
            time.sleep(wait)
 
def rainbow_colors(pixels, wait=0.05):
    for j in range(256): # one cycle of all 256 colors in the wheel
        for i in range(pixels.count()):
            pixels.set_pixel(i, wheel(((256 // pixels.count() + j)) % 256) )
        pixels.show()
        if wait > 0:
            time.sleep(wait)
 
def brightness_decrease(pixels, wait=0.01, step=1):
    for j in range(int(256 // step)):
        for i in range(pixels.count()):
            r, g, b = pixels.get_pixel_rgb(i)
            r = int(max(0, r - step))
            g = int(max(0, g - step))
            b = int(max(0, b - step))
            pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color( r, g, b ))
        pixels.show()
        if wait > 0:
            time.sleep(wait)
 
def blink_color(pixels, blink_times=5, wait=0.5, color=(255,0,0)):
    for i in range(blink_times):
        # blink two times, then wait
        pixels.clear()
        for j in range(2):
            for k in range(pixels.count()):
                pixels.set_pixel(k, Adafruit_WS2801.RGB_to_color( color[0], color[1], color[2] ))
            pixels.show()
            time.sleep(0.08)
            pixels.clear()
            pixels.show()
            time.sleep(0.08)
        time.sleep(wait)
 
def appear_from_back(pixels, color=(255, 0, 0)):
    pos = 0
    for i in range(pixels.count()):
        for j in reversed(range(i, pixels.count())):
            pixels.clear()
            # first set all pixels at the begin
            for k in range(i):
                pixels.set_pixel(k, Adafruit_WS2801.RGB_to_color( color[0], color[1], color[2] ))
            # set then the pixel at position j
            pixels.set_pixel(j, Adafruit_WS2801.RGB_to_color( color[0], color[1], color[2] ))
            pixels.show()
            time.sleep(0.02)
            
 
if __name__ == "__main__":
    # Clear all the pixels to turn them off.
    pixels.clear()
    pixels.show()  # Make sure to call show() after changing any pixels!
 
    rainbow_cycle_successive(pixels, wait=0.1)
    rainbow_cycle(pixels, wait=0.01)
 
    brightness_decrease(pixels)
    
    appear_from_back(pixels)
    
    for i in range(3):
        blink_color(pixels, blink_times = 1, color=(255, 0, 0))
        blink_color(pixels, blink_times = 1, color=(0, 255, 0))
        blink_color(pixels, blink_times = 1, color=(0, 0, 255))
 
    
    
    rainbow_colors(pixels)
    
    brightness_decrease(pixels)
    
 

In line 11 you have to specify the number of LEDs that are on the connected strip. This should be 32 meters. You can save the file with CTRL + O and close the editor with CTRL + X.

Here is the promised video with the different effects from the file:

I would be interested in what projects do you plan to do (Advent lighting, Christmas tree decoration, spice up rooms, “Infinite Mirror Table”, etc.)? Are there any requests for specific tutorials related to the Raspberry Pi WS2801B controller? I already have some ideas, but would also like to hear your opinion 🙂

 

current supply power adapter python voltage WS2801 LED Stripe WS2801B
Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
Previous ArticleRaspberry Pi GPIO Erklärung für Beginner + Programmierung (Teil 2)
Next Article Programmieren lernen am Raspberry Pi – Teil 3: GUI erstellen

Related Posts

Control all GPIOs with the Raspberry Pi REST API via Python

How to build a ESP8266 Scale (with Weight Sensor HX711)

Using TensorFlow Lite with Google Coral TPU on Raspberry Pi 4

How-To: Bluetooth Connection between ESP32’s and Raspberry Pi’s

88 Comments

  1. DorsaiFeydakin on 1. September 2017 16:31

    Hi guys, firstly well done getting your LED strip to work. Now I have spent days (literally ) looking at websites, level convertors, multimeter test, circuits and rxtx libraries, software like Glediator the whole kaboodle. The wife will raise eyebrows at the paypal account I can tell you. Currently trying to run a WS2801 strip with 160 rgb leds and if i’m lucky i’ll get three to light up. Is there a forum that will help me step by step?

    Reply
    • Felix on 9. September 2017 9:49

      Are you sure that is a WS2801? Can you contol any of those 3?

      Reply
    • James on 27. July 2019 1:27

      I’m in the same boat – did you ever get yours working? And any tips or links to get going? Using this tutorial with the 5meter strip is not working quite as easily…. anyway, if anyone else finds this in the future, https://raspberrypi.stackexchange.com/ is the place to check next.

      Reply
    • Tome on 11. September 2022 10:13

      Thanks for that great tutorial! I reconstructed it. Do you have by any chance another one explaining how to use the music input with the WS2801?

      Reply
  2. Reda on 13. September 2017 21:27

    Hello !

    Nice work, can we use this setup to create an ambilight like for TV and HDMI Sources ?

    if Yes, I am noobie, would love to have a tutorial !!!

    Thanks

    Reply
    • Felix on 13. September 2017 21:47

      Yes, I have done that already (german site), but not translated yet.

      Reply
  3. Reda on 14. September 2017 0:09

    Awesome, I can translate the website !

    Thanks for your answer.

    Is it possible to do ambilight for HD sources with a WS2812B only using a Rapsberry pie 3 and Hyperion (without adruino)? This way, I can use the WS2801 tutorial you did (if it’s exactly the same steps), using my WS2801B.

    Thanks for the awesome work !

    Reply
    • Felix on 15. September 2017 9:49

      Yes, I did it completely without an Arduino (but WS2801 instead of WS2812).

      Reply
  4. Reda on 16. September 2017 7:08

    Ow, so the thing is : I can’t get ambilight for hdmi sources using Ws2812B without Andruino ?

    If there’s any way to make my Tv look awesome like yours, I would really appreciate your help !
    Thanks !!

    Reply
    • Felix on 16. September 2017 12:33

      Maybe you can, but I haven’t tried yet. If you use an external audio card, you can use the WS2812 on a Raspberry Pi (tutorial on my german site)

      Reply
      • linkreincarnate on 25. September 2017 22:02

        You can use spi with ws2812 and then onboard audio works fine.

  5. Reda on 16. September 2017 23:47

    Thanks,
    I am newbie at this project… Is a Elegoo Uno (Arduino uno clone) will work ?

    Reply
    • Felix on 21. September 2017 10:50

      This is a Raspberry Pi project, so no it will not work with an Arduino 🙁

      Reply
  6. Bilel on 21. September 2017 7:54

    Hi Felix, thank you so much for this great guide, well explained!
    I have 2 questions :
    1 – If I use th “Switching power supply” solution, will it be possible to use it to power up the raspberry via tha GPIO pins (5v & Ground)? I read that if so there would not have any over current/voltage
    protection? seems dangerous! (source: modmypi.com/blog/how-do-i-power-my-raspberry-pi)
    2 – I’m writing a custom library in NodeJS to control the RGB strip, to reduce the size of the installation I would like to use the small Pi Zero board, The purpose is to update each led of the strip at a 50ms frequency. Do you think the GPIO bandwidth & the CPU of the Pi would handle such a frequency?

    Thank you again!

    Reply
    • Felix on 21. September 2017 10:54

      Hi Bilel,
      1 – it’s only an option but yes, you are wright.
      2 – you have to know that the Pi does not operate in real time like an Arduino, so it could be possible, that the frequency will vary. But actually, the Pi Zero can do that (see my YT channel, where I used a Pi Zero and WS2812).
      Best regards,
      Felix

      Reply
      • Bilel on 21. September 2017 21:58

        Thks for the quick answer Felix, the video answers my 2 questions!
        Is the lack of the over current/tension protection so important?

        I also seen your try with the Pi Zero is very very responsive, hope it will act the same way with a 5 meter 2801 strip xD

  7. Alex on 4. October 2017 16:51

    any idea how do i make rainbow cycle only to loop forever smoothly? thanks

    Reply
    • Alex on 5. October 2017 2:44

      nvm figured it out.

      Reply
  8. mk on 11. October 2017 19:54

    Hi, what components such as resistors did you use on your breadboard? Also, I can somewhat make out the wire connections in the video , but It’s not a precise top down view, which would of been easier. If possible is there a schematic of the wires from the pi , leds, and external power going into the breadboard slots. Would make my life a lot easier. Been trying to figure this out for months. Thanks

    Reply
    • Felix on 14. October 2017 22:36

      Just use the wiring as shown in this post.

      Reply
      • mk on 18. October 2017 18:47

        Maybe you didn’t see what I was talking about but very clearly in the video, the one linked in this post, there are 3 resistors on the breadboard he is using. https://i.imgur.com/jH4BQJ2.jpg I just don’t know what ohm rating to get for the resistors, that’s the only thing left I need to do.

      • Felix on 19. October 2017 0:43

        These aren’t resistors, these are diods, but I am not using them (had something else connected before and just forget to remove them).

  9. MommaBacon on 14. October 2017 5:23

    Very cool, thanks for sharing!! I’m a newbie to all this trying to keep up with my kid. Some projects we’re looking to do together are build a sound reactive lightning simulator as well as Christmas tree lights synchronized to music (so those are my tutorial suggestions ;)).

    Reply
    • Anurag Simgeker on 13. November 2017 8:16

      I’m looking for a tutorial to connect multiple WS2801B strips for a Christmas lights projects using the lightshowpi project. Any luck?

      Reply
  10. Stache on 10. November 2017 23:57

    Fantastic tutorial. I’m using AlexaPi and the Magic Mirror platform and will have these led’s built into the frame of the mirror. I would like these to be triggered when Alexa is summoned similar to an Echo. This would imitate the blue light moves around the Echo when it hears the trigger word. How would I program that scheme?

    Reply
  11. Anurag Simgeker on 13. November 2017 8:14

    I’m looking to connect multiple WS2801B strips for a christmas lights project. From the research i’ve done, it seems like I need a port expander like the MCP23S17. But I couldn’t find a wiring diagram. Can you point me in the right direction? Thanks!

    Reply
    • Felix on 13. November 2017 19:40

      No you can use it with two GPIOs, as I have shown in the tutorial.

      Reply
      • Anurag Simgeker on 17. November 2017 5:21

        Thank you so much for the reply. I think your blog is an excellent resource for learning. I really appreciate it.
        In your tutorial, you have a single long strip. I’m looking to connect 3+ strips simultaneously, use the lightshowpi project to control the lights and play music at the same time. I’ll power the three strips using three 5v-10A power supplies. Correct me if I’m wrong, but would I have to daisy chain the CK / CI Pin 23 (SCKL) and SI / DI Pin 19 (MOSI) from one strip to the next in order to achieve this?

  12. Arne Fjord Rasmussen on 20. November 2017 18:40

    For a switching PS….couldn’t one use a PS from a PC. I mean it has 3.5 5.0 and 12 volts…and most of easy delivers 30 amp i think i have a china RGB chain that needs 12v – but i cant really remember anyways thats not the question…the question is about he PC PS….and wouldnt you be able to draw the 5 volts for your raspberry from same PS – as far as i know – ih has 2 or 3 or sometimes 4 channels with 5 volts…..even if there was a fluktuation wich i dont think there is…the PS should swich off – isn’t that right?

    Thanks in advance
    Arne

    Reply
    • Felix on 20. November 2017 22:18

      You can power the Pi with 5V from the power supply, but do NEVER connect 5V to any GPIO – it will break it.

      Reply
      • Arne Fjord Rasmussen on 21. November 2017 20:33

        Thank you for the answer – no i wouldnt do that 🙂

    • Craig V. on 25. November 2017 16:28

      I have a 12 volt 30 amp supply and I just connect a car USB charger to it in order to power my pi. I have used PC supplies in similar fashon which failed prematurely. I’ve been told they are designed to be fully loaded so leaving the other rails, 3.3v and -12v, unloaded causes it to prematurely fail (improper heat distribution stresses solder joints). Plus, some supplies have multiple 12v rails which equals the rated current so if it were rated at 35 amps, it may have two 12 volt, 15 amp rails and one 12 volt, 5 amp rail. Then again, I could just be buying cheep PC power supplies. 🙂

      Reply
      • Poppy Ann on 4. November 2019 18:12

        I have powered lots of projects from desktop psu’s there is no need to have it under load if it is a modern one then you have to bridge two of the lines to get the psu to power up I have used one to build a bench power supply which had 3.3v 5v 12 v and one adjustable output that could be adjusted for either constant current or constant voltage which I used for charging batteries with.

  13. Craig V. on 23. November 2017 6:19

    Great turtorials and awesome work. I went thru the ws2812 turtorial and I am stumped. I keep getting an error saying ws.ws2811_init failed with -5 (mmap(), #something I can’t remember#). Needless to say, it won’t control my light strip, 308 channels using program striptest.py. I’m a noob to raspi. I’ve installed it on a raspberry pi 3 model B #I think#. I am using the 7″ touchscreen so could that be causing the issue? Any help would be greatly appreciated.

    Reply
    • Craig V. on 25. November 2017 16:09

      I figured it out. After careful debugging it was discovered that I am an idiot. I missed the step where virtual pin 18 is physical pin 12 on the IO header. Works almost flawlessly after that. Now I just have to figure out why the very first channel of an update string is slightly different than the rest. Example:

      for i in range(0, 19):
      strip.setPixelColor(133 + i, Color(200, 0, 0)
      strip.setPixelColor(133 – i, Color(200, 0, 0)
      strip.show()
      time.sleep(50/1000.0)

      As it runs, the first channel updated, ex. 133 – i, will be a different color than it should be. If blue it will be redish, if red it will be green and green works fine. Its almost as if the code doesn’t terminate properly at the end and it affects the first channel of the command at the end. Anyone have any thoughts?

      Reply
    • Craig V. on 25. November 2017 16:30

      And I just realized I am on the imcorrect tutorial page. Sorry. Should have been the ws281x tutorial. 🙁

      Reply
  14. Ronald Hatcher on 24. November 2017 13:24

    This was really helpful but wanted to note that – for raspian at least – SPI is enabled by editing \boot\conflig.txt and making sure that dtparam=spi=on isn’t commented out …

    Reply
  15. Albron on 3. December 2017 18:57

    when i execute the script nothing happens..
    can smb help me with this problem?

    Reply
    • Felix on 10. December 2017 19:55

      Can you please be more specific?

      Reply
  16. Tom on 28. December 2017 10:51

    How many LEDs is raspberry able to address from SPI? I hope it will not have problem with 320 LEDs. Thank you!

    Reply
    • Felix on 30. December 2017 0:43

      I haven’t tested it but as long as it has enough power, I would guess that is no problem.

      Reply
      • Tom on 30. December 2017 10:37

        I tried it and have enough power. First 160 LEDs are working and other 160 LEDs not. It all lights randomly when I connect it and then when I send signal I can controll only first half. I do not know what to do with that, it is strange.

  17. Phil H. on 29. December 2017 22:22

    Thanks for this great tutorial. I used it to setup an LED strip that I used on my Christmas tree. I created a simple web app to control the LED lights, running in a Docker container on the Raspberry Pi. I have released the code on github at: https://github.com/philhansen/led-lights

    Reply
  18. Jesse on 1. January 2018 6:03

    so hi. Love the effort and taking the time to share. I’m very new. Like new-new. I can’t seem to get anything to work. I’m wondering if you could break it down a little more. I run the file and after about a minute I get the last LED to light up very dimly. That’s about all I got. I had it at 33 LEDs and thought I should shorten it I’m using a 5V 3A power supply so that should be more than enough for 16. Could you write a very simple script to just light up 1 LED? I’m not a python guy. I’m taking tutorials but not yet to the level I need to be to read all that is going on here. Also any other sources you can post would be helpful. Thanks Jesse

    Reply
    • Felix on 1. January 2018 14:54

      Just set PIXEL_COUNT = 1

      Reply
  19. Kent M on 11. January 2018 3:32

    I need some help with creating the file in the nano editor. When I open the file with “sudo nano ws2801_example.py” , an empty file opens in the terminal window but the text in your sample file is not there. I know this is a novice error but what am I missing? Thanks
    KentM

    Reply
    • Kent on 12. January 2018 0:08

      Can someone tell me what directory the example.py file should reside to make it run?
      It appears that changes in the Raspberry config have been made since this was
      written. The various interfaces can be enabled and disabled from the GUI.

      Reply
      • Kent on 12. January 2018 0:15

        %Run example.py
        Traceback (most recent call last):
        File “/home/pi/example.py”, line 6, in
        import Adafruit_WS2801
        ImportError: No module named ‘Adafruit_WS2801’

        This the error msg I get.

  20. Kent on 12. January 2018 23:26

    I have it working!!! The whole problem all along was my lack of experience with Linux/Python in general. I had downloaded the Adafruit library from github, extracted the zip file but apparently I did not get it in the correct location under /home/pi/. This time I opened the readme.md file and followed the instructions in there for installing the library. I then opened a terminal and executed the file “example.py”. And to my amazement it worked fine!! However, I still can’t get it to run from a GUI interface without getting error msgs. I am now troubleshooting a problem on the strip itself. The very first led stays red all the time while it is powered and not running. It doesn’t seem to be effected during the execution cycle.

    Reply
  21. Bret Barkley on 9. February 2018 20:35

    Hi, I bought a 5m strip of ws2801, wired it together, and nothing happens when I run the script. The led strip isn’t on at all. How would you debug this?

    Reply
    • Felix on 11. February 2018 12:33

      Is the wiring correct and has it enough voltage?

      Reply
      • Jonathan on 28. October 2019 23:52

        I’ve got this problem too… wiring is correct (same as yours – though with different colours, I had to read the small print to confirm which was which!), voltage is OK… same supply as I’ve use with a string of 150 WS2811 LEDs. Code runs, but no LEDs. I’ve spent several hours swapping components in and out but no joy.
        Other than what is discussed in the article, are there any other settings on the Pi that might need changing? I (and Google) and are completely out of ideas. 🙁

      • Jonathan on 29. October 2019 16:09

        I figured it out…
        I’ve got the waterproof version where the circuit boards are encased in plastic. It turns out I was mis-reading the distorted letters on the PCB and had the lights connected the wrong way round.
        Maybe I just need glasses…
        So, ignoring my little problem, this article is the best on the web to explain how to do this. Thanks!

  22. Frans on 25. March 2018 12:49

    Thank you. It functions as described at the first attempt.
    Very important point: You wrote: “Since the color of the cable does not necessarily correspond to the standards, you should pay attention exactly which cable leads to which connection on the strip.” I had to remove the shrink tubing to find, that the green and the red cable had been soldered together”!
    I am a beginner, how do I see in the program, that Pins 19 and 23 should be used?

    Reply
    • Felix on 26. March 2018 22:45

      I had that problem, too. After removing the shrink, it was clear to me. I use spidev0.0, which needs MOSI (Pin 19) and SCLK (Pin 23).

      Reply
  23. Ron on 28. March 2018 20:51

    Thank you for this tutorial! I have used it as a starting point to create an extension for the Scratch programming language. Now my children (and, in fact, many other kids in the school they are attending) can program the led strip. It’s so great to see the fun they’re having with it. I have uploaded the stuff I created to Github: https://github.com/ronbuist/ws2801scratch. The README on this page also refers to your tutorial. Again, many thanks!

    Reply
    • Felix on 28. March 2018 21:27

      I’m glad it helped you and thank you for sharing it 🙂

      Reply
  24. John on 1. May 2018 18:33

    Thanks for the great tutorial. I have the LED and have ordered the PI.

    My goal is to put these LEDs on my motorcycle. There will strips of LEDs placed in various places on the bike. I understand I need to keep the wires going from one strip to the next in series. That will take some doing, but not a big problem. My concern is the timing. Is there going to be an issue with the length of wire between the strips of LEDs causing a timing issue?

    Reply
  25. St3n on 12. May 2018 17:52

    Hi! Very cool project, this is what I needed! But i have a question. Is it possible to run on Windows 10 IoT Core? Or import the library on Visual studio to run it in C#

    Reply
  26. Kelly on 24. September 2018 18:49

    Hey, will this same schematic and programming work with the WS2811 leds? I would like to create a panel of pixels where I can display different pictures and even animate text. Is this possible with what you have done here? If not, would you consider doing that tutorial? Thanks!

    Reply
  27. John Willis on 30. July 2019 18:55

    I was looking for information on using WS2812B LEDs connecting to audio output plug and read “onboard audio output of the Raspberry Pi can not be used anymore” I was curious as to why??

    Reply
  28. Poppy Ann on 15. October 2019 8:59

    The power supply that you say is the best can only be used in UK if it is inside a case which has a cover over the terminals that can only be accessed either by unscrewing it or unlocking it you are not allowed to use anything that a child could get their fingers to the live terminals.
    Except for that this is a great tutorial many thanks for your work.

    Reply
  29. Andy on 4. January 2020 20:19

    Hey,

    Appreciate the time you have taken with this. I am currently working my way through it. I have a question about the code

    The Wheel() function takes r,g,b values that it generates and turns them in to a single value color with Adafruit_WS2801.RGB_to_color(). Then that single value color is passed to Adafruit_WS2801.setpixel() which splits the color out into separate R,G,B values and then passes those to Adafruit_WS2801.set_pixel_rgb().

    Is there a good reason for taking the seperate values into one, then immediately splitting back out like this? On the face of it it seems inefficient but maybe it’s just easier… i dont know.

    Thanks

    Andy

    Reply
  30. Bill on 4. January 2020 20:27

    Thanks a load for this article. With it’s wonderful and complete description, I was able to build a 120 pixel LED light string and with playing around with the code, I learned sooo much.

    Reply
  31. Tadbor on 5. June 2020 19:32

    Wounderful program but I have problem, how can I do loop

    Reply
  32. Stephen Hemminger on 24. June 2020 7:40

    The Adafruit_WS2801 library is now deprecated.

    Quote: This library has been archived and replaced by a new library that is Python 3 compatible and works with a wide range of Linux/hardware
    https://github.com/adafruit/Adafruit_CircuitPython_WS2801
    This library is no longer supported. Please use the new library

    Could you update the example and library usage please?

    Reply
    • Graeme on 29. November 2020 19:51

      Hi,

      This seems to work to set it up on a Pi;

      # Simple demo of of the WS2801/SPI-like addressable RGB LED lights.
      import time
      import board

      # Import the WS2801 module.
      import adafruit_ws2801

      # Configure the count of pixels:
      pixel_count = 160

      pixels = adafruit_ws2801.WS2801(board.SCLK, board.MOSI, pixel_count * 3, brightness=0.8, auto_write=False)

      Good luck!

      Reply
  33. Maxime Thomassin on 28. July 2020 17:54

    Hi,
    is it possible to install multiple led strips on the same board and control them from the rpi ?

    Reply
  34. Steve Boniface on 29. August 2020 0:11

    Hi,

    Thank you for this helpful tutorial. While I can digest and understand the code fairly well, I am a total newbie when it comes to understanding what’s going on with the wiring.

    Could someone explain why I need to also setup a ground on the Pi as well?

    Thank you, Felix!

    Reply
  35. Andreas on 18. September 2020 22:37

    How many unique light strings can the base Raspberry Pi control? If more accessory hardware is purchased to provide more SPI busses, what is the theoretical limit of unique light strings that the Raspberry Pi can control?
    Thank you.

    Reply
  36. Farhan Rob on 6. October 2020 16:51

    Great work! This is an excellent introductory post for LED control. Any guides on integration with the Amazon Alexa module? i.e. having the LED strip turn on once the Alexa wake-word is activated.

    Reply
  37. Jonah on 29. January 2021 20:03

    Is there a preference to what kind of Power Adapter I should get? As well as for the Plug in Connector because right now I am scrolling around Amazon trying to find ???? so is there a preference.

    Reply
  38. Mark Harris on 31. January 2021 18:03

    Is there anything I need to do special to make sure the script runs at power-on?

    Reply
  39. Gareth Scott on 1. February 2021 10:04

    Hi
    great tutorial, very useful but I’m after running more LED’s 600, but can only get the first 160 to run, anyone any ideas

    Reply
  40. d on 6. March 2021 5:02

    This is great, thank you so much!! I set up a small nodejs server on my pi and then control the leds with websockets. Probably the coolest thing ive done with the pi yet. Cheers!

    Reply
  41. anv in on 11. April 2022 8:38

    https://www.w3schools.com/colors/colors_picker.asp

    Reply
  42. MochaSteve on 22. December 2023 2:11

    Hi, could you make a little tutorial on how to Set up That stuff on a raspberry pi pico?

    Reply
  43. Mirek on 14. February 2025 15:24

    Thank you for your tutorial. So the power consumption of 5m strip is 10A on 5V. It is surely not necessary to have 230V plug made for 10A 😉

    Reply

Leave A Reply Cancel Reply

How to connect and control a Raspberry Pi WS2801 RGB LED Strip

Build Raspberry Pi GPS location/navigation device

Control all GPIOs with the Raspberry Pi REST API via Python

Raspberry Pi LCD Display: 16×2 Characters Display (HD44780)

Setting up Raspberry Pi 4 Wi-Fi and Bluetooth

Connect a Raspberry Pi Keypad – Code Lock

Subscribe to Blog
Subscribe to Raspberry Pi Tutorials and don't miss any new Tutorial!
Subscribe

Thank you!

We will contact you soon.

Tutorials for Raspberry Pi
Facebook Twitter YouTube
  • Contact & Disclaimer

Type above and press Enter to search. Press Esc to cancel.