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)



(-) a005 get photos - (fetch resize)


How the get-photos script works


This script finds new photos, resizes them and saves them to the /photos folder. The script is 'optional' i.e. you only need to use it if you want the Pi itself (rather than a Samba attched PC) to update the /photos folder. This means it doesn't do anything 'vital' for the operation of the photoframe It's main function is to generate thumbnail photos to the exact display size (if you let fbi do your resizing, you are asking for trouble). First, fbi often gets landscape photo's 'wrong', 'croping' them into a 'square' aspect ratio, although (oddly) 'portrait' photo's are always scaled correctly. More to the point, fbi will be rescaling each of the 3 'different' images 'on the fly', at 1 per second, which not only wastes power but also takes longer than the 1s 'allowed' for each to be displayed Finally, saving a copy of the 'full resolution' photo is pointless = it's 15-20x more efficient to save only the exact correct size (1200x1400 jpg's are about 3 a Mb, whilst 16Mpixel camera jpegs are about 5-6Mb each) The get-photo script uses ImageMagick 'convert' to generate (and save) a (correctly) pre-scaled thumbnial of each new photo to fit the display. Note. ImageMagick is installed (if needed) by the go-photoframe script before this script is launched

Actual operation

Version 1 only checks USB sticks (and not mapped Media server folders) and over-writes any file of the same name.

Operation is as follows :-
1) Wait for a USB stick to be inserted
2) Turn on the Loading LED (pull some GPIO pin Lo)
3) Copy/resize all .jpg's in the 'root' to /photos/
4) Turn off the Loading LED (release GPIO pin)
5) Wait until the USB stick is removed
6) Loop back to top

Unused GPIO pins that could be used for the LED are : BCM17 (pin11), 27 (pin13)  or 22 (pin15). Gnd can be found on pin9 and 3v3 on pin17.
To activate the LED, the GPIO line will 'pull Lo', so we need 3v3 (pin17) to power the LED and thus BCM22 (pin15) is the 'nearest choice'.

#!/bin/bash # get-photos.sh for Mk2 PhotoFrame, last updated 28 Sept. 2016 # GPIO setup (GPIO27 (hdr. pin 13) is used to pull LED lo when loading) # Start by clearing any current setting (gpio remains set after the script crashes) sudo sh -c 'echo "27" > /sys/class/gpio/unexport'
sudo sh -c 'echo "27" > /sys/class/gpio/export'
# Tri-state the pin (set it's direction to 'in') - to pull the pin low, we set it's direction 'low'
sudo sh -c 'echo "in" > /sys/class/gpio/gpio27/direction'
#
# source photos are in root of USB stick, set mount point (only done on launch, so doesn't matter if we get an 'already exists' error)
mkdir -p /usbroot
# copy resize is to /photos/ folder (existing files of same name are overwritten)
# loop forever checking for USB stick insert
while [ true ]; do
	# 1) Wait for a USB stick to be inserted (fdisk lists devices, grep looks for sda1 found = true, so need ! (for not found)
	while ! fdisk -l | grep -q "sda1"; do
	sleep 1
	done
	# OK, usb stick found, lets mount it (read only)
	mount /dev/sda1 /usbroot -o noatime
	# 2) Turn on the Loading LED (pull GPIO 27, pin13 Low
	sudo sh -c 'echo "low" > /sys/class/gpio/gpio27/direction'
	# 3) Make/save thumbnials of all .jpg / .JPG in the /usbroot/ to /photos/?.jpg
	for filename in $(ls -A1 /usbroot/*.jpg); do
	convert $filename -resize '1600x1200' /photos$filename
	done
	# some camera jpg's use upper case (.JPG) file extension
	for filename in $(ls -A1 /usbroot/*.JPG); do
	# use SED to substitute (s) JPG with jpg (/g means 'replace all occurances')
	outname="$(echo $filename | sed 's/JPG/jpg/g')"
	convert $filename -resize '1600x1200' /photos$outname
	done
	# all files copied, unmount the usb drive
	umount /dev/sda1
	# 4) Turn off the Loading LED (set GPIO27, pin13 as input)
	sudo sh -c 'echo "in" > /sys/class/gpio/gpio27/direction'
	# 5) Wait until the USB stick is removed
	while fdisk -l | grep -q "sda1"; do
	sleep 1
	done
	# 6) Loop back
done

Note.
The LED is 'on' when photos are being copied from the stick (so user doesn't remove USB stick)
The same LED is used as a 'feedback' (key click) indicator for the iR remote control.

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

sudo chmod +x get-photo.sh
This note last modified: 17th Nov 2017 17:29.

[top]

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