Introduction: Pumpkin Pi Digital Decoration Controller
Hello folks, let me introduce you to the Pumpkin Pi. Simply put it is an I/O controller for the Raspberry Pi with twelve programmable outputs, but with a little hocus-pocus (or Python code to you and me) it becomes a digital decoration controller that offers two video outputs with audio, and lighting FX synced to video.
Last Halloween I decided to create a Witching themed window display, having recently discovered AtmosFX's Digital Decorations I felt inspired to make good use of them and incorporate them into my display.
I needed a way of playing back two video playlists alternately on two different displays (a TV and a projector) without the videos accidentally overlapping each other. I also wanted to integrate lighting FX to add to the atmospherics.
More about the Controller
As it was inspired by a Halloween project I felt the name Pumpkin Pi was very appropriate. It is intended to do the following:
- Control up to 12x individual LEDs (or 4x RGB strips) via 12x programmable outputs
- Operate at 12v via its own external power supply
- 3x quad NPN transistor arrays to support 1 Amp output current per connection
- Include the option of PIR / motion sensor triggering of playback and actions
- Video and Audio playback using the video capabilities of the Raspberry Pi
- Two videos can be played back simultaneously or alternately thanks to both Pis being linked via their GPIOs to trigger programmable actions and prevent unwanted video overlap
- Sync lighting FX to the video playback
- Built-in LEDs to indicate individual output status
You can also use the Pumpkin Pi as a breakout board with a single Raspberry Pi and still have 12x programmable outputs to control LEDs, motors, relays etc.
Note: Want to see how I used the Pumpkin Pi in my Halloween display? Check out my Witching Hour Halloween Display Instructable.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Things You'll Need
To re-create the Pumpkin Pi you will need the following tools and components:
- Soldering Iron
- Wire cutters
- Screwdriver (I used a small flat-blade with my terminal blocks)
- Drill and drill-bits (I used 0.7mm and 1.0mm carbide bits)
- PCB Etching Kit
- 1x Copper PCB Board (102mm X 70mm approx.)
- 14x 1kΩ Resistors
- 2x 10kΩ Resistors
- 1x 4k7Ω Resistor
- 1x Capacitor (Optional)
- 1x Red 5mm LED and a suitable current limiting resistor
- 12x Yellow 5mm LEDs with integrated resistor for 12v supply
- 3x ULN2074B Quad NPN Darlington Pair Transistor Arrays
- 3x 16-Way IC Socket
- 1x DC Jack
- 1x 2-Way Header
- 2x 40-Pin 2x20 Male Header
- 7x 3-Way 5mm Vertical PCB Mount Screw Terminal Block
- 1x PIR Sensor (Optional)
The Raspberry Pi
You will also need a Raspberry Pi (or two) with everything that's necessary to utilize the Pi. This includes the Pi power supply, MicroSD card and the Raspbian software. For best video performance I would recommend the Raspberry Pi 3.
For video playback we will be using the OMXPlayer with the OMXPlayer-Wrapper (but more on this later!).
Note: This Instructable assumes that you have some experience or working knowledge of Electronics, Soldering, PCB fabrication and the Raspberry Pi. If you are attempting any of these skills for the first time I would recommend you take a look at some of the following resources:
- Electronics Class. Includes a Getting Started guide and covers things like soldering and basic components.
- PCB Making Instructable by ASCAS. Covers the toner transfer fabrication technique used here.
- If you want to go further with Circuit Boards, check out the Circuit Board Design Class.
- Raspberry Pi Class. Find out about the Raspberry Pi, learn how to get set up and how to use it.
Step 2: The Electronics
Creating the Circuit
The first thing you'll need to do is create your circuit. The easiest way to re-produce it is to fabricate the PCB using the toner transfer method with the attached printable circuit PDFs. If you haven't tried this before it's a lot easier than you might think, and you only need a few items to get started. I always recommend the DIY Customized Circuit Board (PCB Making) Instructable by ASCAS.
Note: I've also included the PCB design file that I created using DesignSpark.
You'll need a soldering iron and some basic soldering skills to assemble everything on the PCB, there are plenty of Instructables on soldering in case you are new to it, there's a good Instructables Electronics Class too!
If the PCB making process isn't for you then you can also re-create it on strip (vero) board or on a breadboard (I breadboarded my prototype, as shown in the above image). In my prototype I used individual NPN darlington pair transistors as opposed to the transistor arrays on an I.C. (integrated circuit).
How it Works
It is basically a breakout board for the Pi that connects twelve of the Pi's GPIO pins to NPN darlington pair transistors (in the form of three transistor arrays). When the relevant Pi output goes high, it switches the transistor to complete the circuit.
There are also two more GPIO pins that 'link' the two Pis together via pull-down resistors that act as triggers (more on this in the 'Programming the Pi' step later).
How is it Powered
The Pumpkin Pi is powered from its own external 12v power supply. With the use of the transistors I selected it is capable of up to 1.75 Amp current per output (or 1 Amp in this case due to my choice of screw terminals). The Pis are powered via their own Pi power supplies, the Pumpkin Pi puts very little demand on the Pi's power capabilities as it is only used to switch transistors. The circuit includes the option of a smoothing capacitor, but it's not essential. I used a 2200uF rated at 16v (which is overkill, but I had them to hand).
Indicator LEDs and Resistors
There are twelve yellow output indicator LEDs and one red power status LED. Be sure to use the correct current limiting LED with your red status LED, mine has a forward voltage of 3.2v and a forward current of 20mA, so I selected a 470Ω resistor (based on the 12v input current). If you are unsure of how to select the correct resistor for your LED, check out this calculator wizard.
You may have noticed that there are no resistors on the circuit for each of the twelve yellow indicator LEDs. As I wanted to save space on the PCB I made a design choice to use LEDs with integrated resistors for 12v supply.
Motion Trigger (PIR Sensor) and Override
The circuit includes the option of a motion trigger. It utilises a pull-up resistor, so whenever the alarm pin (labelled as AL on the PCB) goes low it triggers an action. This comes in handy if you want your digital decoration playback to be motion activated.
The circuit also includes a trigger override. When the override is in a closed state it ties the input to ground, allowing you to manually trigger the action. Use the two-pin override header with a switch or a 'jumper'.
Step 3: Setting Up the Raspberry Pi
To begin setting up the Raspberry Pi you need to prepare your MicroSD card with the Raspbian image. Download the latest image here (Raspbian Stretch was the latest version at the time of writing).
With your MicroSD card ready, insert it into the Pi and power up. You'll probably want a TV, keyboard and mouse connected at this point. By default the Pi should boot into the GUI desktop OS, I recommend you set the correct date and time zone on your Pi and maybe get connected to your WiFi.
At this point I usually make sure SSH connectivity is enabled so I can access the Pi terminal over the network via PuTTy, then I set the Pi to boot to the CLI (command-line interface) by default instead of the GUI desktop, but this is up to you.
Note: This Instructable assumes that you are already familiar with the Raspberry Pi, if not you can follow the official Raspberry Pi guide for installing operating system images in your environment here: Windows, MacOS, Linux.
Tip: If you are completely new to the Raspberry Pi I recommend you take a look at this Instructables Class.
Once your Pi is up and running with Raspbian and the basic set-up is complete, you are ready to get it to work as a Digital Decoration player that supports Audio and Video playback. Remember that if you are using two Raspberry Pi's for dual playback functionality, you will need to repeat all of these steps on the second Pi.
OMXPlayer-Wrapper for Python
To play our Digital Decoration videos we will be using OMXPlayer. This supports high-resolution videos (including HD) in a number of common video formats. Although OMXPlayer is included with Raspbian 'out-of-the-box', to make it play nice with the custom Python scripts we'll be creating you'll need to install the OMXPlayer-Wrapper.
Before installing the wrapper I recommend updating the system's packages. Run the following commands from a CLI terminal (the Pi must be connected to the internet for this to work):
Update the system's package list:
sudo apt-get update
Upgrade all of your installed packages to the latest versions:
sudo apt-get dist-upgrade
Clean-up the space used to download update packages:
sudo apt-get clean
Next you'll want to download the OMXPlayer-Wrapper itself. To do this run the following command, again from a CLI terminal with the Pi connected to the internet:
Install the OMXPlayer-Wrapper:
sudo python3 -m pip install omxplayer-wrapper
For more information on the omxplayer-wrapper check out the docs here.
Tip: If you encounter DBUS connection errors when trying to play videos using the OMXPlayer-Wrapper, try installing the python3-dbus with the following command:
sudo apt-get install python3-dbus
Other Settings and Tweaks
Default Audio Output
The Raspberry Pi supports audio playback via HDMI or the 3.5mm jack. However if the Pi detects that the connected HDMI device supports audio it will default to the HDMI device. If like me you have a audio capable HDMI device but you want your audio output to default to the 3.5mm jack instead, you can force it to do so by adding the following line to the config.txt file on the Pi:
Set Console Output to Blank
If you don't want the Pi's video output to display the console screen after boot up you can set the console to blank by adding the following to the end of the /boot/cmdline.txt file on the Pi. Note that is is a kernel command parameter and must be on a single line of text:
Step 4: Using the Controller - the Basics
To test the functionality of the Pumpkin Pi I have created a simple test script. It will turn each output on and off in turn, then it will turn all of them on simultaneously and fade out using PWM. The test script is attached, copy it to the Pi then execute the script with the following command (note that sudo is required for Python to interact with the Pi's GPIO pins):
sudo python Lights_Test.py
Note: The Pi doesn't have twelve hardware PWM outputs, this functionality is emulated in software.
Each output is labelled as 'output1' through to 'output12', with each output mapped to the following GPIO pins using BCM numbering (note that this is different to the physical board numbering):
- Output 1 = GPIO 17
- Output 2 = GPIO 27
- Output 3 = GPIO 22
- Output 4 = GPIO 5
- Output 5 = GPIO 6
- Output 6 = GPIO 13
- Output 7 = GPIO 19
- Output 8 = GPIO 26
- Output 9 = GPIO 12
- Output 10 = GPIO 25
- Output 11 = GPIO 24
- Output 12 = GPIO 23
Tip: For more information on BCM and physical board numbering, read this Raspberry Pi GPIO Pinout guide.
With every output that is enabled the corresponding yellow indicator LED(s) should illuminate to signal that the output is on. These indicators can come in very handy when testing your Python scripts.
Assuming everything worked fine on your light test, your Digital Decoration controller should be good to go!
Step 5: Using the Controller - Video Playback
Following a successful light test you should be ready to start experimenting with the video playback and making the LEDs illuminate in sync with your video. For my display I used 'The Witching Hour' and the 'Jack-O'-Lantern Jamboree' from AtmosFX. If you haven't seen it already, check out my Halloween Window Display to see everything in action.
Tip: I use PuTTy to SSH into my Pi's terminal, this helps debug any problems that might occur as it allows me to see what's going on when the Python scripts are running.
I've attached both of the scripts that I used, one for the Witch video sequences (master) and the other for the Pumpkin sequences (slave). My code is commented, but I'll do my best to explain some of it in more detail here too.
The below section sets the GPIO pins to BCM mode, it defines the PIR_PIN variable as pin 18(this is the motion sensor input with a pull-up resistor), then PI_RX and PI_TX as pins 20 and 21 (these are what links both the Pi's GPIO's to act as triggers):
PIR_PIN = 18
PI_RX = 20
PI_TX = 21
In the next section I define each video file that I've copied to the Pi, this includes its variable name and the full path:
Witch1 = '/home/pi/Videos/WitchWickedBrew_Spell.mp4'
Next the outputs for the LEDs are defined, much like the light test we did previously, just with different variable names:
bottom_red = GPIO.PWM(23,100)
bottom_green = GPIO.PWM(22,100)
bottom_blue = GPIO.PWM(27,100)
Next is the initialization sequence, it runs a While loop that waits for the PI_RX pin to go high, this is a signal from the second Pi that it is ready:
while GPIO.input(PI_RX) == 0:
print("Waiting for Slave")
Now it will begin the video playing sequence, the command to play the 'Witch1' video via the OMXPlayer-wrapper is:
player = OMXPlayer(Intro1, args=['--no-osd', '--loop', '--blank'])
Before moving on to the next video it will wait for a trigger from the motion sensor / PIR, this is done using another While loop:
while GPIO.input(PIR_PIN) == 1:
print("Waiting for PIR Detection")
To switch between videos we use the same instance of the OMXPlayer as defined earlier, but we use the following command to stop and load new video files:
The LEDs are synced to the video by using the sleep command during video playback to trigger lighting FX at the appropriate times. For example, in the Witch5 video there is a lightning flash that occurs 32 seconds after the start of the video. We use the following code to start the video then simulate a lightning flash with the LEDs:
In short, you need to know the runtime of each of your videos and at what time in that video the event that requires a lighting FX takes place. It's a little tedious and can be time consuming, but it works!
The whole video playing code sequences are wrapped within a While loop, so when it completes the final video it will start over and loop unless there is a CTRL+C keyboard interrupt via the SSH console:
print('Halloween Media Player Interrupted, QUIT')
player.quit() # Kill the `omxplayer` process gracefully.
GPIO.cleanup() # Exit GPIO cleanly
The final step is to integrate the digital decoration controller into your display. To achieve this everything needs to be hooked up correctly.
I used two Pi's, the GPIO headers of both are connected to the Pumpkin Pi with a couple of ribbon cables. One of the Raspberry Pi's are then connected to the HDMI port of a TV, the other to a projector. The audio from both Pi's is played through an amplifier, connected via the 3.5mm audio out jack. The LEDs are connected to the negative and positive screw terminals, while the PIR motion sensor is connected to the AL, + and - terminals. Use the appropriate external power supply with each of the Pi's (5v) and the Pumpkin Pi (12v), then you should be all set.
I hope the Instructable made sense, feel free to ask questions if anything needs to be made clearer, as always I endeavor to reply to every comment and question I receive. Thanks for reading!