GPIO Xmas Tree

The GPIO Xmas tree for the Raspberry Pi includes 5 LEDs that can be controlled from a simple Scratch or Python program. You can buy one from The Pi Hut or the Raspberry Pi Store in Cambridge.

The tree should be connected to the six GPIO pins as shown here. Ensure the LEDs are facing outwards:

When programming your tree, you need to know the GPIO pin number associated with each LED. Setting a GPIO to output high will turn the LED on whilst setting it low will turn it off.

Do you want to use Scratch 3 to control the LEDs on your tree? If so, click the Add an Extension icon, find Raspberry Pi GPIO and click on it. You can then drag blocks to construct either of the sample programs shown on this page (and click the green flag to run them).

To control the tree using Python, open Thonny and enter this example code:

    from gpiozero import LEDBoard
    from time import sleep

    tree = LEDBoard(26, 13, 6, 19, 5)

    while True:
        # illuminate the top and bottom LEDs
        tree.value = (1, 0, 1, 0, 1)
        # illuminate the middle row of LEDs
        tree.value = (0, 1, 0, 1, 0)



Here is the circuit diagram for the tree:



Here is another piece of Scratch code for you to try: