A Guide for an automated digital signage with a Raspberry Pi

Minjoon Kouh, Drew University

Drew Physics Department uses a Raspberry Pi (RPi) to run custom­made slideshows about its course offerings, research opportunities, student activities, as well as “Physics InSight” about careers and opportunities for undergraduate physics students (published by American Physical Society). The following is a short guide on how to set up and maintain an automated digital signage system with a RPi, in case other departments might want to adopt a similar outreach solution. Some familiarity with the Linux environment is assumed.

Raspberry Pi (RPi) is a $35, credit-card­sized, single­board computer, which can serve well as a low­cost -platform for teaching/learning computer programming or electronics and for deploying various DIY projects. It is equipped with an HDMI output, and can be easily hooked up to a TV for displaying slideshows or video clips.

Among many benefits of using a RPi for driving a digital signage are its low cost, low power consumption (< 5 Watts), and ease of automation. One could use Microsoft PowerPoint to run a slideshow on a regular PC; however, it not only consumes unnecessarily more power (~ 60 Watts), but also is more difficult to automatically start various applications.

Necessary Hardware
  • TV with an HDMI input
  • Raspberry Pi (Model B+, in our case)
  • SD Card (containing a version of the Linux operating system for RPi)
  • HDMI cable
  • USB keyboard and mouse

Setup
RP-i­driven signage can be set up in many different ways. Our particular solution runs “qiv” (for images) and/or “omxplayer” (for video clips) at specified times with a simple shell script.

First, install a Linux operating system on a SD card, and start up your RPi. Configure the RPi to boot into a Desktop environment directly when it powers on, by running “sudo raspi­-confi” from the command line and following the options. You may also want to change the password for security. More information on this basic setup of RPi is available at www.raspberrypi.org.

Second, install “qiv” (quick image viewer) by running “sudo apt­get install qiv” from the command line. The movie player, “omxplayer,” should already be installed by default. You can use “lxterminal” to execute a command.

Third, create a shell script such as the following. Use “nano” within “lxterminal” as a text editor.

#!/bin/bash
# Count­down to the slideshow.
sec=5
while [ $sec ­-ge 0 ] do
    echo "Starting slideshow in $sec seconds"
    sleep 1
    sec=$((sec­1))
done
mintime="0830"
maxtime="1800"
while true do
    t=$(date +%H%M) # Get time.
    w=$(date +%w) # Get weekdays (0=Sunday)
    echo "Current time: $t"
    if [ $t ­-le $maxtime ] && [ $t -­ge $mintime ] \
    && [ $w -­ge 1 ] && [ $w ­-le 5 ]
    then
# Do the following slideshows.
    qiv ­-fismCd 10 /home/pi/Drew_Science/*.jpg
    omxplayer -­b /home/pi/Physics_InSight.mp4

    else
        sleep 60
    fi
done

The above shell script is the major part of the setup. The command “qiv -­fismCd 10” goes through the jpg files in the specified directory every 10 seconds in the full screen mode. Then, the command “omxplayer -­b” plays the specified movie file with a black background. It checks the current day of the week and time. If it is a weekday (i.e., “$w” is between 1 and 5) and the current time is between 08:30 and 18:00, the programmed slideshows will run. If those conditions are not met, the program sleeps for 60 seconds. Since RPi does not have an on­board clock, it needs to be connected to the internet to update its time. The shell script is programmed to run continuously, unless it is canceled with ctrl­-C. In our case, we saved it as “play_slideshow.sh.”

The shell script must be made executable by running “chmod +x play_slideshow.sh” from the command line.

Four, add the following lines to “/etc/xdg/lxsession/LXDE/autostart” by using “sudo nano”:

@xset s noblank
@xset s off
@xset ­dpms
@lxterminal -­e /home/pi/play_slideshow.sh

These commands disable the screensaver and dpms (display power management system), so that the screen does not go blank during the presentations. The last line executes the slideshow shell script as soon as the Desktop starts. Hence, the slideshow can be restarted, just by rebooting the RPi. The initial countdown in the shell script gives its user an opportunity to stop the slideshow at the beginning.

Maintenance
Maintaining the slideshows is relatively easy. In order to add/remove/update a slideshow program, files need to be transferred to the RPi, and the shell script should be edited accordingly. PowerPoint slides can be saved as individual images within Microsoft PowerPoint. If you need to convert a .pdf file into a sequence of images, you can install “imagemagick” on RPi by running “sudo apt­-get install imagemagick” and run the following shell script.

#!/bin/bash
pg=0
maxpage=100
while [ $pg ­-le $maxpage ] do
    convert -­quality 100 -­density 300 \
        your_file.pdf[$pg] $(printf
“img%04d.jpg” $pg)
    let pg=pg+1
done

Minjoon Kouh is an Assistant Professor of Physics at Drew University. His primary research area is in Computational Neuroscience, but he has also published several articles on the teaching of physics, particularly on incorporating the Wii-mote into physics labs as an inexpensive accelerometer.


Disclaimer – The articles and opinion pieces found in this issue of the APS Forum on Education Newsletter are not peer refereed and represent solely the views of the authors and not necessarily the views of the APS.