Saturday, 18 October 2025

Digital Picture Frame II

Intro

Whilst playing with options for my DPF on the iPad I came across an article in LXF describing a simple RPI python slideshow app. Sadly it was the last LXF (Linux format) magazine edition dated July 2025 and was rather nostalgic.  I have enjoyed many of their articles over the last ten years but I guess everone/everything changes over time.

I have a small Samsung TV which functions as an RPI screen and I noticed when experimenting with mirroring my iPad to the TV that it provides an unobtrusive display which can be on in the background and looked at from time to time.

If I attach the screen to my RPI application server (PI41) I have a basic system to use for a PoC to see whether I prefer it to my other DPF versions.

Proof of Concept

The python app requires a desktop GUI to display images and PI41 doesn't have one installed as I usually use it "headless".
My first job was to change over from RPI OS Lite to the desktop version.  I botched it somewhat just adding packages until LXDE worked. I also had to plug in keyboard/mouse to PI41.
I then installed the python pygame module and I was able to display a sample image on the screen and it looked fine.

 I was happy with PoC progress so I setup a Samba share to my database server (PIP) giving me access to my art gallery images.  The image gallery has smaller lower resolution images making them suitable for web loading.  They are fixed height of 922 pixels which fits fits very well, without scaling on the RPI screen which is 1920p wide x 1080p high.

I decided to initially display all images within a folder in my slideshow rather than using the MySQL database containing image, gallery and file information.  Setting up a loop to display the images was straightforward, based on the LXF magazine example.

I was very pleased with the result.  Folders contain a variety of images from different galleries or exhibitions and it is easy to spend a little while looking at images as they attract your attention briefly.  Images look really good on the TV screen; they are a good size and have good quality colours.

Improvements

Choose a gallery

Now we are happy this is a good idea we have various jobs to turn the slideshow into a practical system.  Firstly, I need to be able to control which gallery folder is displayed.  There are about fifteen folders in total each containing about 50-100 images and I want to choose one folder rather than cycle round them all.  Initially I thought that adding websocket processing was the natural way forward but I couldn't easily work out how to run the slideshow and have the websocket waiting for instructions concurrently.

The program which loops round to display files in a folder is called pictureframe.py.  I set it up to read a parameter file picframe.parm which contains the name of the folder to be displayed.  It reads picframe.parm after each image is displayed and, if the folder changes, pictureframe.py loads a new set of images and starts to display them.
A second simple python script, picparm.py, takes a single command line argument, the name of a folder, and saves it to picframe.parm.

It is now an easy task to create a webpage which has a list of folders/galleries as buttons.  When a button is pressed the webpage uses a websocket to invoke picparm.py and change the folder being displayed.  This mechanism has been tried and tested on my music control web pages.


Display Tweak

The Samsung TV screen with a HDMI connection to the RPI has a screen resolution of 1920x1080.  I Rather than display the image as fullscreen using pygame I display a window 1840x1036 which allows me to add the images descriptive file name as a window caption. The image itself is always 922 pixels high which fits nicely into 1036 pixel window height when centred. 

Start and stop the display

The slideshow runs on a RPI desktop but I have no intention of using the attached keyboard to start and stop it.  After a few minutes writing python I was irritated by using the screen / keyboard directly.  The first remote desktop I tried was XRDP, an RDP implementation for RPI.  However it gave me a copy of the console rather than allowing me to "take over" the real one.  Most RPI users choose VNC.  I installed TigerVNC on Windows to communicate with VNC on RPI and this allowed me to stop using the attached keyboard and mouse.

However, I dont really want to do anything at the computer to start the slideshow.  I need RPI to automatically load and run pictureframe.py at startup.  Firstly we can setup RPI to automatically boot into the GUI using raspi-config

Then, in the LXDE GUI preferences, we can add pictureframe.py in autostart to run when the system starts up.

Now, as soon as the system startup our slideshow starts based on the most recent parameter file.


In fact I dont want to have a "stop" option anymore.  I add an extra parameter mode, "pause" or "resume",  to pictureframe.parm.  If pictureframe.py  sees "pause" in the parameter file it loops round until the parameter is changed to "resume" and the screen image doesn't change at all.

We add a "pause/resume" button to the web page so that we can stop and start the display from any browser device.

More enhancements

I am not sure how quickly to change display images so that I can look at them in enough detail, without getting bored.  I have started up with options to display for 5,10,20,60 seconds.  I added an extra line to pictureframe.parm containing the desired interval and added a command line parameter "time" to update the value in python.  I then added buttons in the webpage for each interval.

I also want to see in the browser what the current display parameters are.  I added a "status" parameter to pictureparm.py which returns current parameter values.  I then setup a field in the web page to display the output.


Finally, I added a randomiser, so that we dont start with the same picture each time we display a gallery.  Pictures are still in the same order but we can start with any one.

Outro

I am happy with my latest slideshow.  I like the larger images displayed on the Study TV.  Also you dont need to focus on them - they are just there.  You can control the display from any device and it doesn't require any thought to start / stop or change display.  Unlike the previous slideshows I have actually been using this one.

No comments:

Post a Comment