Sunday, May 18, 2014

DMX – The Complete Project.

DMX – The Complete Project.


This outlines the complete (or almost complete) steps for using a Raspberry Pi to control my garden lights. The outside lights use the DMX protocol, so as well as being able to generate different lighting moods; they can also really annoy the neighbors by turning my garden into a disco.

Figure 1: The obligatory picture of the control system

Figure 1 shows the inside of the control box. (I have a control box because my wife really, really, doesn’t like wires – so I have to hide away as much as I can). I’m using a RS485 USB device (around $10, using the Prolific PL2303 chipset), which you can see crammed in the bottom right corner, to control the DMX devices. I’m using the PiFace to turn on/off power to the lights. (I’m also using it to control some LEDs on the front of the control box, but the cables are not connected in the above picture). The big yellow thing on the right shows that I live in America, where twisting wires together is considered a sound connection. I’m using a nano wifi device (the blue light on the left). Also, I had to use a right-angle USB extension (which turned out to be left-angle) to attach the RS485 device, as the box wasn’t long enough. (I could have used a shorter SD card, but I don’t know if they exist)


The above is the basic schematic for the installation. The Raspberry Pi (Blue) is used to drive the RS485 with the DMX protocol. The green box represents the RS485 device, that drives the twisted pair cable that communicates to the lights. At the end of the twisted pair is the terminating resistor of questionable value (see below). The PiFace (Yellow) is used to turn on power to the lights. It also used to drive some of the status LEDs on the front of the control box, but that’s not shown in the schematic. The power supply is a notebook power supply. These tend to provide a lot of power in a small device and are somewhat more consumer friendly than the more industrial power supplies. (Plus, the one i used has a usb port, so I can power the Pi from that.)

Figure 2:  One of these lights

Figure 2 shows one of the lights. I should have put some sort of scale on this, as they’re “Rather Large”. They’re about 12” across. I wanted to light up my trees, so these are 15W RGB lights. Pretty powerful. The lights have four wires (Which in my case, were very well labelled). Two 24V and two DMX, labeled D+ and D-.

Wire turned out to be one of the most expensive parts of the project. I used 200’ of 16 gauge wire for the 24V DC and 200’ of twisted pair cable. I was going to make my own twisted pair, which I’d done during prototyping (using a post and a drill) but I found a reel that was relatively inexpensive. What I should have done was used Ethernet Cat5e cable – not because I needed 4 twisted pairs, but because it’s sooooo much cheaper than just one twisted pair, plus it probably is more durable when buried in the ground, plus, having underground Cat5e in your garden much cooler than, say, owning a Ferrari.

Figure 3: RS485

Figure 3 shows the RS485 device I used. The DMX protocol uses RS485 for the hardware/signaling side of the protocol. On top of that is a relatively simple protocol that uses BREAKs to signal the start of a packet followed by the data. I had to patch the PL2303 driver to support the DMX 250,000 baud rate and write a utility to generate the DMX packets. [Link]  I was waiting for my lights, so I ended up buying a $25 RGB DMX light off Amazon that I could play with. This was quite entertaining, and my daughter was quite amazed to find out that when you mix Red, Green and Blue light you get White. I created a web page so that I could control the lights and then added network support, so that standard DMX software could talk to the Raspberry Pi and control the lights. So far I’ve tested Vixen Lights 3 on my PC and AuroraDMX on my Andriod.

Installing the lights took about a day and a half. Most of the time was spent trenching and burying the cables. I have a ‘Black&Decker’ trencher and edger, so I used that for making the trench. It draws more of a line than actual trenching. I ended up sitting on a kid’s camping chair using paint stirring sticks to push the cables into place, but it worked. The nice thing is that the trencher didn’t get down deep enough to splice pipes or any other cables. The bad news is I don’t know if I’ll be able to aerate my lawn again.


