Raspberry Pi Slideshow

Raspberry Pi Slideshow

Wanting to do something productive with my Raspberry Pi, I decided to at least get it showing me new art each day. As it turns out... its a little more challenging than I had originally expected. The main reason was resources on the Pi. Many image viewers, both command line and x windows based like to do some crazy things that tend to blow up the memory consumption on my Raspberry. As a result, the kernel will, in turn, enjoy killing the offending process. The following is how I overcame the challenges. The Equipment: Raspberry Pi running Raspbian "wheezy" on a 4GB SD Card HDMI Monitor An Internet connection The Overview: The idea is to get updated images from Deviantart nightly and display them via slide show over the course of the day. The Steps: With a fresh install of Raspbian I booted up the Pi. The initial wizard gives you a few options, here is what I did. 1. Expand the root partition to fill the SD Card 2. Changed the keyboard to the US layout 3. Changed the timezone to reflect where I live 4. Changed the boot into desktop to yes (meaning it will start the desktop after boot). 5. As a matter of security, I also updated the password for the pi user. Reboot the Pi and you should find yourself looking at the desktop once you log in. Add Auto Login: You can skip this part if you don't want to auto login, it wont affect the outcome unless you reboot your machine. Making this as automated as possible, we need to set up the Pi to auto login the pi user. Here's how we do that. Edit /etc/inittab using vi. Of course vi is just my preferred text editor, feel free to use your own favorite. I've heard quite a few people like nano.
sudo vi /etc/inittab
Scroll down till you see the following line:
1:2345:respawn:/sbin/getty --noclear 38400 tty1
Comment it out by adding a pound sign (#) in front of it. Insert a new line and add the following.
1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1
Your file should now look something like this:
#1:2345:respawn:/sbin/getty --noclear 38400 tty1
1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1
NOTE: If your using a user different than 'pi' you will want to change the user, pi, to your user. Close and save the file. Go ahead and reboot your Pi just to make sure your changes have properly taken affect.
sudo shutdown -r now
Update and Install pqiv Once the machine comes back up, it should automatically boot you into LXDE (the default desktop environment). Go ahead and open a terminal window and update the apt-get repository.
sudo apt-get update
Normally we would issue a simple apt-get install pqiv to install pqiv; however, due to issues with version in the raspbian repository we will need to download, fix, compile, and install pqiv manually. Don’t forget to remove pqiv if you've already installed it at some point.
sudo apt-get remove pqiv
Install git and the dependency gtk2 library for pqiv.
sudo apt-get install git libgtk2.0-dev
We have what we need to build the application, now we need to download the source.
git clone -b 0.12
Now that you've downloaded the pqiv source, you will notice a new directory in your home directory called pqiv. Go into this directory and run ./configure to validate all preconditions are met and create a platform specific make file.
cd pqiv
Now we need to fix the source code by replacing the gchar option; with gint option; in the main() function in the pqiv.c file. The line we are looking for is around 2233.
/*gchar option;*/
gint option;
Save and exit vi. Now you've fixed the bug, we will run make and install the application.
sudo make all install
You now have the fixed version of pqiv running on your Pi. Get the slide show images: Now we need to create the process to download the images from Deviant art. To do this, first create a directory in your home directory. Open a terminal session and type in the following commands.
mkdir images
mkdir scripts
cd scripts
Now we need to create the script to get the images from DeviantArt. Create a new file in the scripts directory.
vi ~/scripts/
Inside the script copy and paste the following code. NOTE: Updated wget line to adapt to the change in RSS format from Deviantart.

cd /home/pi/images

rm *.jpg *.png

# go get the files
#landscape files
wget -q -O- "" | grep -o '<media:content url="[^"]*' | grep -o '[^"]*$' | xargs wget -c


for f in $FILES
    file -b $f
    echo "Checking file number $count"
    count=$(($count + $one))
    if [ "$(file $f|grep JPEG)" ]; then
      mv ${f} $RANDOM.jpg
    elif [ "$(file $f|grep PNG)" ]; then
      mv ${f} $RANDOM.png
    elif [ "$(file $f|grep ASCII)" ]; then
      echo ”Skip Script file”
      echo "unknown file type $f"
Once you've added the script, save your file and make it executable.
chmod +x ~/scripts/
Just to be sure your script is working execute it via the command line.
cd ~/scripts
So... whats this script do you might ask? For starters, using wget, it reaches out and pulls down images from DeviantArt via their RSS feeds. Using grep and sed we save the resulting downloaded file to the images directory. The second part of the script looks at all the files downloaded (some of them end up not being images) and gives them random file names. These random file names are what make the slide show seem a little more "random". But we want this pull to be a automated. To do this we add the script to cron. To edit cron:
crontab -e
And then add the following line at the end of the file.
00 01 * * * /home/pi/scripts/ > /home/pi/get_images.log 2>&1
The line above kicks off your script every night at 1:00 am and outputs both output and error to a log file in the home directory of pi. (this is really only to help with troubleshooting if needed). Slide show Image Swapping Next we need to create a set of scripts to refresh the slide show file and make sure the slide show continues to run. First up is a really simple script to continually refresh the slide show image. Create a new script file in your scripts directory.
cd ~/scripts
Copy and paste this script into your new file.

cd /home/pi/images
while true;
  do for i in *;
    do cp $i /home/pi/slideshow.jpg;
      echo $i;
      sleep 30;
Save your file and make it executable.
chmod +x
Here is a quick outline of what the above script does. It first changes its current directory to the images directory. Once there, it goes into an infinite loop. Once inside the loop it gets a list of files from your images directory. It then copies the first file to your home directory calling the file slideshow.jpg. The script then waits 30 seconds and then copies the second file, overwriting the existing slideshow.jpg with this new one. The script will do this for each file until it goes through all of them. Then it starts from the begging and does it all over again. At 1:00 am the get_images script will download a new set of images and because the update_slideshow_image get a new file list each time it loops, these new files will get added to the list to be displayed. This may not make much sense now, but it will after in a moment. Using pqiv to display images: Now we need to create the script to display the images.
cd ~/scripts
Copy and past this script into your new file.

# Lets start and restart the slideshow if needed
until /usr/bin/pqiv -i -f -s -w /home/pi/slideshow.jpg; do
  echo "Slideshow crashed with exit code $?. Restarting..." >&2
  sleep 2
Save your script and make it executable.
chmod +x
This script is really quite simple. Most of the actual slide show work is done by pqiv. This script's only duty is to kick off pqiv. If the program crashes the script will echo the reason it crashed and then wait a few seconds before restarting the slide show. Why do I do this you might ask? Memory resources on a Raspberry Pi are limited and image viewing software isn't all that great at being memory friendly, especially when trying to load larger files, scale them, and then display them. Do that over a hundred times and you will quickly get killed by the kernel. As a side note, I tried several other image viewing programs like fbi, fim, and feh. While they worked, they each had some small issues and more importantly, they were not fond of refreshing the image when the underlying file changed. Autostart the slide show: To have our slide show kick off automaticly once the Pi reboots. To do this we need to add two .desktop files to autostart. One file will run our update_slideshow_image script that the other will run the start_slideshow script. Here is how you create the first file.
cd /etc/xdg/autostart
sudo vi slideshow_image_changer.desktop
Inside this file add the following.
[Desktop Entry]
Name=Slideshow Image Changer
Comment=Slideshow Image Changer
Save this file and create the second file.
sudo vi slideshow_start.desktop
Add the following to this new desktop file.
[Desktop Entry]
Name=Slideshow Image Changer
Comment=Slideshow Image Changer
Save and close this file. Prevent the Raspberry from going to sleep: We are almost done... one thing that drove me nuts for a little while was how the Raspberry would occasionally turn off the monitor. I couldn't really narrow down what I did to fix the issue. I updated the following config settings and they seem to work as expected. Update the kbd config file.
sudo vi /etc/kbd/config
Scroll down till you see the BLANK_TIME setting and change it to 0.
# screen blanking timeout. monitor remains on, but the screen is cleared to
# range: 0-60 min (0==never) kernels I've looked at default to 10 minutes.
# (see linux/drivers/char/console.c)
Scroll down a little more till you see the POWERDOWN_TIME setting and change it to 0
# Powerdown time. The console will go to DPMS Off mode POWERDOWN_TIME
# minutes _after_ blanking. (POWERDOWN_TIME + BLANK_TIME after the last input)
Save and close the config file. Next I ended updating the lightdm.conf file.
sudo vi /etc/lightdm/lightdm.conf
Scroll down till you see the [SeatDefault] section and add a line towards the end of it.
xserver-command=X -s 0 dpms
My screen no longer goes blank and I have the pleasure of having a dynamic slide show all day. Reboot your Raspberry Pi. Provided everything goes as planned, your slide show should start shortly after booting into the LXDE desktop... congratulations!

You might also like

Squeaky Steel Case Jersey Chair... Fixed!


Our offices recently underwent a major renovation. Part of the change was the arrival of new Steel Case Jersey chairs for our work areas. The chairs themselves are adjustable in several areas and quite comfortable. However, by the time the newness wore off the squeaking started. The slightest movement such as leaning back or forward caused an ear piercing squeak to emit from the underside of the chair. As time progressed, you could hear squeaking throughout the entire floor. At times it was quite comical; however, most of the time it simply annoying. The fix: To stop the squeak find


Building a Word Clock


I was recently asked if I could build a Word Clock. Of course, not wanting to back down from a challenge (and a bit of research) I said "yes". One of the objectives of this build, aside from producing a quality product for our client was to document the build and share with the community. After a bit work, I present to you, the Javelin Word Clock. Check out this video a co-worker put together. I think he did a great job. Javelin's Word Clock Want one? You too can build this same clock by following my Instructables