Introduction: Super Christmas Tree Lights

This year I bought a Christmas tree, first one I've ever owned in fact. So the next logical step was to decorate it. Looking around at

the options for lights I found there was actually no lights that did quite what I was wanting. All I wanted was some Christmas tree lights that could blink, and change colors, and be controlled from a phone, or a button, or voice, all 100% customization and re-programmable surely I could find something on amazon to do just that? But after much searching I found nothing of the sort so decided instead of giving up on the dream to make some do what I want myself. But enough of an introduction and onto how I did it. There are many changes and improvements you can make on how I did it, I encourage you to go and build your version using mine as a stepping stone, using the good parts and improving on the bad.

I plan to be adding to this project over the next month as the tree is up, so look for updates soon.

For supplies I used the following:

  • Raspberry Pi 3 (sd card, power supply)
  • Fadecandy LED board
  • WS2811 Addressable LEDs in Christmas tree light style form factor(not the common strips you find) I used eight 50LED strands
  • 5V 60A power supply and power cord
  • Wire Heat shrink
  • 3 Pin JST SM jumpers

For tools I used the following:

  • Soldering
  • Iron(solder, flux, etc)
  • Screwdriver
  • Wire cutters/strippers
  • Multimeter

Step 1: Power!

I had an extra 5V 60A power supply left over from a previous project so I used that, however you

can get away with a much smaller power supply depending on the number of LEDs you'll be driving. I could probably have used a 30A power supply and been alright at 500LEDs but given I already had a 60A supply that is what I used.

These common DC power supplies do not have power cords connected to them, so first you need to do that, start by cutting off the end of a power cord, you'll then use a multimeter to trace the pins on the C13(the female end) end to figure out which color corresponds to Neutral, which is Load and which is ground.

When looking end on and oriented to be two lower holes and one higher one the pin out should be the following. On top is the Ground pin, the left one is Neutral, the Right is Load. I encourage you if there is any doubt to check out a YouTube about doing this. Do be careful when dealing with electricity, especially high voltage such as what comes out of the walls.

Once you've identified which color is which you'll strip the insulation off the tip of the wire and secure them in their corresponding terminals. Before you plug in the supply confirm the switch on the side(if present) is set on 110V not 220V. At this point you will plug it in and confirm it powers on. If it does you'll then need to confirm the output, for this I used the multimeter to check the V+ and V- DC voltage. Mine was 5.5V when I measured it, I then adjusted the screw left of the terminals to bring that down closer to 5V.

Step 2: Prepare the LEDs

The LEDs I bought had 3 pin plugs on either end of the strip as well as dedicated ground/5V lines on each end.

First you need to identify the input end of the strip as they data only goes in one direction. On my strip that was the end with the male 3 pin plug, you can follow the wire from the plug and see if it connects to a Di(data in) or a Do(data out) pin.

Once that was done I trimmed the dedicated ground/5V line off the output side of the strand as I wouldn't be using that.

Next I Soldered roughly 2.5ft of 18ga wire to each of the Ground and 5V lines on the input side. In this step it's important to be consistent with color, I used yellow and red for my 5V and black/green for ground, if you inadvertently hook these up backwards you will damage your LEDs. After soldering all of the strips I added heat shrink to cover all the solder joints this protects them from shorting out on each other.

I did this process for all 8 of my LED strands. Then finally set them aside until later.

Tip If you leave them rubber banded up it makes a bit less of a mess.

Step 3: Prepare the Fadecandy Board

The Fadecandy board is a fantastic little board for driving addressable LEDs we'll get into some of it's abilities later on

but for now this is just about the physical setup of attaching it to the LEDs.

There are 8 output pins and 8 ground pins on the Fadecandy board, I started by soldering 2ft of black 22ga wire to all the ground pins. Next I soldered 2ft of yellow 22ga wire to the output(+) holes on the Fadecandy board.

I then coiled tapped the pairs of wires to make for a bit less of a mess for the next step.

I took 8 of the female 3 pin JST jumpers and removed the line that would match up with the 5V source on the lights, as this was not needed for the Fadecandy. On my particular jumpers that was the red wire.

