jateu01
Posts: 35
Joined: Sat Mar 28, 2020 7:30 pm

Camera preview only showing on HDMI and not GPIO LCD

Fri Apr 24, 2020 10:48 am

Hi All

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

gordon77
Posts: 4992
Joined: Sun Aug 05, 2012 3:12 pm

Re: Camera preview only showing on HDMI and not GPIO LCD

Fri Apr 24, 2020 11:00 am

Is the LCD one of these ?

https://thepihut.com/products/adafruit- ... uEQAvD_BwE

If so did you install as a mirror or a raw buffer ?


jateu01
Posts: 35
Joined: Sat Mar 28, 2020 7:30 pm

Re: Camera preview only showing on HDMI and not GPIO LCD

Fri Apr 24, 2020 11:38 am

Hi Gordon,

No its a fairly simple lcd.

Many thanks

jateu01
Posts: 35
Joined: Sat Mar 28, 2020 7:30 pm

Re: Camera preview only showing on HDMI and not GPIO LCD

Fri Apr 24, 2020 11:48 am

Hi All,


This is all that i had been given with lcd. See image i know its blury zoom out a little.
Attachments
Screenshot_20200424_124212.jpg
Screenshot_20200424_124212.jpg (161 KiB) Viewed 264 times

gordon77
Posts: 4992
Joined: Sun Aug 05, 2012 3:12 pm

Re: Camera preview only showing on HDMI and not GPIO LCD

Fri Apr 24, 2020 1:09 pm

Interestingly this page http://www.lcdwiki.com/HDMI_display_doe ... BCP_driver
says you can use this lcd and hdmi.

PiGraham
Posts: 3929
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Camera preview only showing on HDMI and not GPIO LCD

Fri Apr 24, 2020 1:32 pm

gordon77 wrote:
Fri Apr 24, 2020 1:09 pm
Interestingly this page http://www.lcdwiki.com/HDMI_display_doe ... BCP_driver
says you can use this lcd and hdmi.
I had something similar with a 3.5 inch LCD display case. The install set the display size to match the LCD, which is useless for most HDMI.displays.

fbcp will scale HDMI to the TFT size so set display resolution to suit whatever you want to display. if fbtft is configured to suit the TFT the full display will be scaled down to fit the TFT. Scaling is done in the GPU so it's fast.

Of course you loose a lot of detail going down to 483 x 320 or smaller.

gordon77
Posts: 4992
Joined: Sun Aug 05, 2012 3:12 pm

Re: Camera preview only showing on HDMI and not GPIO LCD

Fri Apr 24, 2020 2:51 pm

In the picamera documentation it states..

5.4. The preview doesn’t work on my PiTFT screen
The camera’s preview system directly overlays the Pi’s output on the HDMI or composite video ports. At this time, it will not operate with GPIO-driven displays like the PiTFT. Some projects, like the Adafruit Touchscreen Camera project, have approximated a preview by rapidly capturing unencoded images and displaying them on the PiTFT instead.

I don't know if this has changed, it works on my Adafruit LCD.

PiGraham
Posts: 3929
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Camera preview only showing on HDMI and not GPIO LCD

Fri Apr 24, 2020 3:02 pm

gordon77 wrote:
Fri Apr 24, 2020 2:51 pm
In the picamera documentation it states..

5.4. The preview doesn’t work on my PiTFT screen
The camera’s preview system directly overlays the Pi’s output on the HDMI or composite video ports. At this time, it will not operate with GPIO-driven displays like the PiTFT. Some projects, like the Adafruit Touchscreen Camera project, have approximated a preview by rapidly capturing unencoded images and displaying them on the PiTFT instead.

I don't know if this has changed, it works on my Adafruit LCD.
I this that's what I described. Output of GPU scaled and copied into a framebuffer which is streamed out to the TFT by the CPU/DMA.

It's not full speed and it's low resolution (of course, given it's a small screen)

I've seen 12 fps full screen and reports of a bit faster.

fbcp copies the full output from the GPU to HDMI so it should work with camera preview and hardware decoded video streams or GPU generated graphics..

Return to “Beginners”