The Peek-a-boo camera demo uses the new Piduino board from skpang. As you move up to it, a little flap opens to expose a camera, it snaps your photo and shows it on the monitor with a random caption, then the flap closes again.
The picture above is of the prototype hardware that I built. SKPang has a much nicer production quality build project on show.
This software uses a zero-install setup based on the Piduino board from SKPang. The Arduino firmware monitors the analog reading from an IR proximity sensor. As you move closer to the device, it controls the Servo to open a flap, and behind this flap is a Raspberry Pi camera. The NeoPixels (driven by the Arduino) show different colours depending on if you are too close or too far away. When they go green, smile, and the camera takes your photo, then the flap closes again! Finally your photo is plastered on the monitor with a random caption.
This is a development from my original photo booth software.
No special setup or install is required to run this program, as it uses a new in-place firmware programmer that runs on the Pi to program the required firmware into the arduino chip on the Piduino board. Just download and run the Python, and it does everything for you.
To run the program, make sure you have done startx and open a LXTerminal window, then type:
sudo python Demo1.py
At this point, something I am particularly pleased with takes place. For the Raspberry Pi to communicate with the Piduino, a number of things must be correct. First, the right firmware needs to be programmed. The script checks to see what firmware is already loaded, and if it is wrong, it updates it automatically using the built-in SPI based programmer.
Secondly, the Raspberry Pi and the Arduino communicate with each other when running by using the serial port on the GPIO pins. This is by default configured as a login terminal when the Pi boots – so the script checks your configuration and if it is wrong, it edits those files for you and then reboots your Pi. Next time you run the program, it all just works.
Because I share all the same piduino code between each of my projects, instead of including it inside the code files below, there is a script you run that automatically fetches and unzips it from my blog. So first thing you should do is run
For the pedantic among you, this is not an install! All it is doing is downloading another zip file from this blog and unzipping it for you. I could include that inside the package below, but I want to manage the piduino programmer code in one place only. This is a sensible compromise. However, once you have all the files in the folder, you can zip those up and give them to someone else to try and they will have everything they need.
Secondly, you will need to enable your camera module before this works, if you have not already done so previously.
Choose the Enable Camera option then reboot when it tells you to.
Photo Booth reusable module
I developed most of the code for this project without even having a Raspberry Pi camera to hand. I’ve since bought one, but I though that the way I developed this software was instructive enough to tell a short story about it, as it is representative of how I develop software professionally.
Most of the systems I design software for, are designed before the hardware is even available. This means that I have to find some way to “mock” or “simulate” the hardware, so that software development can progress. In an ideal world, when the hardware turns up, I just change a setting in the software, re-run it, and it works on the real hardware. In many cases this is not quite the case and there are still some things to fix, but I have had a few really good “worked first time” successes in my career as an embedded software engineer!
To do this “mocking”, I created a module called MockPhotoBooth. It has a set of useful function calls as follows:
setup() - sets up the screen viewer ready for use clearScreen() - makes the screen go black takePhoto() - takes a single photo and stores in a file image.gif, and then displays it on the screen addCaption(text) - adds the text as a caption over the top of the screen finished() - closes down anything that was opened.
This is my user API for the photobooth. It’s basically a module with a set of functions that do all the things I want the photobooth to do, and it completely wraps the code from my original photobooth project linked earlier.
Inside Demo1.py I import it like this:
import MockPhotoBooth as booth
And then whenever I want the booth to do something, I use it like this:
booth.setup() booth.takePhoto() booth.addCaption("you should have smiled")
So, this was how I developed and tested the flow of the main application without any camera hardware.
Finally, I bought a Camera, plugged it in, changed one line in my code to this to load in my “proper” photo booth module that talks to the real camera and drives the screen using pygame:
import PhotoBooth as booth
I ran it, and it all worked first time with the camera.
That’s how I develop software for my day-job, so why not do the same with my home projects! It’s great fun working this way, you should try it sometime!
 SKPang camera project writeup [TODO]
 peek-a-boo-camera-R47 – this is the code you need to download