Next I threaded heat shrink onto the Fadecandy wires(important to do this before soldering the wires together).

Finally I soldered the Fadecandy yellow wire to the data wire on the jumper(green in my case), and the Fadecandy ground(black) to the jumper ground(white). After soldering them I moved the heat shrink up cover the solder joint and heated it with a lighter to shrink it.

When done you should have somewhat of a spider with 8 pairs of wires coming off the Fadecandy and down to 3pin(or 2 pin if you removed the unused wire) connectors. Double check all your connections and that you don't have any mismatched wires then set this aside until later.

Step 4: RPi Setup

I am going to gloss over some of this as it's easy to get caught in the weeds as to raspian setup and such, so for basic getting a

rPi up and working and ssh to it refer to https://www.raspberrypi.org/help/

I will start at the point of having an rPi with a clean Raspian image and you being able to SSH into it and run the latest updates.

ran the usual update/upgrade command to ensure the rPi was upto date.

sudo apt-get -y update 

sudo apt-get -y upgrade

after that

sudo apt-get -y install git  
git clone git://github.com/scanlime/fadecandy
cd fadecandy/server  
make submodules  
make  
sudo mv fcserver /usr/local/bin 

next we need to make the program start automatically for that we do this:

 sudo nano /etc/rc.local 

and right before the final "exit 0" we place the following.

/usr/local/bin/fcserver /usr/local/bin/fcserver.json >/var/log/fcserver.log 2>&1 &

We will then need to create a configuration file

sudo nano /usr/local/bin/fcserver.json

and paste the following in, you'll need to replace YOURSERIALHERE with your board serial you can find your boards serial by typing the following

fcserver

it should list Serail# followed by your serial.

<p>{<br>        "listen": [null, 7890],
        "verbose": true,
 
        "color": {
                "gamma": 2.5,
                "whitepoint": [1, 1, 1]
        },
 
        "devices": [
                {
                        "type": "fadecandy",
                        "serial": "YOURSERIALHERE",
                        "map": [
                                [ 0,    0,   0, 50, "grb" ],
                                [ 0,   50,  64, 50, "grb" ],
                                [ 0,  100, 128, 50, "grb" ],
                                [ 0,  150, 192, 50, "grb" ],
                                [ 0,  200, 256, 50, "grb" ],
                                [ 0,  250, 320, 50, "grb" ],
                                [ 0,  300, 384, 50, "grb" ],
                                [ 0,  350, 448, 50, "grb" ]
                        ]
                }]
}</p>

finally you'll do a

  sudo reboot 

for more details on these steps please refer to adafruits excellent writeup here https://learn.adafruit.com/1500-neopixel-led-curt...

At this point your fadecandy server should be up and running.

Step 5: Plug It All Up and Hope There's No Smoke

There are two ways to go about this, first(and probably wisest) would be test each strand by its self and then combine them.

What I did was plug absolutely everything in, applied power and hopped for the best and it worked out okay. But if you're going to do it that way do be very confident in the prep work getting to this point(no mismatched wires).

Ensure all the power/ground leads from the strands are securely attached in the terminal blocks. Next plug in the fadecandy jumper wires which are keyed so only go in one way. Finally plug the fadecandy USB cable into the raspberrypi and power on the rPi.

At this point you're ready to plug in power to the main power supply. You should be greeted by... nothing If you have bright lights/smoke/noise/etc there's a problem.

If you have a bunch of nothing happening however congratulations.

