The 100 best digital picture frames on amazon
The 100 best digital picture frames on amazon
The 100 best digital picture frames on amazon
The 100 best digital picture frames on amazon

How to autostart and mon­i­tor the Pi3D image view­er on your Rasp­berry Pi 2, 3 or 4 with sys­temd

-

I have been get­ting reports late­ly where crontab didn't work for some peo­ple, so I thought I'd show you a quick way to using sys­temd instead of crontab fix­ing the issue of your image view­er not start­ing at boot. I will use my favorite image view­er Pi3D as an exam­ple.

A quick intro­duc­tion on sys­temd

sys­temd is a sys­tem and ser­vice man­ag­er for Debian, the Lin­ux vari­ant at the core of Rasp­bian. With nar­row regard to our use case, this means that it can man­age user process­es. Its job is to "quick­ly solve prob­lems". In cod­ing, that mes­sage has a nice ring to it!

The great thing about using sys­temd is that it can mon­i­tor process­es.

So where­as crontab can launch your pro­gram or script at boot, sys­temd can check if the process is still run­ning. If that is not the case, sys­temd can either qui­et­ly restart the process, send an alert, or do what­ev­er you want to hap­pen.

As Pi3D needs a dif­fer­ent start com­mand depend­ing if you are using the Rasp­berry Pi 4 or the old­er mod­els 2 and 3, I will show you both ways.

Instruc­tions for the Rasp­berry Pi 2 and 3

From with­in the com­mand line in the ter­mi­nal cre­ate a new sys­temd ser­vice by typ­ing:

sudo nano /lib/systemd/system/pi3d.service

Paste this text into the win­dow:

[Unit]
Description=Pi3D Service
After=multi-user.target
 
[Service]
Type=idle
 
User=pi
ExecStart=/usr/bin/python3 /home/pi/pi3d_demos/PictureFrame.py
 
Restart=always 
RestartSec=30 
 
[Install] WantedBy=multi-user.target

Save the file and change the per­mis­sions to make it read­able by all.

sudo chmod 644 /lib/systemd/system/pi3d.service

As the last step, you need to tell the sys­tem that you have added this file and want to start the ser­vice every time your Rasp­berry Pi boots up.

sudo systemctl daemon-reload
sudo systemctl enable pi3d.service

Reboot your Pi, and you are all set!

Instruc­tions for the Rasp­berry Pi 4

From with­in the com­mand line in the ter­mi­nal cre­ate a new sys­temd ser­vice by typ­ing:

sudo nano /lib/systemd/system/pi3d.service

Paste this text into the win­dow:

[Unit]
Description=Pi3D Service
After=multi-user.target
 
[Service]
Type=idle
 
User=root
ExecStart=xinit /usr/bin/python3 /home/pi/pi3d_demos/PictureFrame.py :0 -- -s off -dpms -s noblank
 
Restart=always
RestartSec=30
 
[Install]
WantedBy=multi-user.target

Save the file and change the per­mis­sions to make it read­able by all.

sudo chmod 644 /lib/systemd/system/pi3d.service

As the last step, you need to tell the sys­tem that you have added this file and want to start the ser­vice every time your Rasp­berry Pi boots up.

sudo systemctl daemon-reload
sudo systemctl enable pi3d.service

Reboot your Pi, and you are all set!

Con­clu­sion

You may have stum­bled upon this arti­cle after hav­ing searched for hours for a solu­tion to your Pi3D image view­er autostart prob­lem. I hope sys­temd will work for you as reli­ably as it has for many Rasp­berry Pi users!

As always, leave me a mes­sage with any ques­tions you may have.