techtalk – Christian Moser It's all about technology

20Feb/1475

How to build your own Ambilight TV with Raspberry Pi and XBMC

I always wanted one of those colourful glowing large TV screens in my living room but I never felt like paying a fortune for it. So, why don't do it on my own? I ordered two Raspberry Pis, which seemed like a perfect fit for a media center and a LED controller because of the built in SPI bus interface. After some research, I decided that using SMD LED strips with WS2801 chips would be the best match for a Raspberry Pi controller. Furthermore SMD strips are quite easy to mount, because of the adhesive tape on the back of the strip.

Demonstration

Hardware installation

We'll setup the necessary hardware first.

Parts list

I've ordered following parts to complete the installation from boxtec.ch

1 x LED Pixel Strip 5m (WS2801)
1 x AC adapter 5V/10A
4 x RGB LED Strip - Pigtail Connector 20cm (pair)
1 x Heat Shrink Kit
1 x Breadboard Jumper Wire m-m (65-cable pack)
1 x 1pin dual female jumper wire (300mm) 20pcs.
1 x 5.5 x 2.1mm DC Power Jack Adapter (f)
1 x 2pin dual female jumper wire (300mm) 5pcs.
2 x Raspberry Pi Model B
2 x 8GB SD memory cards
1 x 1A MicroUSB AC adapter

You'll also need tools for soldering. Alternatively, you could use just one Raspberry Pi, which will act as the LED controller and the media center.

LED power consumption

Regarding the spec sheet, the 5 V LED strip consumes approx. 7.68 Watts per meter or 1.5 A. To calculate the total power consumption, we need to measure how many LEDs we can put on the TV's back. I needed 3.8 m of the SMD LED strip for my 55 inch TV.

Power supply calculation

Total power consumption: 3.8 m LED strip x 1.5 A + 1.0 A Raspberry Pi Model B = 6.7 A / 33.5 W.

Fortunately, the Raspberry Pi requires also 5V, so you'll be able to power up the strip and the Pi with the same 5V power supply. Just don't forget to order a DC Power Jack Adapter for easy connectivity of the at least 7 A / 35 W - 5V power supply.

LED strip soldering

As a Software Developer, I'm not an expert in soldering but I tried to do my best. Cut the strip into 4 pieces that match your TV dimension. For easy replacing of a broken LED strip or moving the installation to another TV connect the stripes with pigtail connectors.

DSC_3409DSC_3407DSC_3425

WS2801 LED strips have always four connectors. In my case with those pinouts:

  • 5V
  • GND
  • SD
  • CLK

Be careful, don't twist those between the pigtails! There's also an arrow on the strip, which marks input / output. Make sure you're able to connect the strips from input to output with the pigtail connectors.

It's easier to solder the connectors to the fine SMD if you put some soldering to each of the four joints in advance. Finish it up with a heat shrink, for more flexibility use non-adhesive heat shrink tubes.

DSC_3402DSC_3394DSC_3395

LED mounting

Now, we're coming to the fun part. It's barely easy to mount the strips because we chose SMDs, just use the adhesive tape and you'll be fine. It's essential that you start mounting from the bottom right, seen from the back of the TV with the arrow on the strip pointing to the right. Later, you'll connect from the GPIO from the RPI directly to this input of the strip. Then go ahead counter clockwise, connecting the output of the first strip to the input of the second strip and so on until you reach the bottom left. The output of the last strip is left empty, so the strips are not connected in a loop.

DSC_3411DSC_3415DSC_3424

LED strip wiring

Wire the LED's up as shown in the following diagram created by Philip Burgess. Make sure the input +5V/GND connectors of the strip and the Raspberry Pi power connectors are directly connected to the DC Power Jack Adapter (DC Jack).

Connect WS2801 to Raspberry Pi Model B

There's no need for the Pi's micro USB port anymore. I'd suggest using Breadboard Jumper wires for proper connections to the Pi's breakout board. Leave the output connectors of the LED strip as they are.

Prototyping: All wires connected to the Raspberry Pi.

