Sunday, June 4, 2017

Raspberry Pi Photobooth with Bluetooth Printer and Wii Remote


This project is based on the Raspberry Pi Foundation All Seeing Pi Photobooth project. I wanted to add in the ability to print the photos to a small Bluetooth printer and to email them instead of tweeting them. I also added in the ability to control the Photobooth with a Wii remote. The Wii remote is useful when people want to stand back further from the Photobooth to take a picture.

For the printer I choose to go with an HP Sprocket Printer. This little printer was light, portable and ink-less. The photo is also a sticker, which added to the fun of the Photobooth. While the HP printer normally uses an app on the phone to send pictures to it, it can communicate over Bluetooth with the Raspberry Pi.

The code I tweaked/forked from the All Seeing Pi Photobooth is on my github. The Raspberry Pi foundation does a great job walking through the code and explaining everything. If you want a firm understanding of how the code works I suggest you walk through their tutorial.  In general, the changes/additions I made to the code were:

1) Added in the ability to print the photo
2) Added in the ability to email the photo
3) Added in support for the Wii Remote which includes the ability to go to the previous/next overlay, remove the overlays, take a picture and start a new picture
4) Added in some sound effects
5) Added in some graphics to the GUI
6) Added in some additional filters to overlay on the picture (note googly eyes on the dog below)
7) Uses a kill button to stop the Photobooth since it runs full screen




Materials I used

