loading

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.

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.

<p>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.</p>
<p>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.</p>
<p>I'm so glad you figured it out. If you have any other questions just ask me.</p><p>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.</p><p>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.</p><p>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.</p>
<p>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.</p>
<p style="margin-left: 20.0px;">Sorry for the late response... hope I didn't ruin your display with my timing.</p><p style="margin-left: 20.0px;">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 &quot;ON&quot; 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.</p><p style="margin-left: 20.0px;">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.</p>
<p>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.</p>
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.
<p>Could you please put a schematic for the transistor bank?</p>
<p>Yep it's now up in step 3. Enjoy!</p>
<p>Thanks!</p>
<p>Great writeup, thanks for sharing.</p><p>As another software alternative, have you checked out lightshowpi.org? It's great for synchronizing lights to music with a hardware setup like yours.</p>
<p>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.</p>
<p>This is a very nice 'ible. I think I might do this one year...</p><p>just a quick question though, I read through the instructable (rather fast) I did not see where/how the Pi was wired in.</p>
<p>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?</p>
<p>This would be great, along with some pictures. This way we could replicate your work.</p>
<p>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.</p>
<p>Just saw your google doc below. that worked for me. thanks.<br><br>For those who might not see it in the comment thread.<br>https://docs.google.com/file/d/0B5-HND9HJkXWSTQtYlFTZ3VyODA/edit</p>
<p>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.</p>
<p>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.</p>
I didn't even think about the dimming capability. Cool idea for some fading.
<p>OMG use opto couplers for controller to transistor. One power surge and poof no more anything</p>
<p>Could you identify the make and model of the terminal strip used?</p>
<p>these are just DIN rail terminal blocks and really, smaller ones would do, we are not passing much current through them. but some thing like this (http://www.mouser.com/ProductDetail/Phoenix-Contact/3212064/?qs=sGAEpiMZZMvNM%2fd3q5fCV%252bc01oLearQtVUVBHzw6%252b%252bc%3d) is comparable to what I have used.</p>
Seeing instructable really gets me thinking about make a lighting board to pair (just ditch the S2L because the LD in me just hates it) with this mini &quot;universe&quot; I would like know about the dimming capabilities of this project. Or would it require something with a bit more pwm pins?
<p>you could make a &quot;lighting board&quot; out of it. they would have to be switches, 'on' 'off', no faders on this type of circuit. This is a limitation not only with the pwm switches but the mechanical relays. So if you were to use solid state realys and map them to pwm pins and write some interpreter code for a number to pwm on the pi, probably already exists, then there would be full dimming capabilities. And yes, a lighting board would be really cool to use with this project so attaching DMX would also be needed.</p>
<p>Vixen appears to be only for a Window machine. Do you need both a Windows machine to run Vixen and then your RasPi? If Yes, how do they communicate?</p><p>Thanks!</p>
<p>The design of the display happens in vixen it then has an output text file that is run through the parsing file. The output of the parsing program is then put on the Pi. The vixen instructions are step 7 and the file structure info is in step 6.</p>
<p>Great!! I built this exact same setup a couple of years ago, first with Arduino and then last year with Raspberry Pi.</p><p>Here's the (admittedly ugly) code I used to do song sequencing and drive my &quot;light channels&quot;. https://github.com/nod/griswald</p>
<p>Looks Col, a cheap salution to controlling lights! But there is one thing that I thought of, here is littel peices of metal on each side of an outlet that if you brake off you can use each socket sepretley and that way you would need only 1/2 the outlets</p>
<p>That is definitely an option but it can be handy to have 2 outlets per circuit.</p>
I'm on the same page as pbhoud. I think elaborating on section 3/8 is important. Is there any way you could include some images of the pi and the wiring as you described? Aside from that, this is one of the nicest light/music instructables I've seen. Thank you!
<p>This will give you a good idea of how the transistors are wired between the Pi and the relay board. The relay board in this picture is 5v instead of 12v, so just ignore the voltage references.<br><br>https://docs.google.com/file/d/0B5-HND9HJkXWSTQtYlFTZ3VyODA/edit</p>
<p>That's an interesting way to do it. I'm not quite sure what TP1 and TP2 are but I used an extra power brick to power the Sain Smart board. I did post pictures of the transistor bank (step 3). I know they are not quite in focus and I can take more if you would like me to.</p>
<p>Look at the comment I left pbhound</p>

About This Instructable

30,525views

497favorites

License:

More by Jboth:ESP8266 for Beginners RPi Christmas Lights My Dream Room 
Add instructable to: