Ambilight with Raspberry Pi and Openelec (part 1)

Last weekend, I decided to build an Ambilight kit to use with my HTPC (a Raspberry Pi with OpenElec 4.0.5).

In a couple of articles, I will show you the steps I followed for hardware and software installation.

The hardware

In this first article, we will start from the components needed. In my case, I purchased everything from Adafruit:

2x 12mm Diffused Thin Digital RGB LED Pixels (Strand of 25)
1x 5V 2A (2000mA) switching power supply – UL Listed
1x Female DC Power adapter – 2.1mm jack to screw terminal block
1x Breadboarding wire bundle

I purchased two strands of leds, because I was not sure of how many leds I really needed. In the end, I used all of them for my 32 inches TV. There are other types of leds if you prefer (pixel strip), but be sure they have at least the WS2801 chip that handle 24bit colors.

The power supply is necessary to power the leds, because the raspberry cannot do that by its own. To be honest, if you like, you can buy a stronger power supply (4a at least) to also power up the Raspberry Pi. You have to use the GPIO instead of the mini USB adapter and is not a good choice in my opinion, because, via the GPIO, there is no backward protection (here is a discussion on the topic).

I chose than to start with two separated power supplies. Remember also to check the power supply connector, so you will not end up like me, and have to buy another one with the correct connector for my country 🙂

In a future post, if there is interest, I will describe my solution to end up with just one power supply.

Assembling the pieces

Now the fun part, let us take our TV on the table and start to hack it.
First, we prepare the leds and connectors that we will then attach to the back of our TV. Just connect together the led stripes (two in my case) and on the male end, connect the female DC power adapter like in the photo below:

WP_20140531_10_35_16_Pro

With the leds I used, the red wire must be connected with plus sign (+) of the DC power adapter, while the blue one on the minus sign (-). Be sure to check how your leds should be wired before frying everything.

DC_Power_Adapter_CloseUp

To attach the leds on the back of the TV, I used a cardboard with double-sided tape. I found it handy for taking the measures and in the case I need to remove and re-attach it.

WP_20140531_11_09_44_Pro

Take the measures and cut it to cover a little less than the TV’s borders. Remember to leave room for vents and back connectors:

WP_20140531_11_38_58_Pro

Now it is time for some math, because we need to distribute equally the leds across the borders of the TV. I did not count the bottom border, because my TV is not hanging on the wall, so do your adjustments just in case (you may also need to increase the numbers of leds)

Measure and sum the three borders and then divide for 50. I end up with a led every 2.47 cm. If, like me, you want two leds on the top angles, you will need to do some adjustments and start drawing marks from one of them. At the end, you should have something like that:

WP_20140531_12_29_20_ProWP_20140531_12_29_23_Pro

Now it is time to attach the leds. I used two stripes of the same double-sided tape used for the cardboard, one on the bottom and one on the top of the them, and it worked just fine. The led are kept firmly in place without having to build any complex infrastructure to hold them.

WP_20140531_13_15_33_Pro

Wiring the Raspberry Pi

Now that we have the leds mounted, we need to connect the wires to the raspberry’s GPIOs.


Based on this diagram from Boblight’s source code, I just connected the two wires for data and the one for ground, so leave out the red one (it is the 5v).

WP_20140531_10_36_55_Pro WP_20140531_10_38_38_Pro

As you can see from the photos, the ground connector is inverted respect to the one in the diagram, so remember to look at the specs of your leds before connecting it.

Now that we have assembled all the pieces, we can proceed to the software part. In the next post we will see how to install and configure the software to handle the leds with XBMC.

Update for Raspberry pi2

