Skip to content

Instantly share code, notes, and snippets.

@thomasedoff
Last active November 10, 2022 15:02
Show Gist options
  • Save thomasedoff/3973846101da1e7496524be075f1c02f to your computer and use it in GitHub Desktop.
Save thomasedoff/3973846101da1e7496524be075f1c02f to your computer and use it in GitHub Desktop.
Raspberry Pi Digital Picture Frame

Raspberry Pi Digital Picture Frame

This gist describes how to setup a Raspberry Pi in order to be used as a digital picture frame.

IMG_0050

Specifically, it covers how to install and configure Raspberry Pi OS and PictureFrame on a Raspberry Pi, using the bare minimum software components along with some quality of life improvements.

The setup has been tested with:

  • Raspberry Pi 2 Model B Rev 1.1
  • Raspberry Pi 3 Model B Rev 1.2
  • Raspberry Pi 3 Model B Plus Rev 1.3

Table of contents:

  1. Install Raspberry Pi OS
  2. Connect to Wi-Fi network
  3. Update Raspberry Pi OS
  4. Enable remote administration
  5. Configure Raspberry Pi OS
  6. Install necessary software and dependencies
  7. Configure Xorg
  8. Install and initialize PictureFrame
  9. Test PictureFrame
  10. Configure PictureFrame
  11. Add Pictures
  12. Autostart PictureFrame on boot
  13. Reboot and enjoy the show

Optional tweaks

  1. Configure automatic control of the display
  2. Simplify remote management of pictures

Instructions

1. Install Raspberry Pi OS

First, download and install the Raspberry Pi Imager and write the disk image to a microSD card as per the instructions. When prompted, select Raspberry Pi OS Lite (32-bit) as the OS. No Desktop Environment is required.

Please note that most of the configuration in the in the first few sections of this gist can be configured within the imager. These image customization settings are accessed via the "gears" icon.

2. Connect to Wi-Fi network

If not preconfigured within the imager, connect the Rasperry Pi to a Wi-Fi network.

sudo raspi-config nonint do_wifi_country SE               # Set the country code
sudo raspi-config nonint do_wifi_ssid_passphrase SSID PSK # Set ssid and passphrase 

3. Update Raspberry Pi OS

Ensure that the newly installed OS is up-to-date (this may a few minutes).

sudo apt-get update
sudo apt-get upgrade

4. Enable remote administration

If not preconfigured within the imager, optionally enable SSH to allow remote administration.

sudo systemctl start ssh
sudo systemctl enable ssh

5. Configure Raspberry Pi OS

Next, configure the OS to automatically login and disable screen blanking.

sudo raspi-config nonint do_boot_behaviour B2                  # Enable automatic login
sudo raspi-config nonint do_blanking 1                         # Disable Xorg screen blanking

If not preconfigured within the imager, optionally configure the time zone and hostname.

sudo raspi-config nonint do_change_timezone "Europe/Stockholm" # Set time zone
sudo raspi-config nonint do_hostname picframe                  # Set hostname

6. Install necessary software and dependencies

Install the following packages that are required to run PictureFrame with or without glx.

sudo apt-get install --no-install-recommends \
  xserver-xorg \
  xserver-xorg-legacy \
  xinit \
  python3-pip \
  libopenjp2-7 \
  libgles-dev \
  libatlas3-base \
  libxrender-dev

7. Configure Xorg

In order to run PictureFrame, configure the X server to execute as root.

sudo sed -i 's/\(^allowed_users=\).*/\1anybody/' /etc/X11/Xwrapper.config
sudo bash -c 'echo "needs_root_rights=yes" >> /etc/X11/Xwrapper.config'

8. Install and initialize PictureFrame

Install the latest release of PictureFrame.

python3 -m pip install picframe

Next, initialize PictureFrame.

/home/pi/.local/bin/picframe -i /home/pi/

Accept the default configuration options.

Finally, create the corresponding directories referenced during initialization.

mkdir /home/pi/{Pictures,DeletedPictures}

9. Test PictureFrame

Ensure that everything is working thus far by starting PictureFrame.

xinit /usr/bin/python3 /home/pi/.local/bin/picframe /home/pi/picframe_data/config/configuration.yaml

A placeholder image should appear. Press ctrl+c to exit.

10. Configure PictureFrame

The default configuration created at /home/pi/picframe_data/config/configuration.yaml should work out of the box. But at least enable glx.