I tested out the installation twice before burying the cable. Once in the house, where I was running into issues and ended up taking 100’ of twisted pair cable and had it going through an assortment of rooms in the house and once in the yard/garden, where I had it laid in position. DMX calls out for a 120 ohm terminating resistor on/after the last device. This is to stop the signal bouncing back. When you have a short run and a few devices, you’ll not need this, but once you get a long line of cable, it becomes an issue. When I did the test runs, I needed a larger resistor, around 150 ohms. Luckily I had these to hand. Once I buried the cables, this no longer worked. The lights I have go into an automatic mode when they’re not getting any commands, so it was pretty obvious that something was wrong.  Initially I thought that it was a loose cable and had the annoying experience of finding and fixing the loose cable only find out that it wasn’t the real issue. I ended up trying an assortment of resistors in different configurations until something worked. In my case, two 150 ohm resistors in parallel, so 75 ohms. Next time I think I’ll invest in a variable resistor/rheostat/potentiometer and use that to find out the correct resistance, and then connect up the right amount of resistance.

The reason for the 120 ohm resistor is based on the impedance of the cable. Obviously there’s some dark magic at hand that I don’t quite understand. maybe cables are like people, they put up less resistance when buried underground.


With the cable trenched, I installed the lights. I dug holes just slightly larger than the lights and filled it in with dry concrete. (I had to redo the lights a few weeks later, as while the lights had plenty of bedding, they didn’t have a whole lot of encasement on the side, so I dug a wider hole and filled that in with dry concrete. The rain took care of the rest). I was initially going to use a garden type control box for each junction, but in the end use some underground spicing devices, some electrical tape spray and wrapped it up in plastic – this appears to be working, but I’ll have to see how long they last.

With the lights installed and the testing complete, it was time to drill a hole in the side of the house and fish the cables through to the control box. I used the PiFace to control the power to the lights. The positive wire is connected to the “common” connection on relay#2 and the line to the lights is connected to the “open” side of the relay. (The side that’s not connected to common by default, you can see the lose screws in the picture above).  Note that the PiFace spec calls out 20 volts or 5 amps max, I’m 24v at about 3 amps, so I think I’m OK. (you can see in the picture above that the relays can cope with more. I assume the limitation is based in the traces on the PCB) It appears that all the PiFace documentation points you to perl.  I use the gpio utility, which can be slightly odd (“gpio –p write 200 1” sets the top relay on, but you need to use “gpio –p read 209” to read the current state of the relay).

The nitty-gritty inside the Raspberry Pi is difficult to take a picture of, so here’s a written version. I’ve modified /etc/rc.local to run the utilities that I need when the system boots up.

/usr/local/sbin/dmx -e &
/root/lights/lights.sh >/var/log/lights.log &

The /usr/local/sbin/dmx is the utility I created to talk the DMX protocol to the RS485 device. I’ve documented this in a separate blog/blogs. [link]. The ‘-e’ option enables E1.31 unicast network support.
The “lights.sh” is a shell script that is split into three parts. The first part calculates the amount of seconds until sunset and sleeps until sunset (garden lights being a more nocturnal activity). The second part turns the lights on and generates a random set of values for the lights. The third part shuts the lights down when it gets late.

Figure 4: Unimpressive Web Frontend

The webpage controls the power to the lights as well as the lights themselves. It’s quite unimpressive as I wanted to use the “slide” type (for reasons that currently escape me – I think to avoid huge wads of java script ). There’s some java script, mainly communicating to PHP scripts on the server that do the actual control of the lights and turning the relay on/off.  Really I should have a front end where you just select the color of the light you want (well, that’s what my wife wants).

Figure 5: Vixen pumping up my lights

As well as certain “staged” or set scenes for lights, you may want to pump up the jam/jelly. Figure 5 shows my take on the middle bridge(?) on “Hello”. I’m no expert on any DMX mixing/lighting software. I tend to learn how to use software by banging my head against it for a while and then giving up and reading the manual. In the case of DMXcontol and FreeStyler, they both look great but I didn’t make it over the first hurdle. I then took a look at Vixen.


Vixen appears to be the choice of people who want to overdo it on Christmas lights. I liked it because it kind of fit in with how I imagined DMX software would work. It has a timeline and you can plonk different effects on each light and it has a nice “Preview” that works. It also support “E1.31 Output Controller”, which is a pretty generic way of talking to lights over the network, so I updated the DMX utility to understand E1.31 and was able to make my lights sing and dance. (Link to setting up Vixen for use with theDMX utility). I’ve banged my head against it for a while, but I’ve not resorted to reading the manual...yet.


Figure 6: The finished control box. Power Supply on top.














No comments:

Post a Comment