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.
I collected tips from several pages and try to list as many of them at the end of this article.
Prepare Raspberry Pi
Install standard rasbian package from www.raspberrypi.org by following the image installation guide. NOOBS 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. My preferred SSH client is MobaXterm.
Install feh and setup startup files
Update rasbian and install feh. Network connection is needed.
sudo apt-get updatesudo apt-get upgradesudo 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
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
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
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 &
Update LXDE autostart
Update LXDE so that feh is started automatically on startup
This doesn’t seem to work anymore with rasbian jessie
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
But this one does
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/
Mount USB by running
sudo mount /dev/sda1 /media/usb
And see if you can see the content of USB drive
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 connecting the proper pins.
Addition to original post
To turn TV on and off trough HDMI CEC
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
The Raspberry Pi A+ works fine with feh and USB flash drive. Simple configuration without anything fancy. Just power on the Pi and images start to roll directly from USB and it can be shutdown properly by connecting the 9 and 11 pins (button).
A lot could be done. I tested already some digital signage solutions but for my use case this one was the most convenient especially since my goal was to get my Raspberry Pi A+ in good use. I did all the tasks mentioned in this article in my Raspberry Pi 2 since it is so much faster and have ethernet port build in and used the A+ after everything was ready. 🙂
Possibility to fetch images from some external source can be reached with feh and insertion of USB while feh is running. Just keep reading the references and other sources.
Starting the RPi by connecting the run pins could be added so that power doesn’t need to be removed and reconnected. One button to shutdown RPi and another to start it up again. RPi uses very little power when it is on idle.
Perhaps archinux could be used instead of rasbian?