Grapefruit1
Posts: 6
Joined: Mon Oct 02, 2023 12:11 pm

After reboot, Libcamera preview command executed automatically not working

Mon Oct 02, 2023 1:18 pm

Hello everyone,

long time reader, but now is the time i need to register and ask for your help.

I am not very knowledgeable yet, most of my projects were done with tutorials, so please explain as if i'm doing this for the first time, which it kindof is, since i have not found anyone describing this behavior.


The Goal:
After the Pi boots it should show a fullscreen, full fps (atleas 1920x1080 30 fps) webcam preview, until the power is cut. Manually i can do this, but the automation on boot is not working for me. It should be a cabled connection(cam to pi and pi to monitor). No recording, just watching the camera feed on the PC monitor or TV. It does not have to be libcamera, but

Code: Select all

libcamera-still -t 0
is the only reliable manually working solution i found, that worked for hours without crashing, different other ones i tried crashed after 10min to 30min.

The Hardware:
Pi Zero W (headless, connectiing with Windows Powershell)
Pi Cam 3 with csi to hdmi adapter
Output for the preview is my normal PC monitor, connected via HDMI port, target is the TV
OS: Newest Raspberry Pi OS Lite 32bit from the Pi Imager + Update and Upgrade after initial boots(tried several times, had to reformat, so always up to date)


Failed attempts
(maybe the would work, but i tried them several times with )

Crontabs (never used it before, tried several things on how to wirte it from this forum and tutorials. basically it was my manual command with a @reboot infront of it)
Other methods all seem to open .py files, which seems to not be aplicable ?! (I have no idea yet on how to do python)


I hope the situation is described as clearly as possible and you can find a solution. If i have missed an already existing thread that might help i may have missed it due to missing knowledge to transform the information.

Thanks in advance!

Cheers
Sven

User avatar
neilgl
Posts: 6841
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: After reboot, Libcamera preview command executed automatically not working

Mon Oct 02, 2023 5:27 pm

The guide to all things startup is here: viewtopic.php?t=314455
Presumably it is a pi camera module, not a usb webcam?

Grapefruit1
Posts: 6
Joined: Mon Oct 02, 2023 12:11 pm

Re: After reboot, Libcamera preview command executed automatically not working

Mon Oct 02, 2023 7:34 pm

Hey ,

thanks for the reply.

I tired with the file you linked, it seems to be similar to what i already saw and tried in the last weeks. I gave it another shot.

Yes it is a Pi camera 3.

Here my results, maybe you or someone sees an obvious error i made.


rc local:


tried the following: (each separate ofc, the error below is shown for all of them, a couple of seconds after the error message, the login is waiting. Then the manual commands via ssh work... )

sudo libcamera-still -t 0
libcamera-still -t 0
sudo libcamera-still -t 0 &
libcamera-still -t 0 &



Oct 02 20:17:52 pzwh2 systemd[1]: Starting /etc/rc.local Compatibility...
Oct 02 20:17:54 pzwh2 rc.local[342]: Preview window unavailable
Oct 02 20:17:54 pzwh2 rc.local[342]: [0:00:35.555371000] [342] INFO Camera camera_manager.cpp:297 libcamera v0.0.5+83-bde9b04f
Oct 02 20:17:54 pzwh2 rc.local[342]: ERROR: *** no cameras available ***
Oct 02 20:17:54 pzwh2 systemd[1]: rc-local.service: Control process exited, code=exited, status=255/EXCEPTION
Oct 02 20:17:54 pzwh2 systemd[1]: rc-local.service: Failed with result 'exit-code'.
Oct 02 20:17:54 pzwh2 systemd[1]: Failed to start /etc/rc.local Compatibility.
~


Systemd

The service i created works when i manually do "sudo systemctl start sv" (sv.service = name of testservice i created). No automatic start again.
I even tried a combination with "sudo systemctl start sv" in the rc.local file. although no errors occured with systemd there is still only the manual way working.

now either
libcamera-still -t 0
or
sudo systemctl start sv


In my head it seemed like an easy task, do nothing just show webcam on screen.

Hope anybody has an idea of how to do it.

Cheers
Sven

sandyol
Posts: 58
Joined: Sun Dec 05, 2021 6:48 pm

Re: After reboot, Libcamera preview command executed automatically not working

Mon Oct 02, 2023 9:18 pm

After reading thagrol's guide I decided that a crontab was the simplest way to achieve what I think is a very similar task. (In my case a third party camera connected to a Pi3A and displaying a full-screen preview on switch-on)

Adding

Code: Select all

@reboot libcamera-hello -t 0 --viewfinder-mode 1920:1080:10:P
at the end of the crontab file seemed to be sufficient. The viewfinder mode command was needed to get the 1920x1080 sensor to fill the preview screen.

Grapefruit1
Posts: 6
Joined: Mon Oct 02, 2023 12:11 pm

Re: After reboot, Libcamera preview command executed automatically not working

Tue Oct 03, 2023 12:12 pm

Hey Sandyol,

fresh new install of the os, (same as mentioned in my initial post). did update and upgrade.

i tried this new command as well. Same outcome though. Manually via ssh it works, automation after boot with crontab not. There are no obvious error messages maybe i did something wrong?! I followed the tutorial, but no success. Which OS did you use? Maybe i need "normal" Raspberry Pi OS (with desktop)? Havent tried that yet, didnt want the pi zero to load something it does not need, like a desktop.

Here is my crontab file:

GNU nano 5.4 /tmp/crontab.dUxN0i/crontab # Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
@reboot libcamera-hello -t 0 --viewfinder-mode 1920:1080:10:P



Thanks for your help.

Cheers
Sven

sandyol
Posts: 58
Joined: Sun Dec 05, 2021 6:48 pm

