RPi Christmas Lights





Introduction: RPi Christmas Lights

About 2 years ago I found these amazing little computers. I saw the IO pins and thought how cool is that that I now have a real computer that I can interact directly with the world around me. At the same time I was beginning to get into stage tech (sound and lights), which I still love. and I thought to myself: how crazy would it be if i could control these lights with a Raspberry Pi, really crazy.

Well I fell short of that exact goal but rather took it into a different direction. I thought about my favorite holiday, Christmas, and it hit me that I could make a Christmas lights display that would be "choreographed" and well that's when I began to research and put together what you will see here.

There Is A Lot Of Reading But It Is All Important.

Please read everything so that you don't run into problems and even if you do you wont sound silly when you ask for help.

This Project Uses Electricity

Remember that electricity is dangerous and... (the usual disclaimer nonsense that no one reads).

Step 1: Bringing Together the Pieces

This step can be a little tricky as there are so many ways to do this project; mainly the electrical wiring for the control box.

Essentials to the project

  1. Raspberry Pi (as though I needed to say it
  2. Breakout Ribbon Cable (I suppose not essential unless you enjoy being sane!)
  3. Jumper Cables (both male-to-male and male-to-female)
  4. Prototyping Board
  5. Resistors
  6. Transistors
  7. Sainsmart 16 Channel Relay Board

This list does not include the items needed to make the electrical box that the lights plug into. Mainly because there are so many ways to make it. although I will put pictures and explanations of how it needs to be done.

Step 2: Lets Start With Hardware (Electrical Box)

This sections materials are not spelled out in the Instructable because there are so many ways of wiring and so many ways to make the box its not even funny. But here is the way I did it.

I would like to thank Bill Ringel, Head Electrician at Rockhurst University, for putting time into the implementation and design of the main electrical box.

We began connecting the outlet double duplex boxes to the main metal box. To this we added the duplex outlets, see all of the grounding wires for SAFETY, and ran individual wires for both plugins back into the box, notice all of the labels on the cables. After we wired all of these we added terminal strips into the box.

These easy to use strips allow you to bring in electricity, like from an extension cable that you cut the female side off of, and attach the hot, black wire, to the gray, notice that it is through a fuse for SAFETY, and then connect a bunch, 18 in this case, of parallel circuits off of it.

To this we put the Sainsmart board next to the terminal blocks, make sure to use standoffs to the board is not shorted out. Connect the hot terminal to the normally open terminal, there is a picture on the board (_/ _) and you want to be connected to the right side of this. To the Sainsmart board we attach the cable from the matching duplex outlet, label everything it makes your life so much easier the board is already labeled, to the center post of the relay. Repeat this for all of the duplexes and that is all tidied up.

just in case you got lost in all of the words the electricity goes: power cable |~> terminal strip |~> relay |~> duplex

Forgot to mention a few things. Remember about the neutral line in the wiring. We also added a box that was directly connected back to the terminal strip so that they always had power, this is for the Sainsmart board and the RPi.

Step 3: Lets Start With Hardware (Transistor Bank)

The Sainsmart board relays are "closed" by bringing the corresponding pin on the board header to ground, the board also needs a 12V power supply. To do this we can use transistors, PNP's (learn more about the difference here), to switch the pins to ground.

This was really confusing at first for me so if you have questions that I don't answer please leave a comment.

To start we attach a ribbon cable, makes it easier for me, to the Sainsmart board header pins. Attach the pins labeled GND to the negative strip on the negative strip on the breadboard. Next we connect the negative strip to one of the outer legs of the transistor the red connector. Connect the other leg of the transistor to one of the pins of the Sainsmart board through a resistor does not really matter the value. the center post of the transistor is connected to the RPi (we'll talk about this latter). Label or keep track of which relay is attached to which of the transistors.

Step 4: Now for the Software (RPi Setup)

For this we need to do the standard setup for a Raspberry Pi. This is incredibly well documented on the RPi website.

To get started install Raspbian. Here are the instructions.

Go ahead and allow FTP, makes working with the pi easier not to have to be in front of it/ use another computer.

Please test to make sure both of these things are working. And continue testing at all points throughout the project.

Step 5: Now for More Software

This part can get a little bit tricky; so read this once or twice before doing it.

We design what our lights will do with the music in a program called Vixen. Download Vixen 2, it has the functionality that we want. (get it here)

There are also two additional scripts that you will need that I have written. They are python so you will also need python.


Vixen Interpreter (lights parsing below)

Main playing script (main below)

These scripts will be used in their respective order. The vixen interpreter will be used for a special file we get from vixen and interpret it so that it will execute faster on the pi. The main playing script will go on the pi and it will run the new files, created by the interpreter, and play the music along with it.

THE SECOND SCRIPT IS HARDWARE SPECIFIC. If your hardware is set different than what is here then the scripts will have to be re-written to some extent. IT IS ALSO FILE STRUCTURE SPECIFIC. The files must be put in the correct places and the script will need to be updated to match. We will talk about this in just a moment.

Step 6: Pi Work

We have the files that run the pi, and now they need to be setup in the correct places.

The script will need to be updated to match where everything on the pi is located.

The randomsong function will need the location of the control files from the vixen interpreter.

As will the fileprocess function.

The play_song function will need the location of music files. (Please be aware of the limitations of the pygame music module as far as the type of music files)

And if you want ambient music between songs, you probably will, the name of the file in the pygame.mixer.music.load function towards the bottom.

After all of that we will also need to make a daemon (instructions here) to be able to run the script on start up. This just allows us to plug the pi in and it will run, we do not need to access the pi on location of the display and the main script to begin running.

The next, and final bit of this work, is to attach the transistor bank that we made to the PI. This will be configured in a one-to-one mapping type setup: that means that the first relay will go to the first IO pin (BMC setup) on the Pi.

If any of this is fuzzy or hard to understand please leave a comment and I will attempt to help in any way I can.

Step 7: Vixen "work"

This is where the creative fun work comes in.

Look at the space that you have available to for the display and the lights that are available. Now design something (e.g. frame a window, drop some "pillars," make a pumpkin face) write numbers on the pic so that you know which channel/plugin to turn on. Make sure that you write it all these cool ideas down!!

Open a new project in Vixen and make a profile for the pi (sure tell it that there are 16 channels to control) (these are also a binary type lights which means there is only on/off so no gradients).

Go out and find the music file for the display. Put it in vixen ( the weird squiggly line on the top-ish left). Now go nuts have fun with it.

...After designing the display and telling the lights when and when to turn on/off go into the profiles tab and manage a profile and edit the one you made. click on the output plugins button and find the event data logger and add it to the profile. when you double click on this output plugin it will ask if you want to view or clear the log, clear it.

Now exit out of all of that and play the entire song from beginning to end without changing anything. Now get back to the data logger and view it. Save this file as the name of the song somewhere where you will remember.

Run the Vixen Interpreter with the file we just saved.

And finally move the file over to the pi in the control files folder made earlier along with the music file used to the music folder.

Step 8: Setup and Watch the Pretty Lights

Above is a video of one of my Halloween displays.

String out the lights where they were designed to go (remember the sketch make earlier?) and either extension them or string them to the box and plug them into the plugin assigned to it earlier.

Once this is done if a daemon was set up then just plug in and it will run all by its self!!! (otherwise access it and run the main script)

If it worked than CONGRATS!!

If it didn't work comment and I will trouble shoot the problem with you.

Step 9: Cool Add on Ideas

  • Use solid state relays and work on dimming capabilities with PWM pins
  • Add MIDI capabilities
    • file process
    • live midi input from instrument
  • Website
    • people watching could choose the next song to play

This is just a list of things I think would be interesting to add and to the project to make it a more interesting display.

Digital Life 101 Challenge

Runner Up in the
Digital Life 101 Challenge



    • Clocks Contest

      Clocks Contest
    • Oil Contest

      Oil Contest
    • Creative Misuse Contest

      Creative Misuse Contest

    34 Discussions

    Could you please explain the software a little more? What do I export the sequence from vixen as? .fseq? .tim? I have edited the main.py file to reflect my file locations but it locks up and I have to reboot as soon as I run it.

    5 replies

    Edit: I figured it out. I didn't have the controllers in Vixen set up right. You must set it up as a generic output.

    I'm so glad you figured it out. If you have any other questions just ask me.

    I do have to be honest. I recently had to re setup my RPi and I did not realize how tricky the Vixen part of this could be.

    Also some of my gpio pins are, I think, broken and that threw me for quite a loop. So i think an update is in order with a shift register instead of direct access to the gpio ports. This will also mediate the problem with the transistor nastiness. So be on the look out for that.

    I'm also working on something for the iot contest that is shaping up to be challenging and will also have relays, sensors, and the like.

    I actually have two more questions. What is the transistor bank for? I am using solid state relays plugged directly into my pi so the fact that they are SSRs could be why I don't need the transistor bank. How many relays are you able to trigger simultaneously? I can only trigger 4 at a time and then when I try to trigger the fifth one they all go out.

    Sorry for the late response... hope I didn't ruin your display with my timing.

    So the transistor bank is for that kind of problem. The Pi can only sink so much current and each of the SSR sends current to the Pi when you turn it "ON" and the Pi is being over driven. So the idea is to add a layer of isolation/protection from the Pi. Another option, instead of transistors, would be opto gates or a shift register would be even better, though the code would need to be rewritten a bit, as it would take up only 3-4 pins to use it.

    In essence your pi is being shorted out when you try to turn too many of them on at once and so the operating system fails and all that fun stuff.

    That make sense. Thanks for the reply. No worries on the display; I actually made it just for my christmas tree so I do not need too many strands on at once. I just made my vixen files have a maximum of 4 strands on at a time.


    1 year ago

    Go check out step 7. I am working on being able to use just the vixen filess, but that works for now. I'd love to see some pics of what you are working on.

    Could you please put a schematic for the transistor bank?

    2 replies

    Yep it's now up in step 3. Enjoy!

    Great writeup, thanks for sharing.

    As another software alternative, have you checked out lightshowpi.org? It's great for synchronizing lights to music with a hardware setup like yours.

    1 reply

    That is a neat piece of software. I like that it takes in midi files and I also don't: that could be awesome for live performances and save me a lot of time programming songs, but it would also require me to write or try and/or find midi files and be kind of at the mercy of pitch assignments instead of making the display do whatever I want. Pros and cons but thanks for showing me this I might use it for a live performance sometime.

    This is a very nice 'ible. I think I might do this one year...

    just a quick question though, I read through the instructable (rather fast) I did not see where/how the Pi was wired in.

    4 replies

    Step 6 second paragraph from the bottom it is attached through the transistors to the relay board. Do you think I should have a page just fro connecting the Pi to the rest?

    This would be great, along with some pictures. This way we could replicate your work.

    Getting pictures of this is really hard to do and would not make much sense. if you will use the BMC I/O pin map to find the first I/O pin, on B+ RPi its pin 3 (its index strangely, and connect this with the pin connected to the first relay on the header of the Sainsmart board. I know this is frustrating to not have pics but they would confuse you even more I promise you.

    Just saw your google doc below. that worked for me. thanks.

    For those who might not see it in the comment thread.

    The only problem I can see is the use of relays. They aren't going to last very long in this application (mechanical wear). I would probably have looked for a solid state relay option.

    2 replies

    That was a concern of mine when I first put it together. But this display has run for months, non-stop, and still works perfect. The solid state relay would be a better option for several reasons: 1. lifetime, as you pointed out 2. if they were attached to some pwm pins we could now do dimming of the channels, very fun.

    I didn't even think about the dimming capability. Cool idea for some fading.