8.5" x 12" x 4" Wooden Box from Michael's
Buttons
Landzo 7" Touchscreen
PiCamera
Speaker (Optional, nice for camera sound effects)
Optional Button (used to kill the fullscreen Photobooth program)
HP Sprocket Printer (other Bluetooth printers may work, but I haven't tested them)
Chalkboard Paint
Raspberry Pi 3 
Original Wii Remote (NOT THE WII PLUS OR THIRD PARTY REMOTES-IT MAY NOT WORK)

3D Printed Parts

Landzo Touchscreen Case
Simple Pi Camera Mount 
Tripod Mount 


Build the Case

For my case I used a  8.5" x 12" x 4" wooden box from Michael's. It was just the right size to mount the 7" Screen with some room to spare for the buttons and the Raspberry Pi Camera. I designed and printed a case to hold the 7" touch screen and a little mount for the camera. In order to mount the box on a tri-pod, I printed out this tripod mount  and fastened it to the bottom. I also cut a hole in the back so I could access all the parts. Alternatively, you could put the lid for the box in the back and simply cut a little hole for the power to go out. After making all the holes in the box for the screen, buttons and camera I painted the box with black chalkboard paint. I decided to use chalkboard paint so I could change the design depending on the event.



Front with Pi Camera Mount


Attach the Buttons

For this project, I decided to use three buttons. Two buttons are mounted on the front. One cycles through the overlays/picture effects, and the second will take a picture. I attached the Overlay Button to GPIO 23 and the Print Button to GPIO 11. The buttons I chose light up, so each button is also connected to a 5V and Ground Pin. You could also just use a plain style arcade button and forgo the lighting.

I also placed a small reset button in the back and attached it to GPIO 13. This button will kill the Photobooth application since it launches in full screen mode. If you want to hear the sound effects, you can connect a small speaker to the audio jack in the Pi. I love this little speaker I ordered from Amazon. The charge seems to last a long time and does not need any external power to run.


 

Load the Libraries and Dependencies

My touchscreen came with an Raspbian image pre-configured for the touchscreen, however, any recent version of Raspbian should work. There are several libraries and packages that will need to be installed to get everything working. After running sudo apt-get update, run the following commands to get everything installed:

sudo apt-get install python-imaging-tk
sudo apt-get install python-cwiid


The above commands will add in support for Tkinter (the GUI) and the Wii Remote. Next, the following libraries are needed to support the Bluetooth printing:

sudo apt-get install python-pip python-dev ipython
sudo apt-get install bluetooth libbluetooth-dev
sudo pip install pybluez
sudo apt-get install obexftp

Connect and Test the HP Printer

Now that all the dependencies have been installed, let's connect and test the printer. Turn the printer on and  use the Bluetooth Icon to connect to the printer. If you hover over the device, you will see the MAC address in the dialog box. Write this down as it will be needed later:


After connecting, you may receive an error similar to the following. It's safe to ignore it. Mine seems to work fine regardless:


Now that is has been paired, test the printer to make sure you can send a picture to it. I just took a screenshot of my desktop for a test image to send. Open up a terminal and type in the following (make sure and put in your own MAC address)

obexftp --nopath --noconn --uuid none --bluetooth C4:30:00:00:7E:41 --channel 4 -p screenshot.png


If you have any issues, check out this detailed post by  Matt Richardson, which is where I was able to get this all figured out. If you install the HP Sprocket app on your phone, you can adjust some settings in the printer. By default, the printer turns off after 5 minutes or so. I turned this off so mine remained on the whole time. I also added a strip of Velcro to the underside of the printer to secure it to the top of the box.

Get the Pi-Photobooth scripts 

Make sure you are in the directory /home/pi and clone the repository for Pi-Photobooth:

git clone https://github.com/mdegrazia/Pi-Photobooth

There are four python scripts for the Photobooth program. The main one is photobooth.py. This one runs the Photobooth application and prints the pictures etc. When it launches, it will start up the photobooth_wii.py script as a separate process. The photobooth_wii script is responsible for connecting to the Wii remote. Once connected, it will monitor the buttons pressed and report back to the main script. The third script, overlay_functions.py is used by the photobooth.py script. It contains functions related to the picture overlays. The fourth script, monitor_gpio_buttons.py kills the photbooth application when the button in back is pressed.
 
After the code has downloaded, a couple of lines need to be edited in the photobooth.py file to customize it for your printer and email settings.

nano /home/pi/Pi-Photobooth/photobooth.py

Find the lines at the top of the code under "CHANGE ME", and put in the MAC Address from the printer, your gmail account username and password, and what you would like your email subject line to contain. (The code is currently written to support gmail. You may have to adjust the security settings on your gmail account to send emails from an application)


The  monitor_gpio_buttons.py script needs to start automatically. As mentioned before, this will be responsible for shutting down the Photobooth application when the button on back is pressed. I found this useful because there is no way to exit the Photobooth application when it's running.  To get it to start automatically, edit the crontab file:

sudo crontab -e
@reboot sudo python /home/pi/Pi-Photobooth/monitor_gpio_buttons.py &


After rebooting, start the photobooth.py script through the terminal (dont use ssh, it must be done via the touchscreen)

sudo python /home/pi/Pi-Photobooth/photobooth.py

If all goes well, Photobooth should launch. A sound effect of  will play, meaning that it is looking for a Wii remote. Note - you don't have to use a remote with this, it will work just fine without one too. Push the 1 and 2 buttons simultaneously to sync the Wii remote. Once it's been paired a confirmation message will play and the Wii remote will vibrate.

When the application starts, all the buttons will fire. If necessary, just hit the "New Picture" button to reset everything. Note- the image preview is a GIF, so it will may be a little pixelated. The image that prints out or is emailed will be a full sized png file with better resolution.

Below are how the buttons are configured on the Wii remote:


Note: Do not use a Wii remote Plus, only the original Wii remote

 Finishing Touches

While not necessary, the following are some additional things that can be done.

Add a shortcut on the desktop to start up the Photobooth. To do this, create the file  /home/pi/Desktop/photobooth.desktop with the following contents:

[Desktop Entry]
Version=1.0
Name=PhotoBooth
Comment=PhotoBooth
Exec=sudo python /home/pi/Pi-Photobooth/photobooth.py
Icon=/home/pi/Pi-Photobooth/images/photo-booth.png
Path=/home/pi/
Terminal=false
Type=Application
Categories=Utility;Application;

Customize the touch keyboard to include the '@' symbol to facilitate adding in email addresses. I have a matchbox xml config file included in the repository. Copy the keyboard.xml file provided to the root user profile:

sudo mkdir /root/.matchbox
sudo cp /home/pi/Pi-Photobooth/images/keyboard.xml /root/.matchbox/keyboard.xml


Change the desktop background to a more Photoboothy one. Right click the Desktop, Desktop Preferences, then under Wallpaper browse to /home/pi/Ri-Photobooth/images/photo_booth_background.jpg



You may also want to turn off the screen-saver to keep the screen from turning off.

That's it! For additional fun, check out some of the photobooth props you can buy online or make some yourself.