Introduction: Raspberry Pi USB Picture Frame

Picture of Raspberry Pi USB Picture Frame

Raspberry Pi USB picture frame

Raspberry Pi plays automatically images from inserted USB flash drive and is shutdown by pressing the button inserted into the device.

feh is used to display the images from USB and python script to shut down the device.

In this instruction I am not explaining how to add button on raspberry pi between pins 9 and 11.

Step 1: Prepare Raspberry Pi

Install standard rasbian package from by following the image installation guide. NOOBS or Raspian will do just fine too.

Setup Raspberry Pi according to your preferences. Only thing to ensure is that Raspberry start on GUI. Instructions can be found also from You need keyboard on first startup. You can use either console directly from Raspberry Pi or as I prefer SSH to connect the device. If you use latest Rasbian and want to enable ssh on first startup you need to add file named ssh on /boot/ directory of SD card.

Install feh

Update rasbian and install feh. Network connection is needed.

sudo apt-get update<br>sudo apt-get upgrade<br>sudo apt-get install feh

Create mount point

Mount point is needed to ensure all USB flash drives are treated same way. If USB is not mounted it will show under media as the way flash drive is named. For example KINGSTON would be ’/media/KINGSTON’ and could not be detected by feh if different flash drive was used previously

sudo mkdir /media/usb

Step 2: Shutdown Button

Picture of Shutdown Button

This phase can be skipped if button is not used to shutdown Raspberry Pi. I do recommend using this since shutting down the Raspberry Pi simply by unplucking the device can cause the SD or USB flash drive corruption.

Connecting the GPIO 17 to the ground will cause shutdown to be performed. You may use other pins also but code need to be changed accordingly.


nano shutdown py

And paste the following code

<p>import RPi.GPIO as GPIO<br>import time
import os
# GPIO 17 = pin 11
# GND = pin 9
GPIO.setup(17, GPIO.IN,pull_up_down=GPIO.PUD_UP)
while True:
    print GPIO.input(17)
    if(GPIO.input(17) == False):
        os.system("sudo shutdown -h now")

Ctrl-x and Yes and Enter to close editor and save changes

Step 3: Auto Start

Update rc.local

Update rc-local so that USB is automatically mounted and is loaded at startup

sudo nano /etc/rc.local

Into the rc.local before ’exit 0’ add the following lines to mount USB flash drive and to start on background process

sudo mount /dev/sda1 /media/usb<br>sudo python /home/pi/ &

Ctrl-x and Yes and Enter to close editor and save changes

Update LXDE autostart

Update LXDE so that feh is started automatically on startup

sudo nano ~/.config/lxsession/LXDE-pi/autostart

Instert following lines at the end of autostart

@xset s off<br>@xset -dpms
@xset s noblank
@feh --quiet --fullscreen --borderless --hide-pointer --slideshow-delay 30 /media/usb/

Ctrl-x and Yes and Enter to close editor and save changes

Step 4: Testing

Picture of Testing

Add some pictures on USB drive.

Mount USB by running

sudo mount /dev/sda1 /media/usb 

And see if you can see the content of USB drive

ls /media/usb 

Test feh by running following on command line. You need to have pictures on USB ?

feh --quiet --fullscreen --borderless --hide-pointer --slideshow-delay 1 /media/usb/ 

Test shutdown by running

sudo python 

and press the shutdown button (connect the proper pins).

Step 5: Additional Info

My original article can be found from here.

feh info and manual.


RichardW58 (author)2017-09-14

TJuTZu thanks for this awesome instruction. I created this masterpiece project for my coworker's new office. Unknown to me at the time, they don't have a network connection in their office. So, the monitor goes to sleep mode after running for a period of time. Does cron work when there is no internet connection? If not, is there any workaround?

TJuTZu (author)RichardW582017-09-14

cron does not require network. It is a job scheduler.

RichardW58 made it! (author)2017-08-31

I made a photo frame for my coworker's new office. He loves it, but I need to figure out how to turn it on/off at 6:30-5:00pm. Everything I read, says crontab don't work. Do you know?

TJuTZu (author)RichardW582017-08-31

I tried method found from here with DAKbord but it didn't worked as expected and I haven't had time to study it further.

RichardW58 (author)TJuTZu2017-09-03

I did the same thing and shut off, but when it came back on it doesn't start the slideshow.

TJuTZu (author)RichardW582017-09-04

That method should only shut down the hdmi display and restart it. It does not start feh when display is restarted.

You could try to use crontab to start feh at the same time hdmi turned on

0 7 * * * feh --quiet --fullscreen --borderless --hide-pointer --slideshow-delay 1 /media/usb/

you should be able to replace LXDE-pi/autostart with line below in crontab.

@reboot feh --quiet --fullscreen --borderless --hide-pointer --slideshow-delay 1 /media/usb/

But I have not tested crontab reboot :)

RichardW58 (author)TJuTZu2017-09-04

So I used and it works fine;

# Turn monitor on
0 7 * * 1-5 /usr/bin/vcgencmd display_power 1
# Turn monitor off
0 20 * * 1-5 /usr/bin/vcgencmd display_power 0
TJuTZu (author)RichardW582017-09-11

I tested another solution with TV that will turn it on and off using CEC

Install cec-utils:

sudo apt-get intall cec-utils

add following lines in crontab -e

# Turn TV on
0 8 * * 1-5 echo "on 0" | cec-client -s
# Turn TV off
0 16 * * 1-5 echo "standby 0" | cec-client -s

This worked fine with TV

TJuTZu (author)RichardW582017-09-05

Great to hear.

Thanks for sharing the solution

fahv (author)2017-07-01

Thanks especially for the line sudo nano ~/.config/lxsession/LXDE-pi/autostart. My noblank autostart works again. And no need for xscreensaver.

DIY Hacks and How Tos (author)2017-02-26

I always thought that a raspberry pi would make a good picture frame because you could even set it up to get video.

I tried that also, but I can't remember now what software I was using :) Instead of feh, fbi (linux framebuffer imageviewer) or FIM (Fbi IMproved) could be used.

I needed a simple image viewer which  show automatically images from inserted USB drive.

About This Instructable




Bio: Playing with Arduino and Raspberry Pi
More by TJuTZu:Raspberry Pi Included3D PrintingRaspberry Pi USB Picture Frame
Add instructable to: