logo
background
 Home and Links
 Your PC and Security
 Server NAS
 Wargames
 Astronomy
 PhotoStory
 DVD making
 Raspberry Pi
 PIC projects
 Other projects
 Next >>

Notes index links

Links to all my notes (includes mini-projects and source code etc)

(+) 0001 How do I change the Pi System partition size ?

(+) 0100 Device tree settings

(+) 0201 Power over Ethernet - (PoE)

(+) 0202 Solar Power - (with WiFi)

(+) 0203 Power Bank pass through

(+) 0400 Accessing the SDHC card system image

(+) 0401 Accessing PC shares from the Pi

(+) 0402 Installing samba - (the Pi as a Network Share on your PC)

(+) 0900 Can this approach be scaled up to a PC UPS ?

(+) 1001 Pandora Spotify on the Pi

(+) 1002 Playing movies on the Pi

(+) 1003 Getting VGA from the HDMI socket

(+) 1004 Using the RCA socket

(+) 1005 Using the Pi RS232 serial links

(+) 1006 Using the GPIO pins

(+) 1007 Controlling the Pi Zero ACT LED

(+) 1200 List of standard camera modes

(+) 1300 Auto file names

(+) 6500 How to make the System partition read only ?

(+) 6501 Minimising SDHC corruption on power down

(+) 9000 diode switch

(+) 9001 Auto shut down

(+) 9001 MOSFET switch

(+) C201 High speed photos

(+) Dec 1969 (no desc)

(+) a000 Display setup - (for PhotoFrame)



(-) a001 go photoframe - (how it works)


How the go-photoframe.sh script works

This script 'wraps it all together' and is designed so all you have to do (after update/upgrade) is create the /photos folder, place all 3 scripts inside (making them executable) and then add this script to the end of the Pi boot-up command list (the /etc/rc.local local file)

Install ImageMagick

One of the first things the script does is check if ImageMagick 'convert' exists, and, if not, apt-get it and install it (it's about 80Mb)

#!/bin/bash # go-photoframe.sh for Mk2 PhotoFrame, last updated 2016 Sept 28 # test if ImageMagick convert exists, and if not get it now hash convert # check for convert (status appears on screen) if [ $? -eq 1 ]; then # convert not found, install it now    echo >&2 "convert not found, installing ImageMagick" sudo apt-get install -y imagemagick fi #
To check if it installed OK, do a basic 'convert with resize' :-

convert {sourcefile} -resize '1600x1200' {destfile}
(where 1600 is max width, 1200 max height and the image will be resized to fit)

ram-disk

To avoid wearing out the SDHC card directory with 'linking' of files, a ram-disk is used for the fbi display files which means we only read the SDHC card directory and then read (copy) photos from SDHC card to the ram-disk (i.e. to the free buffer in tmpfs).

Of course, after a reboot, we need to create the ram-disk folder (we don't care if it already exists, just let the create attempt error out)

# tbd

The launch sequence

Start by launching the other 2 scripts in the background :-

# Launch background tasks # get and resize (comment this out if you don't need Pi to update /photos from USB etc)
sudo /photos/get-photo.sh &
# select next for display
sudo /photos/set-photo.sh &
#

Fbi will 'run for ever' (stepping from one photo to the next) to avoid the 'memory leak' problem found when it's allowed to stop (and is restarted).

In order to 'switch' the photo being displayed we 'cheat' fbi by changing a symbolic link from the 'fixed' file it's showing to a new one we want to show next.

It turns out that fbi actually has to be given 3 'fixed' file names because, even when fbi is told 'no cache', it will actually pre-fetch two. Only when it has to 'step' across 3 or more files will it actually go read the image data each time. To make it easy to 'switch', fbi is given 3 dummy 'alias' files, all 3 of which 'point' to a single 'intermediate' dummy 'display.jpg' = so switching just means changing the display.jpg file symbolic link.

To speed up the appearance of a new photo (after a switch), we have to get fbi to step across the 3 'dummy' photos 'as fast as possible'. The fastest step rate turns out to be about 1 second (so a 3 second cycle for all 3 files).

# give the go-photo (background) script a chance to copy the first image into buffer1.jpg and alias link it to display.jpg sleep 5 # now generate the 3 fbi files and alias them to the display file, which is itself an alias to one of the buffer files # (-f means overwrite any existing link of the same name) ln -s -f display.jpg alias-1.jpg ln -s -f display.jpg alias-2.jpg ln -s -f display.jpg alias-3.jpg # # launch fbi foreground task on a 3 second cycle fbi -T 1 -d /dev/fb0 -noverbose -t 3 -cachemem 0 alias-1.jpg alias-2.jpg alias-3.jpg
Notes.
During development, the '-a' flag (auto-rescale) was used so fbi would cope with 'any' sized photo sent to it.
Needless to say, sometimes fbi got this wrong (adding 'black bands' to both top and bottom of the display at the same time), so we rely on the get-photo script to scale correctly (and don't need -a)

We actually need to copy the next photo to the ram-disk (so it can't be deleted whilst it's being displayed), and that means we have to avoid over-writing the current displayed photo with the next (if we do, the actual screen display becomes 'corrupted', although it does usually recover without the Pi crashing). This means using a pair of 'buffer' files. This means display.jpg is 'linked' to one of two bufferX.jpg files.

Because fbi is stepping at 1s, when we change the display.jpg link (to point at the new bufferX.jpg), the new photo should appear 'on screen' within 1 second. 

Swapping out the image and updating the display link is done by another script running in the background - for more details, see the 'set-photo' script.

To have your photoframe start-up on each boot, add "/photos/go-photoframe.sh" at the end of /etc/rc.local

This note last modified: 17th Nov 2017 17:29.

[top]

(+) a002 set photo - (select for display)

(+) a003 go button script - (photoframe pause control)

(+) a005 get photos - (fetch resize)

(+) a00x Other display utilities

(+) c000 CCTV UPS requirements

(+) c001 countering low speed motion detect

(+) c002 Pi Overclocking

(+) c203 Pi ram disk - (tmpfs)

(+) c901 iR illumination

(+) c902 Viewing a video stream

(+) c905 Image anotation

(+) Dec 1969 (no desc)

(+) raspicamdocs.txt (no desc)

(+) s010 Elevation sensing

Next subject :- index

[top]