Power up the Rasbperry Pi by plugging in the USB power adapter, then follow the on-screen prompts set up your WiFi network, keyboard layout, and localization.
Optional Frame Orientation
You may want to orient your frame as a portrait (tall) instead of a landscape (wide) display. To do so, follow these steps:
To rotate the orientation of the data sent to the TV, you'll add a single line to the Pi Zero's configuration text file. Type this in a terminal to edit the file:
sudo nano /boot/config.txt
and then press return.
You can add the new line at the very bottom of the file. Type this in on a new line:
#rotate the display: 0=normal, 1=right vertical, 2=upside down, 3=left vertical
That line is a comment, which won't be read by the machine, just us humans. Comment lines are preceded by the # symbol.
On the next line, type this:
display_rotate=1
Now, you can save the file (ctrl-x, Yes, return) and then restart the Pi Zero by typing:
sudo reboot
Get ready to turn your neck sideways or rotate your monitor to continue! If you ever need to go back to regular orientation, change the config.txt file's display_rotate value to 0.
Install Instaloader
Instaloader is the application you'll use to grab your pictures from an Instagram account. Head here to follow the instructions to install it on your Raspberry Pi from the terminal. I used the following command:
pip3 install --break-system-packages instaloader
This should return Successfully installed instaloader-4.12.1 or later
Directory Prep
You can keep things tidy by creating a directory for the photo frame scripts and pictures. In the terminal type:
mkdir /home/pi/igframe
This will create a folder named igframe.
Navigate to the directory by typing:
cd /home/pi/igframe
Instaloader Image Download
From inside the igframe directory you can test out Instaloader. By default, Instaloader will grab images, videos, captions, metadata, and more, but we just want the still image files. Enter:
instaloader profile adafruit --no-videos --no-profile-pic --no-metadata-json -no-captions
This will automatically create a new directory inside the current directory named for the profile - adafruit
- and then start downloading the IG images to the directory. You'll see feedback as the images download -- IG currently will limit this to twelve posts unless you are logged into your account. In case it seems to be downloading lots and lots of images without stopping you can hit ctrl-c at any time to stop it.
Note, you can substitute another IG account name if you like!
Check out the contents of the /home/pi/igframe/adafruit directory, you should see images from the latest twelve posts.
Install and Configure feh
Feh is a very nice command line image viewer, that happens to be perfect for running a slide show with specific parameters.
Let's install feh! Type this into the Terminal window, and then press return:
sudo apt-get install feh
This will download the necessary files and then install the application. When prompted, type Y and press return to continue.
DISPLAY=:0.0 XAUTHORITY=/home/pi/.Xauthority /usr/bin/feh --quiet --preload --randomize --full-screen --hide-pointer --slideshow-delay 5.0 /home/pi/igframe/adafruit &
Script It
Instead of retyping that command every time you want to run a slideshow, you can create a special type of text file, known as a shell script, to store the command (or many commands). This shell script can then be invoked any time you want to run the commands contained within.
Create a new shell script with this command:
sudo nano /home/pi/igframe/start-picture-frame.sh
Once again, this will launch the nano text editor. Copy and paste the code below into this into the file:
#!/bin/bash # Define variables PROFILE="adafruit" # you can type in any public IG account name here PAUSE=20.0 # how long you want to wait between images IMAGE_DIR="/home/pi/igframe/$PROFILE/" FEH_CMD="/usr/bin/feh --quiet --preload --randomize --reload 60 --hide-pointer --slideshow-delay $PAUSE $IMAGE_DIR" DISPLAY_ENV=":0.0" XAUTHORITY_ENV="/home/pi/.Xauthority" # Export the environment variables export DISPLAY=$DISPLAY_ENV export XAUTHORITY=$XAUTHORITY_ENV # Start feh in the background and save its PID $FEH_CMD & FEH_PID=$! while true; do # Run instaloader and check for errors instaloader profile $PROFILE --no-videos --no-video-thumbnails --no-captions --no-profile-pic --no-metadata-json if [ $? -ne 0 ]; then echo "No new images downloaded." else echo "Images downloaded successfully." fi # Sleep before repeating (3600 seconds in an hour) sleep 7200 done
Close and save the shell script by pressing ctrl-x and then Y and return.
Now, run the shell script -- which will in turn run all of the contents of the file -- by typing this:
bash /home/pi/igframe/start-picture-frame.sh
That just ran your slideshow with a much shorter command. Much easier!
Permissions
Let's have a look at the current file permissions. In your Terminal, type this in to the list directory contents with verbose info:
ls -l /home/pi/igframe
That list of letters on the left side in front of each file shows you what type of permissions exist for the file.
Possible permissions are read, write, and execute for three types of accounts: owner, group, and user. Here's a very good primer on the subject.
For the slideshow script we see:
-rw-r--r--
which means the file can be read and written by the owner ("root"), and only read (not executed or written) by groups and by users. This means the system (user "pi") doesn't have execution permission. So, we want to adjust that so the system can actually run the script without user intervention.
This simplest way to adjust this in our case is to grant execution permissions to all users. The chmod command is used to do so. Type this in your Terminal:
sudo chmod 755 /home/pi/igframe/start-picture-frame.sh
Autostart the Script
You may want to set up the Pi to automatically run your slideshow script on startup. This also means that if there is a loss of power, the system will not spend a long time stuck on a Linux screen!
To set the script to automatically run on startup we'll add a line to the desktop environment configuration script that automatically runs our picture frame shell script upon launch.
Open the autostart file for editing by typing:
sudo nano ~/.config/lxsession/LXDE-pi/autostart
Add a new line at the bottom and enter this text:
@./igframe/start-picture-frame.sh
As is by now the familiar routine, save and exit the file with ctrl-x, Y, return.
Once again, you'll need to restart the Pi to see the effects of your changes, so type:
sudo reboot
This time, once the Pi reboots, it will launch the desktop, and then start the slideshow! How automagical!
Text editor powered by tinymce.