The sky is the limit as far as code goes for this but what I started with was just some examples out of the fadecandy library to ensure the strips were working correctly From another computer I ran the http example thats in the fadecandy library we downloaded earlier(https://github.com/scanlime/fadecandy/blob/master/... will work, although you'll need to change the number of LEDs).

Making sure to change the localhost in the examples to the IP address of the RaspberryPi. At this point it's sorta up to you as to how much playing you want to do, I decided to hang the lights on the tree before going too far forward as that would give me a better view of what they would look like installed.

Step 6: Install the Lights Into the Tree.

At this point you'll need to disconnect everything you've done to this point, it's a pain but its good we checked for issues before

wiring up the tree and finding they don't work.

This part is fairly self explanatory, everyone will have their own preference on how to best do that, for me i basically installed them nearly vertical up the tree from bottom to top roughly every 30deg(as about 90deg of my tree is unseen). Make sure to leave enough room to be able to attach the power/signal wires we had setup before.

Once that are done it comes time to reattach the wires as we did before, being careful about the power connections and the signal wires.

Also at this point it's important to keep track of the signal wires order, I did 0-7 starting on the left most strand and working to the right most strand.

Step 7: Light the Tree!

Now you have everything installed in the tree and checked all the connections you can power it all up and watch the show, of course it'll be blank again like two steps ago until you kick off something to talk to the fadecandy server. The quickest way is in the next step so go check that out.

Step 8: Easy Cellphone Control

So you have the tree all strung up(which can be a mess of wires i'll admit) and everything plugged back in, raspberry pi running and ready to go. Here's a quick way to test it. This app whitten by Bertrand Martel does a fantastic job at controlling the fadecandy board https://play.google.com/store/apps/details?id=fr.b...

After installing do the following.

  1. Make sure you're on the same WiFi network as the rPi
  2. Start the app, click on the hamburge button in the top left
  3. click server configuration
  4. uncheck "start a local server"
  5. type in the Server IP address as the IP of the Raspberry Pi
  6. hit okay
  7. Click the hamberger button again
  8. Click on "led count configuration" and type in 500 then select Ok

At this point you'll have basic control of the lights from your cellphone.

Step 9: Code Code and More Code

Building on what we did earlier now that the lights are in place its time to work more with the code.

I started out thinking it would be cool to just have a website hosted on the rPi where I would open it on my cellphone or computer and change the lights there, and that may still happen depending on how much time i get in the next few weeks. But for now I decided in the interest of getting this project to a working state and keeping things simple I would do the following.

  • Define a few patterns which can be toggled to run
  • Setup the rPi to listen for MQTT messages telling it which patters to run

This route makes toggling the tree easy from the rest of my home automation projects, and opens a lot of options as for tieing in triggers to tell the tree to do things.

I am going to gloss over the MQTT settings, there is a lot of useful detailed instructions out there on how to set it up please do refer to those in doing this, I am not very knowledgeable about MQTT so I will be deferring to those who are as to how to get your rPi hosting a mosquitto broker. I used the following to get mine working:

https://www.instructables.com/id/How-to-Use-MQTT-W...

Okay now we have MQTT broker running and a python script listening for commands, it's time we define a few. For this again I drew off the fantastic examples in the fadecandy library. But overall it's pretty basic you need.

import opc
numLEDs = 400
client = opc.Client('YOURrPiIPhere:7890')

(stuff)

pixels[i] = (rgb)
client.put_pixels(pixels)
<br>

Of course there's a lot admitted from this above block of code, but the (stuff) is just whatever you decide to do in order to define your pattern, if that's a rainbow, or a chase light etc all up to you. Time permitting i'll be writing a few patterns and will upload them here soon.

Step 10: RGB Button Control

A friend has this very cool project he's been working on that is a board that sits in a push button that gives that big button RGB led's here you can check it out on github https://github.com/tylercrumpton/rgbeep

I have one of his prototypes and though this would be a fantastic way to use it, my goal was to have the button slowly cycling through colors, and when pressed it would turn the tree whatever color it was when pressed.

Here is my button. I 3D printed a base for it, right now it is USB powered but may make it batter powered at some point in the future.

Attached is the code I wrote for the button that cycles through the rainbow and when the button is pressed toggled a MQTT message to be sent to the RaspberryPi with the current color.

With this running i can just plug the button into a usb power outlet or battery pack and control the tree wirelessly as the MQTT message gets sent via WiFi.

Thanks all for checking out this project, please let me know if you have any questions I'll do my best to answer. Looking forward to seeing your projects.

Wireless Contest

Participated in the
Wireless Contest

Raspberry Pi Contest 2017

Participated in the
Raspberry Pi Contest 2017

LED Contest 2017

Participated in the
LED Contest 2017