This gist describes how to setup a Raspberry Pi in order to be used as a digital picture frame.
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
- Install Raspberry Pi OS
- Connect to Wi-Fi network
- Update Raspberry Pi OS
- Enable remote administration
- Configure Raspberry Pi OS
- Install necessary software and dependencies
- Configure Xorg
- Install and initialize PictureFrame
- Test PictureFrame
- Configure PictureFrame
- Add Pictures
- Autostart PictureFrame on boot
- Reboot and enjoy the show
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.
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
Ensure that the newly installed OS is up-to-date (this may a few minutes).
sudo apt-get update
sudo apt-get upgrade
If not preconfigured within the imager, optionally enable SSH to allow remote administration.
sudo systemctl start ssh
sudo systemctl enable ssh
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
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
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'
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}
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.
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
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.
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
At this point, you should be all set to reboot and enjoy the show.
sudo reboot
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
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.
Just an FYI, these instructions do not work. Installation of PicFrame fails with compiling numpy.