prototyping

Final outcome: Raspberry Pi in black enclosure and power supply wired up.

Proper wiring

Software installation

So, the hardware is prepared. In this section I'll show you how to setup two different applications on the Raspberry Pi to control the LEDs. You have to chose one of them, I'd recommend Hyperion for various reasons.

Hyperion

Hyperion is newer, features a JSON interface and is easier to setup than Boblight. It is also less resource hungry. Therefore we can easily run XBMC and hyperion on the same Raspberry without performance issues.

  1. Install a media center distribution for the Pi. I recommend Raspbmc for beginners, it's easier to install and less locked down.
  2. Boot up Raspbmc and remote login with your host computer. You'll find the IP in XBMC under Settings -> System Info. If you're on Windows, use putty for the ssh connection.

    Prepare hyperion installation
  3. Install hyperion, it will also be added to your autostart.
  4. Now we create the hyperion config file which includes for example the LED position informations. It's a very readable JSON format. The configuration can initially be generated by a Java tool called "HyperCon". Have a look at the instructions page. Download HyperCon to your Host computer where Java must be installed. If you followed the LED installation instructions above, the following settings should give you reasonable results for a start. Please adjust the LED counts and the 1st LED offset four your setup on the "Hardware" tab. Then click "Create Hyperion Configuration" and save the json file to your Desktop. Don't rename the file.
    Hypercon - HardwareHypercon - ProcessHypercon - External
  5. Let's copy "hyperion.config.json" to the "pi" user home directory on the Raspbmc. You can easily copy the file by using the shared folder "raspbmc". Make sure you put it in the folder pi/hyperion. Alternatively you could use SCP for copying the file.
  6. Back on the Raspbmc ssh shell, copy the configuration file to the place where it will actually be picked up by hyperion at boot.
  7. We're nearly finished. Hyperion grabs the color information directly from XBMC over an interface running on port 9090. We configured this in HyperCon, tab "External". By default, this remote interface is disabled. In XBMC goto Settings -> Services -> Remote Control and activate both options. Reboot the system.
  8. We're finished, play a movie or display some pictures and the LEDs should light up. The LED are disabled in the menu, you could easily change this setting in /etc/hyperion.config.json, look for "xbmcVideoChecker".
  9. If you'd like to use the LED as mood lights simply install following excellent app and point it to the Raspberry Pi with port 19444: Hyperion for Android. For non Android users, there's also a web app available.

 

Boblight

I'd recommend using ArchLinux as distribution for the Raspberry Pi, it boots in less than 10s to the command line.

  1. Go to http://archlinuxarm.org/platforms/armv6/raspberry-pi and follow the instructions.
  2. Boot up the Pi and remote login: ssh root@raspberryip password is root.
  3. Create a new directory and switch:
  4. We'll install a resource optimised version of boblight for archlinux.

    This will install all required packages for the boblight installation.
  5. Let's checkout the optimised boblight source.
  6. Next commands will actually install boblight.

    Now, configure ld.

    Lets configure Boblight as a deamon so it will autostart after Archlinux was booted.

    Register the script as a deamon.

    Boblight should now be installed and running in the background. For more details, have a look overhere: https://github.com/werkkrew/boblight-archarm#installing
  7. Now generate the boblight config file. Switch to the boblight checkout directory create on step 3 and make the config script executable.

    Then execute the script

    The script will ask you for the exact LED count mounted on each side of your TV. Use the default values for all other inputs. Wait till the script is ready, then copy everything between "------- Light section starts here ------" and  "------- Light section ends here ------" into a text file on your host machine (Not on your Pi). Write down the total LED count.
  8. Download this preconfigured  config file: SPI-WS2801-basic and open it with a texteditor on your host machine. Add your generated light section simply to the end of the file. Multiply your total LED count by 3 (RGB channels) and replace "369" with your result in the file. Then select all and copy.
  9. Create the actual boblight config file with

    on your Pi and paste the content of your modified config file on the host machine into it, this will take some time to complete.
  10. Lets test the LED config.

    Check the output for errors.
  11. We're getting closer, try firing the LEDs up. boblight-constant BB55AA  All LEDs should light purple.

boblight-dispmanx installation

So, we've managed getting boblight to control our LEDs. Now, we'll see how to setup another tool for sending captured screen color information right to our boblight deamon, it's called boblight-rpi. Perform the following steps on the Raspberry Pi, that will be running the media center. A media center for example XBMC, running on this Pi will act as the video input source. Everything played on XBMC will be captured by boblight-dispmanx and sent to boblight.

  1. Install the newest version of OpenELEC (XBMC distribution) on your Pi: http://wiki.openelec.tv/index.php/Installing_OpenELEC_on_Raspberry_Pi#tab=Linux
  2. SSH to the OpenELEC Pi:

    Checkout the source code

    Set execution permissions to the precompiled boblight-dispmanx binary.
  3. We have to configure the tool to actually send the captured screenshots of the TV screen to your Pi Boblight server. Create an autostart script:

    Paste following sample config into the file.

    Don't forget to replace the {placeholder} with the IP of your boblight running Pi or set it to "localhost" if you went for one Raspberry Pi. Then save the script and make it executable with
  4. We're done, just restart the system
  5. Check the setup with a RGB test video. If you think the colours are to pale, try a higher value for the "-o saturation" parameter. When the lights are to slow, try setting "-o speed" to 90. If you don't like the LED's in the XBMC menu, just remove the "-b" parameter.

Conclusion

This is a really educational project, which will give insight into a lot of interesting technical areas reaching from compiling in the Linux shell to soldering and calculating LEDs power consumption.

For now, you're bound to XBMC as media source for ambient light your environment. If you want to go a step further and use every HDMI input signal as media source, have a look at this how to: How to build an Ambilight for every HDMI input source

If you have any question, feel free to ask in the comments section. Enjoy your ambilight!

Comments (75) Trackbacks (0)
  1. Hi Nitesh
    You may use your current media center but then you have to go this path: http://techtalk.christian-moser.ch/wordpress/?p=562 since you’ll need a SPI controller for this purpose.
    Regards Chris

  2. Hello

    I would like to build an ambilight for my 58″ TV but the problem is that I have never worked with a Raspberry Pi in my entire life. Can you please explain at a lower level so I can make one at home as well. I tried doing one with arduino but it requires a laptop plugged in constantly so I though of searching how to with a Raspberry Pi.

    Thanks,
    Sid

  3. Hi Sid

    I already tried to explain the setup process step by step. Perhaps you start first with some beginner guides and have a look at the documentation.

    Regards Chris

  4. Getting ready to start building this, finally! Reading through the tutorial again, I see you built this using two Pi’s. Is there any reason you didn’t set this up on one? Is performance an issue?

  5. I’m thinking Raspbmc and Hyperion is the way to go as you stated in the tutorial..how do I miss these things…

  6. Exactly, one Pi is sufficient with hyperion, good luck! ;-)

  7. can i use a mac mini instead?

  8. Just so I’m understanding this correctly…. If you go with Hyperion and XMBC then you only need one Pi, if you use Boblight then you will need two?

  9. Exactely :-) Maybe you’ll get satisfying results if you just use one overclocked Rpi and boblight. But I would recommend Hyperion anyway.

  10. Hi Alex, no you can’t. You need a LED SPI interface for the LEDs. But you could use an HDMI splitter and build this setup: http://techtalk.christian-moser.ch/wordpress/?p=562 instead. So you’ll be able to use a mac mini as mediacenter.

  11. I took on this project and I have everything connected but the LED strip only lights the first light which reacts anytime I touch the wires. Either by flickering through the colors or going off. the wire I used was 22 AWG. I feel like that should be enough, but should I be using 20 or 18 AWG? It seems that there is a bad connection but all seem stable. I’m going to see what I can do tonight, but wasn’t sure if you experienced anything similar or know what would cause that.

  12. Well, I have this behavior sometimes when my Rpi is powered off. I’d double check the connection to the SPI pins. Also check the hyperion config json, did you set the “output” to “/dev/spidev0.0″ (device section) or maybee your SPI interface is mapped to another index?

  13. Thanks for pointing me in the right direction. The dev was the key. They were not present and I found a post that mentioned you need to comment out the spi device line in /etc/modprobe.d/raspi-blacklist.conf. Once I did that and restarted hyperion the LED stip reacted to the android tool. Although, now it looks like the last 2-3ft section does’t change. just stays orange. I hope that doesn’t mean it’s bad…..took 3 weeks to come in from china and cost $110

  14. Great write-up… looking forward to building this out. One question for you… my TV and Pi are about 10 feet apart (the Pi’s sitting in a cabinet). Any suggestions on the type of wires I may need to support that length?

    Thanks,
    Sam

  15. Christian,
    What kind of GPIO connectors did you use? I was only able to find 6″ female jumper cables, so I’ll have to splice some additional wire to that and then splice again to the LED wires. Is that how you did it?

  16. Hi Christian,

    I’m fairly new to this and there’s something I don’t understand (it’s probably a stupid question) When you mention HDMI are you talking about the HDMI on the pi? How do you connect the pi to your TV? I connect mine via HDMI through an amp. Do I have to follow the other guide in order to make it work with my pi or is this guide enough?

    Thanks!

  17. I forgot to mention that I’m running XBMC openelec not raspbmc, will this guide work regardless?

    Thanks!

  18. Hi Fernando, sorry for the late reply but was in vacation overseas :-)

    If you just want the ambilight effect for content you do playback with XBMC running on your Rpi, this guide is all you need. It’s slightly different to install Hyperion on Openelec but it’s documented in the Hyperion wiki the rest of the process is identical.
    If you have other HDMI (video) sources for example PS3, XBox, blueray player etc, you’ll need to follow this guide as well.

    Regards, Chris

  19. Hi Sam, well we could calculate the voltage drop but I would go for the biggest jumper cross-section cable you can find. In addition, test the setup first with shorter cables, just to make sure your setup works. Then try it with the 10 feet. If you have issues, you can still play around with bigger cross-sections for the 10 feet.
    Regards, Chris

  20. Hi, I’m using “1 pin dual-female jumper” and “2 pin dual-female jumper” cables for the connection to the Rpi GPIO. Then I spliced them to the LED strip pigtail connector. I had to extend the wires to the appropriate length, the jumper cables were just 300 mm.
    Hope this helps, Chris

  21. The installation process of Hyperion is slightly different, check this guide.

  22. Hi Christian,

    Brilliant guide! I’ll be following it closely when my hardware arrives. One question: The guys at Hyperion have noted that they prefer to keep the power supply for the LEDs separate to the Pi. Naturally, in the example above, the supply is being shared between the LEDs and the Pi. What’s the easiest way to keep the supplied separate? Is it as simple as not connecting the GND to the GPIO?

    Thanks.

  23. Hi Josh,
    Thanks, I’ll wish you good luck! ;-) Yes, I went for a powerful power supply to power the LED’s and the Rpi, which works pretty well. If you go for the separate solution, just power up the Rpi by micro USB and don’t connect anything to the Rpi’s +5V/GND connectors. Then connect the LED power supply directly to the +5V/GND connectors of the LED strip.
    Regards, Christian

  24. Hello Mr. Moser,
    First of all I want to thank you for such a good tutorial for ambient lighting, very educational. I have a question, where are the jumper wires connected to from the GPIO? Does it go in the input side( from the left side/downward direction (looking from the back side) of the TV? I doubt that the LED Strip is connected in a loop all around.

    Thank you for your time.

  25. Hello, you’re welcome!

    I’m not quite sure if I got your question. You connect the GPIO connectors of the Rpi to the input side of the first LED strip. Then you connect the output of the first strip to the input of the second strip and so on.. The output of the last strip is left empty, so it’s not connected in a loop. You should mount the strips counter clockwise if you look from the back of the TV.

    Regards, Chris


Leave a comment

No trackbacks yet.