Raspberry Pi USB Picture Frame

Introduction: Raspberry Pi USB Picture Frame

About: Playing with Arduino and Raspberry Pi

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 www.raspberrypi.org 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 www.raspberrypi.org. 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
sudo apt-get upgrade
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

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.

Create shutdown.py

nano shutdown py

And paste the following code

import RPi.GPIO as GPIO
import time
import os
# GPIO 17 = pin 11
# GND = pin 9
GPIO.setmode(GPIO.BCM)
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")
        break
    time.sleep(1)

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 shutdown.py 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 shutdown.py on background process

sudo mount /dev/sda1 /media/usb
sudo python /home/pi/shutdown.py &

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
@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

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 shutdown.py 

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

Step 5: Additional Info

Solution that will turn TV on and off using CEC

Thanks to RichardW58 for this solution.


Install cec-utils:

sudo apt-get install 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

More

My original article can be found from here.

feh info and manual.

1 Person Made This Project!

Recommendations

  • Make it Glow Contest

    Make it Glow Contest
  • First Time Author Contest

    First Time Author Contest
  • PCB Challenge

    PCB Challenge

18 Discussions

0
Boost Willis
Boost Willis

Question 11 months ago

Can you please explain sudo mount /dev/sda1 ? That folder doesn't exist on my version. Is there supposed to be something in there?

0
TJuTZu
TJuTZu

Answer 11 months ago

/dev/sda1 is USB drive connected on RPi. It can't be seen until it is connected.

The mount command connects USB drive to location /media/usb

0
hodg
hodg

Question 1 year ago on Step 5

Hi after doing line " sudo nano ~/.config/lxsession/LXDE-pi/autostart "...I get "Directory '/LXDE-pi' does not exist".......please help
Ray H

0
TJuTZu
TJuTZu

Reply 1 year ago

Hi

The autostart location have changed since I made this instruction.
The following should work with latest rasbians

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

0
Faist
Faist

2 years ago

Very interested in this for some sales displays! Does a screensaver ever kick on with this method?

0
TJuTZu
TJuTZu

Reply 2 years ago

I made simple signage system which uses centralized image storage and where each display can be set to show its own set of pictures.

web server (which can be pi) and network access is required.

You can find the code from here https://github.com/TJuTZu/onefilesignage

0
TJuTZu
TJuTZu

Reply 2 years ago

Is should not.

This part in autostart disables screensaver
@xset s off

@xset -dpms

@xset s noblank

0
kd6not
kd6not

3 years ago

Found the issue with the strange <p> , <br>, etc. When testing I see a recurring 1 and then a 0 when the button is pressed. I assume this is the desired outcome.

Mark

0
TJuTZu
TJuTZu

Reply 3 years ago

I don't know where those <p> and <br> came from. Probably a copy error since I coped that part originally from my web site. It should be fine now.

0
kd6not
kd6not

Reply 3 years ago

Thanks very much for the Instuctables to begin with - this one really covered exactly what I needed, especially the shutdown function with the button. I had heard that a hard power down could corrupt things, and was a bit worried how to protect against that. Your Instructable really helped. Thanks again.

Mark

0
TJuTZu
TJuTZu

Reply 3 years ago

Hard shutdown can cause SD card corruption. That was the reason I made this system. The reset button can be used to start system when it have been shut down as long you keep it powered all the time. I am happy to hear that this little hack is useful.

0
TJuTZu
TJuTZu

3 years ago

For some reason almost all code blocks contained suddenly html line breaks <br> that I needed to clean away.

Well is should be OK now.

0
kd6not
kd6not

3 years ago

I did a copy and paste of the shutdown.py , but get a syntax error on the first line. Here is the paste I'm using:

<p>import RPi.GPIO as GPIO<br>import time
import os
# GPIO 17 = pin 11
# GND = pin 9
GPIO.setmode(GPIO.BCM)
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")
break
time.sleep(1)</p>

I'm fairly new at this, and certainly won't spot any obvious errors. Can anyone point out my mistake?

Mark

0
RichardW58
RichardW58

3 years ago

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?

0
TJuTZu
TJuTZu

Reply 3 years ago

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

0
fahv
fahv

3 years ago

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

0
DIY Hacks and How Tos

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

0
TJuTZu
TJuTZu

Reply 3 years ago

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.