Re: After reboot, Libcamera preview command executed automatically not working

Tue Oct 03, 2023 1:30 pm

Grapefruit1 wrote:
Tue Oct 03, 2023 12:12 pm
Which OS did you use? Maybe i need "normal" Raspberry Pi OS (with desktop)? Havent tried that yet, didnt want the pi zero to load something it does not need, like a desktop.

I'm using the latest 64-bit Lite image of Bullseye, so similar to your setup?
(Don't think 32 v 64 bit will be relevant)

Have you set the auto log-in for the console?

Code: Select all

sudo raspi-config

Option 1 System Options
S5 Boot / Auto Login
B2 Console Auto Login

PS your description of CSI to HDMI adapter sounds a bit odd. Presume V3 camera is connected directly to the Zero W camera flexi connector and your monitor to the mini HDMI port?

User avatar
davidcoton
Posts: 7280
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: After reboot, Libcamera preview command executed automatically not working

Tue Oct 03, 2023 2:26 pm

sandyol wrote:
Tue Oct 03, 2023 1:30 pm
I'm using the latest 64-bit Lite image of Bullseye, so similar to your setup?
(Don't think 32 v 64 bit will be relevant)
We're talking about a Pi0W, so the OS word size certainly is relevant. Pi0W is 32-bit only.
Location: 345th cell on the right of the 210th row of L2 cache

User avatar
neilgl
Posts: 6841
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: After reboot, Libcamera preview command executed automatically not working

Tue Oct 03, 2023 3:49 pm

Raspberry Pi OS Lite (64-bit) will not work on a pi zero - as it says in Imager:
Attachments
OS 64-bit Lite.png
OS 64-bit Lite.png (51.17 KiB) Viewed 340 times

Grapefruit1
Posts: 6
Joined: Mon Oct 02, 2023 12:11 pm

Re: After reboot, Libcamera preview command executed automatically not working

Tue Oct 03, 2023 5:08 pm

i am using 32bit.

The camera connection is as follows, and it work, with manual input of any of the two commands.

Cam --(short flatcable)-->CSI to HDMI --(HDMI cable)--> HDMI to CSI adapter --(short flatcable)--> Pi --(HDMI cable)--> Monitor

sandyol
Posts: 58
Joined: Sun Dec 05, 2021 6:48 pm

Re: After reboot, Libcamera preview command executed automatically not working

Tue Oct 03, 2023 6:00 pm

Grapefruit1 wrote:
Tue Oct 03, 2023 5:08 pm
i am using 32bit.

The camera connection is as follows, and it work, with manual input of any of the two commands.

Cam --(short flatcable)-->CSI to HDMI --(HDMI cable)--> HDMI to CSI adapter --(short flatcable)--> Pi --(HDMI cable)--> Monitor
Ahh ....understand now the camera extension adaptor setup!

Have you tried starting from a new fresh install to remove any 'after-effects' of the various test methods?

From memory the only changes in my system following a Bullseye lite fresh install were the one line crontab entry and the switch to auto console login, (apart from a config.txt dtoverlay entry for my non RPi camera - which won't be relevant to the V3 camera.)

Can't test the influence of the extension cable adaptor, but, like the difference between your 32 bit Zero W and the 64 bit 3A+ I'm not sure how relevant it is to this particular 'run on reboot' problem??

Grapefruit1
Posts: 6
Joined: Mon Oct 02, 2023 12:11 pm

Re: After reboot, Libcamera preview command executed automatically not working

Wed Oct 04, 2023 10:13 am

Hey,

i believe so ?! I never formatted the sd cards seperately, i just "reinstalled" the os with the Raspberry Pi Imager, and from my understanding it formats the card.

I will write down a complete step by step protocol what i do, maybe there we can see either my mistake or more mystery why it is not working. Most likely i will have time tomorrow to do so.

Best
Sven

sandyol
Posts: 58
Joined: Sun Dec 05, 2021 6:48 pm

Re: After reboot, Libcamera preview command executed automatically not working

Wed Oct 04, 2023 3:48 pm

Hi Sven,

In an effort to get closer to your setup I followed these steps:-

Original Pi 1 model and set it up with a newly imaged copy of RPiOS 32-bit Bullseye Lite and a V2 camera.
(No wifi/ssh but keyboard and mouse attached).

Let it run through its lengthy first setup until it rebooted.

Wait again for login prompt to appear.

Logged in as the user defined in Imager advanced options

Code: Select all

sudo raspi-config
to set Auto login to console as described earlier

finish and reboot

Wait for logged in user prompt

Code: Select all

crontab -e
(not sudo) and added

Code: Select all

@reboot libcamera-hello -t 0
exit and reboot

and........

it eventually reached the logged in user prompt but didn't run libcamera-hello.
(no surprise to you I guess!!)

The above list of steps on a Pi3A+ did give the expected result of a camera preview on the monitor.

Given the difference in speed between the older and later Pi models a 'bodge' of adding a delay in the crontab was tried and a new crontab entry of

Code: Select all

@reboot /bin/sleep 30 ; libcamera-hello -t 0

seemed to work.
Might need some experimentation with the time delay.

I'm sure there are more rigorous ways to achieve the result but that seems to work .
HTH
Sandy

Grapefruit1
Posts: 6
Joined: Mon Oct 02, 2023 12:11 pm

Re: After reboot, Libcamera preview command executed automatically not working

Thu Oct 05, 2023 10:26 am

Sandy, you are amazing!!!

THANK YOU VERY VERY MUCH.


With the delay it actually works fine! It doesnt have to be the best way, it just needs to work :D

In desperation and fueled by some beer. I ordered overpriced pi zero 2 w, to check for the 64 bit thing, but i guess now i can use it for something else :)


Thanks again for your work!

Best
Sven

Return to “Troubleshooting”