sed -i 's/\(^  use_glx: \).*/\1True/' /home/pi/picframe_data/config/configuration.yaml

For further details refer to the Configuration section in the PictureFrame wiki.

After making changes to the PictureFrame configuration, restart it with systemctl.

systemctl --user restart picframe.service

11. Add Pictures

To add your own pictures, put them in /home/pi/Pictures/.

This can, for example, be done by downloading a file from the Internet ...

wget https://upload.wikimedia.org/wikipedia/commons/8/8b/Fuji_da%C4%9Fi_manzara.jpg -P /home/pi/Pictures/

... Or sending them to the Raspberry Pi via SCP (provided that SSH is enabled).

scp ~/Downloads/Earth_seen_by_Hayabusa2.jpg pi@picframe:/home/pi/Pictures/

Also see the Simplify remote management of pictures section.

12. Autostart PictureFrame on boot

To make PictureFrame start automatically, first, create the necessary directories.

mkdir -p /home/pi/.config/systemd/user/

Next, create a service.

cat << EOF > /home/pi/.config/systemd/user/picframe.service
[Unit]
Description=PictureFrame

[Service]
ExecStart=xinit /usr/bin/python3 /home/pi/.local/bin/picframe /home/pi/picframe_data/config/configuration.yaml
Restart=always

[Install]
WantedBy=default.target
EOF

Finally, enable the service.

systemctl --user enable picframe.service

13. Reboot and enjoy the show

At this point, you should be all set to reboot and enjoy the show.

sudo reboot

Optional tweaks

1. Configure automatic control of the display

The following section may be specific to the Raspberry Pi Touch Display!

To automatically enable/disable the display on a schedule, we need to create a shell script that adjusts the brightness, a service that calls that script as well as two timers to schedule the service.

First create a script.

cat << 'EOF' > /home/pi/.local/bin/lcd_backlight.sh
#!/bin/bash

max=255
min=0
step=1
delay=0.0

case $1 in
  on)
    for (( i=$min; i<=$max; i+=$step )); do
      vcgencmd set_backlight $i > /dev/null
      sleep $delay
    done
  ;;

  off)
    for (( i=$max; i>=$min; i-=$step )); do
      vcgencmd set_backlight $i > /dev/null
      sleep $delay
    done
    ;;

  *)
    echo "Usage: $0 <on | off>"
    exit 1
  ;;
esac

exit 0
EOF

After creating the script, making it executable.

chmod +x /home/pi/.local/bin/lcd_backlight.sh

Then create the service that executes the script.

cat << EOF > /home/pi/.config/systemd/user/lcd_backlight@.service
[Unit]
Description=Turn on/off LCD

[Service]
Type=oneshot
ExecStart=/bin/bash /home/pi/.local/bin/lcd_backlight.sh %i
EOF

Now create a timer for turning on the display ...

cat << EOF > /home/pi/.config/systemd/user/lcd_backlight@on.timer
[Unit]
Description=Turn on LCD every day at 07:00

[Timer]
OnCalendar=*-*-* 07:00:00

[Install]
WantedBy=timers.target
EOF

... And a timer for turning off the display.

cat << EOF > /home/pi/.config/systemd/user/lcd_backlight@off.timer
[Unit]
Description=Turn off LCD every day at 23:15

[Timer]
OnCalendar=*-*-* 23:15:00

[Install]
WantedBy=timers.target
EOF

Finally, enable the two timers.

systemctl --user enable lcd_backlight@on.timer
systemctl --user enable lcd_backlight@off.timer

2. Simplify remote management of pictures

Optionally, install Samba to allow file and folder sharing over a network.

sudo apt-get install --no-install-recommends samba

Next, add samba user and set a password.

sudo smbpasswd -a pi

Set a Samba password when prompted.

Then, disable the read only setting in the [homes] section in the Samba configuration located at /etc/samba/smb.conf.

sudo sed -i '0,/^\(   read only = \).*/s//\1no/' /etc/samba/smb.conf

Finally, restart Samba.

sudo systemctl restart smbd

You should now be able to manage pictures via \\picframe\pi\Pictures.

@thomasedoff
Copy link
Author

See helgeerbe/picframe#257 for a discussion about this Gist.

@MDanihy
Copy link

MDanihy commented Nov 10, 2022

Just an FYI, these instructions do not work. Installation of PicFrame fails with compiling numpy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment