Igor's Blog

A while back I wrote an entry on how to get the Lenovo LT1421 USB DisplayLink monitor working on a RaspberryPi. Now I took that a bit further and created a photo frame using the Raspberry Pi model A, a USB monitor and a bunch of software and some custom scripts.

This is part two of this blog post, if you haven't seen the first part, you can find it here: https://www.igorkromin.net/index.php/2015/04/06/raspberrypi-and-a-usb-monitor-combined-to-make-a-photo-frame-part-1/.

In the first part I got as far as setting up file sharing and disabling screen blanking on the photo frame. This post deals with the setup required for the display of the photo frame and selection of random photos from a directory. Here's a screenshot of the final result that my custom scripts have achieved:
screenshot.jpg


It's important to note that the scripts assume a certain resolution for the display and may not work correctly on a different resolution. This resolution is 1366x768. So far I've not been able to figure out how to make Conky resolution independent.

I thought about how I would display the photo frame content and in the end decided that the easiest way would be to stick with Xorg and lightdm as they come out of the box with Raspbian, but I added Conky to the mix. I also decided on ImageMagick to manipulate images and threw in unclutter so that the mouse cursor would not be visible (it always gives me a chuckle whenever I see a mouse cursor on those big advert screens).

Using apt-get, I installed the following packages: conky, unclutter, imagemagick.

Once unclutter is installed, it will hide the mouse cursor automatically the next time the OS is restarted so there is no configuration required for that, however lightdm has a panel that is usually visible, this is easily hidden by editing some configuration like this:
 ~/.config/lxpanel/LXDE-pi/panels/panel
Global {
...
autohide=1
heightwhenhidden=0
...




When I first set up Conky, I was using a default font, this looked quite ugly, so I took to the web and had a look around and found a nicer font to use: Origami Mommy. It's simply a matter of copying the .ttf file to the ~/.fonts directory to install the font.

Next I set up a shell script that would select the next photo to display on the photo frame. This script picks a random photo from the /photos directory, resizes and pads the photo as needed, caches the result and copies the selected photo as /photos/caches/current.jpg. Caching is quite important because displaying large photos can take considerable amount of time on the Raspberry Pi, it also saves energy in the long run as the CPU is not being maxed out. ImageMagick is used to do the resizing and padding of the photos. The script will not pick the same photo twice in a row, so it is important to have at least 2 photos in the /photos directory or it will get stuck in an infinite loop.

Here's the script:
 select.sh
#!/bin/bash
PHOTO_DIR=/photos
CACHE_DIR=/photos/cache
CURRENT_PHOTO=`cat $CACHE_DIR/current.txt`
cd $PHOTO_DIR
files=(*.*)
# get new random photo
randphoto=$CURRENT_PHOTO
until [ $randphoto != $CURRENT_PHOTO ]; do
randphoto=$(printf "%s\n" "${files[RANDOM % ${#files[@]}]}")
done
# keep track of selected photo for next run
echo $randphoto > $CACHE_DIR/current.txt
if [ ! -f "$CACHE_DIR/$randphoto" ]
then
convert "$PHOTO_DIR/$randphoto" -gravity center -background black -resize 1066x768 -extent 1066x768 "$CACHE_DIR/$randphoto"
fi
# swap in new photo file
cp "$CACHE_DIR/$randphoto" $CACHE_DIR/_current.jpg
mv $CACHE_DIR/_current.jpg $CACHE_DIR/current.jpg


I set this script to run every 3 minutes using cron.
 crontab -e
*/3 * * * * /photos/cache/select.sh


That's it for this post, the next post is coming soon so stay tuned. Next time around I will describe the Conky setup and will show the resource file used.

Part 3 is posted now, check it out here: https://www.igorkromin.net/index.php/2015/04/12/raspberrypi-and-a-usb-monitor-combined-to-make-a-photo-frame-part-3/.

-i

, , ,
About — I'm an enthusiastic software engineer and consultant interested in many fields including J2EE, programming, electronics, 3D printing, video games, wood working and gardening.
See my Resume for more information.
The views expressed in this blog are my own and not those of my employer.
comments powered by Disqus
My other posts you may like...
Programming, DIY, Games, Hacks, Tech and more.
Follow me on...
Current and Past Projects
See my Resume

Subscribe


RSS Feed

My Other Web Sites

Igor and Elise's Travels
Riverside Expressway Cam
StrFunc() Online
300 George St Blogumentary
Guru JSON-RPC Tester
Extrudifier Object Designer

Recent Blog Posts

NeoOffice Viewer macOS Word Document viewer vs Preview and Microsoft Word

Importance of cleaning the internal fans and heatsinks in a MacBook Pro

Adding an email subscribe feature to your Blog with Blogtrottr

How to remove Google's logo from your G Suite applications

Pedestal fan transformed into a ceiling fan

Testing the Velvet WiFi Hotshot signal strength

Improving slow download speeds on the PS4 and PSN

Add batch image resize functionality to macOS using Automator

Show transfer percentage and speed when copying files in Linux and Bash

So I finally got to try eating some space food

Recent Galleries

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

DIY spare parts computer build with a RAIDMAX Anura case

Fake 'Lepin' brand Lego packaging

Hardwood garden bench with clear resin void filler

Fixing a 3D printer extruder that stopped heating up

Easily increase disk space in a Lenovo Ideapad 100S 14" laptop with an M.2 SSD

Making a multi-piece 3D printed solder spool holder stand

DIY indoor apartment grow light wiring

Good Friday Electronics fun Easter Bunny LED PCB Kit IBEABU-01.0

Top Categories

Blogs I follow

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth

Friends

RAWS Parts Online
Alpha Dimensions Hosting
Kristensen Photography
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity
Please follow me on...