As posted in comments by user Chaves, the pins to use are different from the first raspberry. Use pin 19 (MOSI) and 23 (SCLK) like in the photo below
rpi2_pins

  • slidvendetta

    Thank you for this guide. Making my parts wishlist set up now.

  • Pingback: Ambilight en una tele de tubo | Raspberry PI()

  • Pingback: Ambilight from any video source with a Raspberry (part 3)()

  • Pingback: Instalación Ambilight Raspberry PI + Openelec + Hyperion | Raspberry PI()

  • SQ

    Why is any other project recommend using no usb power on the pi and plug the 5v? Why didn’t you? I know some say its not the best way to power the pi (over-current protection), but why do they insist on not using a usb power adapter on the pi and wiring the 5v anyway?

    • Honestly I do not know. After doing some searching, the possibility of burning the pi connecting the 5v is high so I preferred to saty safe 🙂
      Maybe, like me, they try to reduce the number of power adapters needed for all the gadgets.
      I did the same by modifying one of my power adapter to be able to power up both the pi and the Leds.

  • Lierez

    Why you use the white cardboard?
    Why not just put the leds directly on the back of the tv?

    • Because my tv has “holes” for the side connectors, so I used the cardboard as a “bridge” to have my leds stay near the edge and not too inside. Also I was still experimenting, so when everything worked out I never thought of removing the extra paper

      • Lierez

        so it’s not for the light to be brighter or something like this?
        i can place the leds without the white cardboard and it wont affect the result?

        • Yes. I did not use it for some sort of “effect”.
          In my opinion is the wall behind the TV that will influence a lot the final result

          • Lierez

            thank you very much!!

          • Lierez
          • The chipset declared in the page is the same I use (ws2801). So it should works without problem.

          • Lierez

            hi
            finaly i have time to work on this project!!!
            i am using rpi2 and i connected all parts as you described.
            the led strip is connected to a 5v, 2a power suply.
            on the led strip i have 5v, ck, sd and gnd. the 5v is not connected to anything, the ck to pin 23 (spi_clck), the sd to pin 19(spi_mosi) and gnd to gnd.
            i have light on the leds but i dont have any changes on the them.
            i tried the 3 tests you recommended but nothing happens.
            i add a picture of the leds.

          • Hi, sorry for the delay, but I was on vacation. If no error message appear when you launch the command to turn red all the lights, maybe the configuration file of hyperion is incorrect or is not saved in correct directory. Have you double checked it?

          • Lierez

            I’m not at home now and tomorrow i’m going to vacation too so i will check it again next wednesday. I replaced the original configuration file with my file in the default directory it was installed in.
            I will try to download and use your file if it still not work.

          • Mesut Gençcik

            Dear Lierez,

            I think your strip works well
            I have same problem and i found the solution. It works now 🙂

            Solution:
            The GPIO pins can be addressed at the Raspberry Pi 2 ever to send signals to the LEDs, we must first activate a specific module in the config.txt file
            Just the Micro SD card from your Raspberry to take them then connect to your PC. Open this with a text editor and add this to a bottom side. Save it 😉

            # Ambilight Modul aktivieren
            dtparam=spi=on

          • I can confirm that, if you are using a rapsberry pi2. I worked on it this week and I will make a post in the next days with all the Q&A happened during this last year.

          • Lierez

            i hope this will be my last answer….
            everything works fine but i have one problem.
            there is a confusion between the red and the blue colors.
            when my screen shows blue background, the leds are red and when my screan shows red background the leds are blue.
            the green is o.k.
            can you help me to understand the problem?
            thank you.

          • You can configure the color sequence from the hyperion config. Change it from RGB to BGR and you should be ok. Also remeber to test the final result with the ad hoc video (at the end of part 2)

            Hope it helps

          • Lierez

            AMAZING!!!!!
            thank you very much for all your help!

          • Lierez

            i have a little problem (hope it’s realy the last problem).
            everything works fine and the colors are great but every few seconds all the leds are flashing.
            the time between every flash is not fixed and the color of the flashes is changing every time.

          • Have you double checked the connections? Are you using a video grabber (like in part three)?

          • Also try to play with the smoothing settings in hyperconf. that should reduce flickering

          • Lierez

            well i just arrived home.
            thank you mesut.
            where can i find the “config.txt” file in the sd card?

          • Mesut Gençcik

            It is on the root 😉

          • Lierez

            thanks man!!!!
            i changed the file via ssh and now its working great!!!!!
            i just need to change back the hyperion config file to my file and enjoy it.

          • Lierez

            Hi
            I checked the connections and i realized that i connected the strip in the opposite side. But after i changed the sides still nothing happens.
            I even try your configuration file and still nothing.
            In the picture is the message i received when i try the first command for testing the leds.
            The second pic is the connections on the strip.
            What else i can check?

          • Lierez

            i am trying to start again from the beggining
            the picture below is the hyperion installation.
            is it looks good?

          • Lierez

            i dont have the “adding hyperion to outostart script”

          • that’s strange. if you reboot the pi do you see the hyperion daamon in execution? (“ps” command if I remember correctly)

          • Lierez

            you are talking about this lines?

          • Yes. It seems that hyperion is loading correctly. Another stupid question, have you double checked to have uploaded the configuration file in the correct folder?

          • Lierez

            Yes. In the configfiles folder i replaced the one that was already there with my file.
            Maybe it have something with the fact that i am running opelelec 5?

          • I am using 5.0.8 without issues I do not think it is the problem. At this point the only test that come to mind is to really try with another stripe. Maybe you have a different one to use for testing?

          • Lierez

            I dont have another strip but i dont think the strip is the problem because when i connecting it to the power suplly the leds are lighting.
            When i disconnect the gnd the first led is blinking

          • Then try to recheck the connections (pins on the raspberry and on the leds, maybe check the specification of your specific stripe), sorry mate but no other possible solutions come to mind.

          • Lierez

            i think my strip has short between the 5v and the gnd.
            when i check shorts with multimeter it beeps when i touch both the 5v and the gnd.
            correct me if i wrong but it shouldn’t beeps right?

          • As far as I know it should not be shorted. Maybe the led get damaged when you connected them to the 5v of the Pi? Check if the Pi is working correctly, just to be sure.

  • Chaves

    can you help me? Im trying with a PiV2 latest OpenElec Release, follow all the guide, but it seems that the raspberry’s GPIOs, doesnt send amy signal….. or im not sure, since my leds doesnt light up.
    Im using a WS2801 led strip.

    • Are you sure the Hyperion daemon is loaded and working? maybe it does not work correctly with the new RaspberryPi

      • Chaves

        Yeah. The issue was the on the Pi2 you need to use other pins, in this scenario 19 and 23,hope this might help others.

  • Joel

    Have you connected the LEDs to the raspberry in the same side that you have connected the power supply? I have a raspberry li 2 and bought the LEDs that have just arrived, now my main two questions are a bought the power supply needed and which cables do I have to buy to connect the LEDs to raspberry!

    • I use a separate power supply for the leds (be sure to identify the correct amount of juice you need for your leds). Recently I have modified a bigger one to power up both the raspberry and the leds. If I will remember, tonight I will upload a photo of my experiment. For the connectors, just use jump wires like I did and check that everything works. Then, if you prefer, you can weld the wires.

      • Joel

        The LEDs strip has two sides right, I think that one for the input and another for output? How do I know which one is the input? And should I connect both the power supply and the connection to raspberry in the same side, input? Thank’s a lot for your help!

        • Look at the photos in my post. If you have more the one led stripe, you tie them togheter via the male/female connector. One female than is used for the data connections and the power supply. The 3 wires for data go to the raspberry the other two (red and blue) to the power supply

          • Joel

            Ok, thanks a lot for your help! Now I just need to get the jumper cables online since I can’t find any store that sells this kind of cables! Your tutorial is really a great help!

          • Joel

            Hello again, I’m having a problem to make this work, perhaps you can help me! I’ve done everything as you say in this tutorial, but my LEDs simply don’t give any sign of life! I’m using a charger 5v 2a with a usb cable and one adapter like you have here and a raspberry pi2 using the correct pins for this model, but after having everything connected and all the software installed without any error the LEDs don’t work at all! Do you have any idea about what may I been doing wrong? I’m even thinking that maybe the LEDs have some problem, but I don’t know how can I check if they really work or not!

          • Hi, If I understood correctly, you have one power supply for the Pi and one for the LEDs. If you try to launch the command to turn all the leds red from the console, you get an error or nothing?

            If you power up just the leds without the raspberry connected at least one light turn on?

          • Joel

            When I turn all the leds Red nothing happens and no error messages! I never got any Led to work at all…

          • mmh. Other than double check power and connectors I can not think of anything else to help you. I guess you should try to connect another stripe of leds if you can, and see if they are really faulty. Sorry I can not help you more than that

          • Joel

            Hello, I tryed using another charger which only has 1amp and although it still doesn’t work when I connect the power supply of the leds with raspberry working I get all the leds flashing one time Just for a fraction of second. I think it means that the leds may be ok right?

          • Yes, the LEDs should be fine

          • Joel

            Well in that case I really don’t know what else I can do to get it to work, I’ve tryied this several times, checked all the connections, tryed different softwares, tryed to use the boblight but also with no success… There must be something wrong here, with the leds or with rapsberry!

  • Pablinho

    Hi, i have a osram led strip, it still works with it?

    • I do not know, you should check on the site of hyperion if it support them

  • עידן אוליאל

    Hello and thank you for the guide !

    I have a question, will it work with WS2812B IC ?

    Thanks !

  • Pingback: Raspberry Pi | Pearltrees()

  • Ron

    Hi guys, it’s been a while 🙂

    Just got my LED strips and were about to start wiring everything together, when realized the cables colors are a bit different… There are red and white cables & red + white + green bundled (PFA).
    What should be connected and where to in the PI, and if I would like to use an external power supply what should I connect and where to?

    Thanks again.

    • Ron

      This is what I have.
      The bundled cables can be plugged as is to the raspi’s GPIO, assuming all the three headers are nearby obviously.

      • Shooting in the dark here, but are your leds the WS2812? it seems that a cable is missing. In my setup I have 4 connections, looking at your picture I assume you probably have ground, power and just one for data. Read this, it may be of help https://github.com/tvdzwan/hyperion/issues/6

        • Ron

          Thanks mate.
          On the back of the strip it says 3M 200MP so not quite sure…

          As for the four cables, I do have the enclosed connector which I can connect to the strip itself (cut the exist strip’s cabling). Is this what you meant? If so, how can I tell which cable (color?) is what and what it should connect to in the PI side?

          • You should ask who sold you the leds. When you know the chipset (WS2801, WS2812, etc.) you can easily find the schematics

          • Ron

            Thanks, the exact module is WS2812B

          • Then you should look at the link I posted in one of my previous comments