Thanks to gordon77 for his great help wit the following code to save sequential file names and actions related to button presses. its works flawlessly. The project is all contained in a LCD case with all buttons and Pi4 all in the same case as LCD and powered by a power bank. The problem I am having is that the Camera preview is not displaying on the LCD but when I plug in a HDMI to my TV the preview pops up there. As this is for a self contained portable photographic telescope project I will not be able to carry around a TV. Can anyone shed light on this problem please code is below again supplied by gordon77.
Many thanks
J
Code: Select all
#!/usr/bin/env python3
# import libraries required
from gpiozero import Button
from gpiozero import LED
from signal import pause
import time
import glob
import os
import subprocess
import signal
import sys
import datetime
#setup gpios used. Note gpio numbers NOT pin numbers
video_button = Button(26)
still_button = Button(16)
stop_button = Button(11)
capture_led = LED(23)
preview_led = LED(24)
#start preview
preview_led.on()
path = "raspivid -t 0 -p 0,0,480,320 -a 'PREVIEW'"
p = subprocess.Popen(path, shell=True, preexec_fn=os.setsid)
# function for taking a still
def capture_still():
global p
preview_led.off()
# stop preview
os.killpg(p.pid, signal.SIGTERM)
capture_led.on()
now = datetime.datetime.now()
timestamp = now.strftime("%y%m%d%H%M%S")
# define command for raspistill
path = "raspistill -o /media/pi/0A30651730650B51/Photo/AstroPic" + str(timestamp) + ".jpg -p 0,0,480,320"
# call raspistill command
os.system (path)
capture_led.off()
preview_led.on()
# restart preview
path = "raspivid -t 0 -p 0,0,480,320 -a 'PREVIEW'"
p = subprocess.Popen(path, shell=True, preexec_fn=os.setsid)
# function for taking a video
def capture_video():
global p
preview_led.off()
# stop preview
os.killpg(p.pid, signal.SIGTERM)
capture_led.on()
now = datetime.datetime.now()
timestamp = now.strftime("%y%m%d%H%M%S")
# define command for raspivid
path = "raspivid -o /media/pi/0A30651730650B51/Photo/AstroVideo" + str(timestamp) + ".h264 -p 0,0,480,320 -t 30000 "
# call raspivid command
os.system (path)
capture_led.off()
preview_led.on()
# restart preview
path = "raspivid -t 0 -p 0,0,480,320 -a 'PREVIEW'"
p = subprocess.Popen(path, shell=True, preexec_fn=os.setsid)
# function for stopping
def switch_stop():
global p
# stop preview
os.killpg(p.pid, signal.SIGTERM)
# exit
sys.exit()
# setup button actions
# call capture_video if button pressed
video_button.when_pressed = capture_video
# call capture_still if button pressed
still_button.when_pressed = capture_still
# call swicth_stop if button pressed
stop_button.when_pressed = switch_stop
pause()