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)

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



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


The 'go-photo' display script

The basic 'go-photo' script just has to find the 'next' photo, copy it to the 'free' buffer and re-link display.jpg to the just 'filled' buffer (thus freeing the other buffer).

Of course it's not quite that simple :-)

To avoid any 'missing file' errors (and speed up the appearance of new photos), the 'source' folder contents will need to be checked after each photo is shown.

Further, because the fbi script has to be launched last, this script has to set-up the files needed

Note, it is assumed that the ram-disk folder (/photos/ram-disk) has already been created and 'mounted' to tmpfs, however to make sure type :-

df -HT
/photos holds the .jpg's to be displayed, and the /photos/ram-disk (tmpfs) folder holds both 'buffers' (buffer1.jpg, buffer2.jpg) and the display.jpg 'virtual' file name (which will be 'linked' to one of the buffers)

The 3 'alias' files needed by fbi will be created (and linked actual to virtual, display.jpg to alias) by the fbi script.

One thing to watch out for is to avoid 'overwriting' the 'just free' buffer too quickly = it takes fbi 1 second to stop 'reading' the old buffer and follow the alias - display - new buffer link.

The way it works is as follows :-
The outer loop runs 'while true' (i.e. for ever).
A directory list is generated in file date order (so the 'newest' photo is top of the list) and then we inner loop
- first name = top, compare with current, if it differs exit with next=top
 
New top is compared with previous top
- if no match (new top is newer), new top is used as the next photo
- else the dir list is scanned, and the photo after the current is chosen
- if current is not found, the top photo is used
The existing 'freeze' button will be replaced with a 'remote control', so there is no point in adding it at this stage

sudo nano go-photo.sh
#!/bin/bash # go-button.sh (based on go-photo.sh) # Start by setting up the gpio pin # clear any current setting (gpio remains set after the script crashes) sudo sh -c 'echo "17" > /sys/class/gpio/unexport'
sudo sh -c 'echo "17" > /sys/class/gpio/export'
sudo sh -c 'echo "in" > /sys/class/gpio/gpio17/direction'
# show the button status and give the user a chance to see it (allows test at power-on)
echo "Button detect - 'blank' = gpio didn't program, 1=default (not pressed, not plugged in), 0 = pressed"
cat /sys/class/gpio/gpio17/value
sleep 3
# this script copies the next photo into the free buffer and then updates the display alias
# source photos are held in the /photos/ folder (fetching and resizing is performed by the fetch-resize script)
# both buffers1&2.jpg and display.jpg are held in the /ram-disk/ folder (actual display is performed by the fbi script)
#  (all ram-disk files have to be recreated after each power on)
mkdir -p /photos/ram-disk # -p means prevents errors if dir already exists
mount -t tmpfs -o size=10M,mode=0755 tmpfs /photos/ram-disk # mount to tmpfs (10M is max allowed use, not reserved ram)
#
showtime=4 #photo show time -1 (so 4 = 5 seconds total)
cfile="0" # current file name
ctop="0" # current top by date
nbuf="buffer1.jpg" # next (free) buffer
# loop forever
while [ true ]; do
	top="0" # no top found
	next="0" # no next found
	# Scan the photos dir for the current file
	for filename in $(ls -A1c /photos/*.jpg); do
	# note, when you ls a different folder, the path is added to each file name (so file is /photos/name.jpg )
	if [ $top = "0" ]; then
		top=$filename
		if [ $filename != $ctop ]; then next=$filename; fi
	fi
	# find the next file AFTER the current
	if [ $next = "0" ]; then
		if [ $cfile = "0" ]; then next=$filename; fi
		if [ $filename = $cfile ]; then cfile="0"; fi
	fi
	done
	# if no next found, use top
	if [ $next = "0" ]; then next=$top; fi
	ctop=$top
	# OK, we have the next file, pause in case fbi is still reading the free buffer
	sleep 1
	cp -f $next /photos/ram-disk/$nbuf
	cfile=$next
	if [ $nbuf = "buffer1" ] then;
		nbuf="buffer2.jpg"
	else
		nbuf="buffer1.jpg"
	fi
	# wait if button (GPIO 17) is held down (Lo). Check every 0.1s for fast response
	while [ "$(cat /sys/class/gpio/gpio17/value)" == '0' ]; do
	sleep 0.1
	done	
	# now switch the link (on the first pass this creates display.jpg)
	ln -s -f /photos/ram-disk/$nbuf /photos/ram-disk/display.jpg
	# wait for the rest of the show time
	sleep $showtime
	# now go find the next
done


After creating any new script, don't forget to make it 'executable' :-)

sudo chmod +x go-photo.sh
To test this from the command line (assuming you are in the directory where the script resides) just type :-

./go-photo.sh

If you have samba installed and are 'sharing' the /photos/ folder with your PC, on your PC you can 'map' the share and go look in the (share)/ram-disk folder and watch the buffer1/2 file sizes change as new photos are copied in. You should also see display.jpg 'switching' (i.e. 'tracking' buffer1.jpg file size then buffer2.jpg file size and back again)


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

[top]

(+) 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]