Raspberry GPIO Xmas Tree Add-on


Andrew Gale from PocketMoneyTronics.co.uk kindly sent me a GPIO Xmas Tree kit. Today I soldered it up with my son so we could get it set up for Christmas. The plan was to attach it to a Model A+ and power it with a USB battery pack.

The kit includes the tree PCB, 6 red LEDs, 1 yellow LED, 4 resistors and 1 2×3 header. It’s fairly easy to solder and a great kit for someone wanting to learn soldering.


P1020827With 7 LEDs you would expect the tree to require 7 GPIO pins but it uses a technique called “Charlieplexing” to control them with only 4. Andrew explains a bit more about this on his “Charlieplexing on the GPIO Xmas Tree” page.

However you don’t really need to go into this if you don’t want to as the example Python scripts can be used to get your tree working as soon as you have soldered it.

Software Setup

Here’s the sequence of steps I used to get the example scripts running :

Create and browse to a folder called “xmas” :

mkdir xmas
cd xmas

Download the files from the web :

wget http://www.pocketmoneytronics.co.uk/downloads/xmas.zip

Extract the zip file to the current directory :

unzip xmas.zip

This will give you some example scripts. Type “ls” to see a list of files.

You can run the examples using :

sudo python example_5.py

You should see something like this :

Modified Script

P1020826In order to create a battery powered Christmas tree I needed a script that would start when the Pi was powered up and allow it to be shutdown without a keyboard or monitor.

To do this I fitted a BerryClip and modified example_5.py to exit and shutdown when the red switch was pressed.

You can download my modified script directly to your Pi using :

wget https://bitbucket.org/MattHawkinsUK/rpispy-misc/raw/master/python/xmastree.py

Make sure you download it while in the “/home/pi/xmas” directory.

Autorun On Boot

To run the script automatically when the Pi boots you can use ‘cron’. To edit it we use the command :

sudo crontab -e

Using your cursor keys scroll to the bottom and add the following line :

@reboot python /home/pi/xmas/xmastree.py &

Make sure you get this line correct as the script will fail to run on boot if there are any mistakes. “xmastree.py” should be

To save these changes click “CTRL-X”, then “Y” and finally “Return”. You should now be back at the command prompt.

To start testing you can now reboot using :

sudo reboot

The tree lights should randomly illuminate and pressing the switch attached to GPIO25 will shutdown the Pi.

GPIO Christmas Tree

The GPIO Xmas Tree kit is available from DawnRobotics.co.uk.


1 Comment

Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.