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).
Runner Up in the
Digital Life 101 Challenge
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
- Raspberry Pi (as though I needed to say it
- Breakout Ribbon Cable (I suppose not essential unless you enjoy being sane!)
- Jumper Cables (both male-to-male and male-to-female)
- Prototyping Board
- 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
- 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.
We have a be nice policy.
Please be positive and constructive.