Make your own selfie box with a raspberry PI

February 11, 2019

How to build your own selfie box with a very simple script and VLC. It needs only a push button, a Raspberry PI and a USB camera.

Introduction

Last November, I turned 30. For this occasion, I organized a party with friends and family. A great way to have some (fun !) photos is a selfie-box. Many tutorial for home made selfie boxes are available all around the web, sometimes called "photo booth". I read many of them and I though that I can made it simpler. This is my approach.

Hardware

For mouting, I have a little wood case.

Wiring

Only 3 wires are needed. There is no resistor on the LED because a raspberry PI limits current on the output at 16mA. Source : http://www.mosaic-industries.com/embedded-systems/microcontroller-projects/raspberry-pi/gpio-pin-electrical-specifications

Blink LED

            
                    import uinput
                    from gpiozero import LED
                    from time import sleep
                    
                    led = LED(17)
                    
                    while True:
                        led.on()
                        sleep(0.25)
                        led.off()
                        sleep(0.25)
            
        

VLC and screenshots

VLC can show a stream and take screenshots.

Just hit CRTL + ALT + s and an image is save in /home/user/.vlc

screenshots in VLC : https://www.vlchelp.com/take-picture-snapshot-video/

Click on "Media", then "capture device" and you get an access to "/dev/video0"

From command line :

            
                    vlc v4l2:///dev/video0 --fullscreen --no-osd
            
        

Create a new file in /home/pi/.config/autostart called autovlc.desktop. This file contains :

            
                [Desktop Entry]
                Type=Application
                Exec=vlc v4l2:///dev/video0 --fullscreen --no-osd
            
        

On boot, VLC will start automatically in fullscreen, showing your webcam input.

keyboard emulation

            
                import uinput
                from gpiozero import Button
                from time import sleep
                
                button = Button(2)
                device = uinput.Device([
                        uinput.KEY_LEFTALT,
                        uinput.KEY_CTRL,
                        uinput.KEY_S,
                        ])
                pressed = False
                
                while True:
                    sleep(0.25)
                    if button.is_pressed:
                        if pressed == False:
                            device.emit_combo([ uinput.KEY_LEFTALT, uinput.KEY_CTRL, uinput.KEY_S ])
                            pressed = True
                            print("Pressed")
                    else:
                        pressed = False
            
        

Final Code

            
                import uinput
                from gpiozero import Button
                from gpiozero import LED
                from time import sleep
                
                button = Button(2)
                device = uinput.Device([
                        uinput.KEY_LEFTALT,
                        uinput.KEY_CTRL,
                        uinput.KEY_S,
                        ])
                pressed = False
                
                while True:
                    led.off()
                    sleep(0.25)
                    led.on()
                    if button.is_pressed:
                        if pressed == False:
                            device.emit_combo([ uinput.KEY_LEFTALT, uinput.KEY_CTRL, uinput.KEY_S ])
                            pressed = True
                            print("Pressed")
                    else:
                        pressed = False