The LED Christmas lights I purchased operated using 3 AA cells, so you could place them safely anywhere without access to an electrical outlet. The battery box has a second, small, compartment that houses the control board that has a switch coming out the side. There are four positions for the switch: off, solid on, blinking, and a pulsing fade in and out.

The first thing I did was test that I could power the lights with 3.3V, since that's what I'd get off the Raspberry PI's GPIO pins. I simply connected the +/- terminals of the battery box to a hacked ATX power supply from a dead computer that I use for testing such things. (An ATX PSU has 3.3V, 5V, 12V and -12V outputs.) 3.3V illuminated the set of lights just fine, but they were a bit more dim than when using 4.5 V from cells. However I wasn't too worried about it.

Once it was determined that I could power the lights, I opened up the battery box, removed the control board, and desoldered it from the battery terminals. I then soldered on some longer lead wires, using black for neutral and red for power. I connected these directly to the Raspberry Pi GPIO pins. This may not be the safest thing to do when it comes to the preserving the longevity of the Raspberry Pi. After all, who knows what poor quality electronics were used to fabricate $3 Christmas lights? On the other hand, that's sort of the point of Raspberry Pi, isn't it? It's a $35 computer so if I wreck one or two during the learning process, then my mortgage isn't going to be affected. The system has been running for many months now, so I'm going to say that I lucked out here. Some quick use of the "gpio utility" that comes with the Wiring Pi library allowed me to test that the hardware modifications were working well with the Raspberry Pi's GPIO pins.

Speaking of Wiring Pi ... at this point I had already downloaded and built Gordon's great little library and gpio utility. It's very easy to setup and install. There are great instructions on the author's website. (See the link on the project page.)

One "feature" of my Christmas lights was that they automatically turned off after 5 or 6 hours to save battery life. Rather than make my own control board to replace the one it came with, I decided to fix this with software. I already had cron setup to check for updates on my computer every couple of hours. This script writes a small, hidden, text file to my home directory when I have a software update available. The last line of my .bashrc just cat's the content of this file every time I log into the Pi so I know how many packages are available. My plan was to update this script to turn on the lights when there was a software update. Since I'll be checking for updates every couple of hours, all I have to do is toggle the Christmas lights off and on if there's an update to make sure that I'm not affected by the 5 hour auto shut-off written into the micro controller on the LED driver board.

I used the Wiring Pi library to write a small app called "lights" that I install into /usr/local/bin and I gave my account sudo permissions to execute this program without a password. "lights on" turns on the lights and "light off" turns off the lights. Gordon's library makes it easy. It's in this little app that I toggle the GPIO pins off and on to make sure that the LEDs stay lit.

That's all the hard parts in place. My bash script is a utility that I keep maintaining for myself. It's not too complex if you know bash. Except for the syntax of the "test" command (the [square brackets] used for "if" conditions), bash reads pretty easy. I use some arguments to "apt-get dist-upgrade" combined with grep to compute a list of packages that need to be updated. Then I use the wc command to count how many package updates there are. Most of the script is just formatting output nicely.

I set up a crontab to execute my script to check for updates periodically. There's an example with my code. That's about it.

One more little detail. Since I...

Read more »