blaser93
Posts: 2
Joined: Sat Jun 08, 2019 2:47 pm

Picamera take several photos issue

Sat Jun 08, 2019 2:59 pm

I need help with this python code.
I want it to take multiple photos, all starting with the datetime-string. But it only takes one photo!?
I get the same when running the take_photo() function in a while loop.

Probably basics...but can anyone give give me some advice?
Thanks!
My code:

Code: Select all

from picamera import PiCamera
import time
import datetime as dt
import sys

camera = PiCamera()
camera.resolution=(720, 300)
i = dt.datetime.now()  
now = i.strftime('%Y%m%d-%H%M%S') 
filepath = now + ".jpg"

def take_photo():
	print("Taking a photo...")
	camera.capture(filepath)
	time.sleep(1)

for i in range(10):
	time.sleep(1)
	take_photo()

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

Re: Picamera take several photos issue

Sat Jun 08, 2019 7:53 pm

It was taking the photos but all had the same name as you only specified it once..

try this...

Code: Select all

from picamera import PiCamera
import time
import datetime as dt
import sys

camera = PiCamera()
camera.resolution=(720, 300)

def take_photo():
   print("Taking a photo...")
   i = dt.datetime.now()  
   now = i.strftime('%Y%m%d-%H%M%S') 
   filepath = now + ".jpg"
   camera.capture(filepath)
   time.sleep(1)

for i in range(10):
   time.sleep(1)
   take_photo()

blaser93
Posts: 2
Joined: Sat Jun 08, 2019 2:47 pm

Re: Picamera take several photos issue

Sat Jun 08, 2019 9:25 pm

Got it! Works!
Thanks for the reply gordon77!!!

antennas
Posts: 20
Joined: Thu Sep 20, 2012 4:09 pm

Re: Picamera take several photos issue

Tue Jun 18, 2019 4:02 pm

I am using this same script to save pics to a folder. But I want to save them to the USB drive which shows up at / mnt/usb. How do I do that ? I don't see where to change it to make it do that. Thanks.

I found a chunk of python and just put" /mnt/usb/" after the camera.capture command.
Last edited by antennas on Tue Jun 18, 2019 4:37 pm, edited 1 time in total.

User avatar
B.Goode
Posts: 8045
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Picamera take several photos issue

Tue Jun 18, 2019 4:34 pm

antennas wrote:
Tue Jun 18, 2019 4:02 pm
I am using this same script to save pics to a folder. But I want to save them to the USB drive which shows up at / mnt/usb. How do I do that ? I don't see where to change it to make it do that. Thanks.


Here ->

Code: Select all

   filepath = now + ".jpg"

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

Re: Picamera take several photos issue

Tue Jun 18, 2019 5:24 pm

filepath = "/mnt/usb/" + now + ".jpg"

I would have expected the USB at

/media/pi/ followed by the USB stick name

Eg /media/pi/usb1/

Return to “Python”