beira
Posts: 6
Joined: Mon Apr 09, 2018 9:38 am

Start PiCamera at startup

Mon Apr 09, 2018 9:44 am

Hello,

I'm new at raspberry. So i need to start the picamera ate the start of the raspeberry. I only need to do live at a monitor.

were can i place the raspivid -t 0 command to start automatically?

i have this sripy at startup but it wont start

from picamera import PiCamera
from time import sleep
camera = PiCamera()
camera.framerate = 15
camera.start_preview()


Thanks

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: Start PiCamera at startup

Mon Apr 09, 2018 4:49 pm

hi, try to follow, i hope you can copy paste commandlines and file content into your terminal:
( rev. 2018-04-12 )
cd
mkdir projects
cd projects
mkdir RPI_CAM
cd RPI_CAM
nano RPI_CAM.py

Code: Select all

#!/usr/bin/python3
from picamera import PiCamera
from time import sleep

camera = PiCamera()
camera.led = False
camera.resolution = (640,480)
camera.framerate = 5
camera.sharpness = 0
camera.contrast = 0
camera.brightness = 50
camera.saturation = 0
camera.ISO = 0
camera.video_stabilization = False
camera.exposure_compensation = 0
camera.exposure_mode = 'auto'
camera.meter_mode = 'average'
camera.awb_mode = 'auto'
camera.image_effect = 'none'
camera.color_effects = None
camera.rotation = 0
camera.hflip = False
camera.vflip = False
camera.crop = (0.0, 0.0, 1.0, 1.0)
print("show web cam")
#camera.start_preview()  # if need fullscreen use later
camera.start_preview(fullscreen=False, window = (100, 100, 640, 480))
sleep(10)
MYINPUT = input("stop and take picture")  # will wait for answer and show CAM forever
camera.capture('/home/pi/Pictures/RPI_CAM_py_image.jpg')
camera.stop_preview()
print("use gpicview to see Pictures/RPI_CAM_py_image.jpg")

nano RPIcamshow.sh

Code: Select all

#!/bin/bash
for N in {30..5..-5}
do
   echo $N'sec'
   env sleep 5
done


TODAY=$(date +'%Y-%m-%d_%H:%M:%S')
echo $TODAY
/usr/bin/python3 /home/pi/projects/RPI_CAM/RPI_CAM.py
echo 'show picture'
gpicview /home/pi/Pictures/RPI_CAM_py_image.jpg
echo 'press ENTER'
read
chmod +x RPIcamshow.sh

test with
./ RPIcamshow.sh

nano RPIcamshow.desktop

Code: Select all

[Desktop Entry]
Type=Application
Comment=RPI cam show
Name=RPI cam
Icon=/usr/share/pixmaps/guvcview/guvcview.png
Exec=lxterminal -e /home/pi/projects/RPI_CAM/RPIcamshow.sh
Terminal=false
cp /home/pi/projects/RPI_CAM/RPIcamshow.desktop /home/pi/Desktop/RPIcamshow.desktop
( you might see not showing that same icon )
test with double click on it

for auto start try
cd
cd .config
ls
mkdir autostart
# if not exist
cp /home/pi/projects/RPI_CAM/RPIcamshow.desktop /home/pi/.config/autostart/RPIcamshow.desktop
sudo reboot



after test you can make the preview big again, use the while true: and shorten the timer...
Last edited by KLL on Thu Apr 12, 2018 8:14 am, edited 1 time in total.

beira
Posts: 6
Joined: Mon Apr 09, 2018 9:38 am

Re: Start PiCamera at startup

Wed Apr 11, 2018 1:51 pm

Thanks,

It works!!!:)

Now for fullscreen ate startup and to be always on until reboot i have to supress this lines?


print("show web cam 10 sec and make snap")
#camera.start_preview() # if need fullscreen use later
camera.start_preview(fullscreen=False, window = (100, 100, 640, 480))
if True:
#while True: # this use later if all works out, but how to stop it? do not enable while AND autostart together
sleep(10)
camera.capture('/home/pi/Pictures/RPI_CAM_py_image.jpg')

camera.stop_preview()
#print("use gpicview to see Pictures/RPI_CAM_py_image.jpg")

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: Start PiCamera at startup

Wed Apr 11, 2018 2:01 pm

beira wrote:
Wed Apr 11, 2018 1:51 pm
Thanks,

It works!!!:)


if True:
#while True: # this use later if all works out, but how to stop it? do not enable while AND autostart together
ok, ( i prepared for that ) just change to

Code: Select all

#if True:
while True:
	sleep(10)
but i warned you, you need to know how to stop it!
Last edited by KLL on Wed Apr 11, 2018 2:14 pm, edited 2 times in total.

beira
Posts: 6
Joined: Mon Apr 09, 2018 9:38 am

Re: Start PiCamera at startup

Wed Apr 11, 2018 2:05 pm

Thanks once again,
When i do that it goes to the picture dont go live

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: Start PiCamera at startup

Wed Apr 11, 2018 2:11 pm

beira wrote: When i do that it goes to the picture dont go live
?? when
while True:
is enabled, it will sleep 10 sec again and again, and never come to the "make a picture part???
also python and bash script never stop!
https://www.dotnetperls.com/while-python
Last edited by KLL on Wed Apr 11, 2018 2:19 pm, edited 1 time in total.

beira
Posts: 6
Joined: Mon Apr 09, 2018 9:38 am

Re: Start PiCamera at startup

Wed Apr 11, 2018 2:17 pm

I did this

#!/usr/bin/python3
from picamera import PiCamera
from time import sleep

camera = PiCamera()
camera.resolution = (640,480)
camera.framerate = 5
camera.sharpness = 0
camera.contrast = 0
camera.brightness = 50
camera.saturation = 0
camera.ISO = 0
camera.video_stabilization = False
camera.exposure_compensation = 0
camera.exposure_mode = 'auto'
camera.meter_mode = 'average'
camera.awb_mode = 'auto'
camera.image_effect = 'none'
camera.color_effects = None
camera.rotation = 0
camera.hflip = False
camera.vflip = False
camera.crop = (0.0, 0.0, 1.0, 1.0)
print("show web cam 10 sec and make snap")
#camera.start_preview() # if need fullscreen use later
camera.start_preview(fullscreen=False, window = (100, 100, 640, 480))
#if True:
while True: # this use later if all works out, but how to stop it? do not enable while AND autostart together

sleep(10)
camera.capture('/home/pi/Pictures/RPI_CAM_py_image.jpg')

camera.stop_preview()
#print("use gpicview to see Pictures/RPI_CAM_py_image.jpg")

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: Start PiCamera at startup

Wed Apr 11, 2018 2:30 pm

if you not use ["code"] tags, we not see if the sleep(10) has a [tab] in front ( so is looped by while )

again:

Code: Select all

print("show web cam ")      #10 sec and make snap")
#camera.start_preview()     # if need fullscreen use later
camera.start_preview(fullscreen=False, window = (100, 100, 640, 480))
#if True:
while True:                # this use later if all works out, but how to stop it?
	sleep(10)
camera.capture('/home/pi/Pictures/RPI_CAM_py_image.jpg')

camera.stop_preview()
#print("use gpicview to see Pictures/RPI_CAM_py_image.jpg")
shows:

Code: Select all

30sec
25sec
20sec
15sec
10sec
5sec
2018-04-11_21:26:10
show web cam 
and never stops,
live cam window and that bash terminal window open.
______________________________________________________
if i select the bash window and [ctrl][c]
cam stops and i see this

Code: Select all

30sec
25sec
20sec
15sec
10sec
5sec
2018-04-11_21:26:10
show web cam 
^CTraceback (most recent call last):
  File "/home/pi/projects/RPI_CAM/RPI_CAM.py", line 29, in <module>
    sleep(10)
KeyboardInterrupt
show picture

Last edited by KLL on Wed Apr 11, 2018 3:42 pm, edited 1 time in total.

beira
Posts: 6
Joined: Mon Apr 09, 2018 9:38 am

Re: Start PiCamera at startup

Wed Apr 11, 2018 3:02 pm

Thanks for all. :D :D :D :D

Return to “Beginners”