-1

I am new to programming with Python and the Raspberry Pi, and for my first project i wanted to play the official "Push button stop motion" code from the official raspberry pi camera guide (https://projects.raspberrypi.org/en/projects/push-button-stop-motion)

I wired up the button sucessfully and didn't change one thing in the code + downloaded and installed the picamera. The button works fine and takes pictures, but it only saves the last taken picture on the desktop. I tried adding an ongoing "i" but it doesn't seem to work, can anybody help?

from datetime import datetime
from gpiozero import Button 
import picamera 
import time

b=Button(2) 
pc=picamera.PiCamera() 
running = True 
timestamp=datetime.now() 
def picture():         
pc.capture('pic'+str(timestamp)+'.jpg') 

pc.start_preview() 
b.when_pressed=picture 
try: 
while running:  
print('Active'
time.sleep(1) 

except KeyboardInterrupt: 
pc.stop_preview() 
running = False
1

Move the setting of the timestamp inside your picture() method. It looks as though you are currently overwriting the image with the same timestamp.

def picture():          
    timestamp=datetime.now() 
    pc.capture('pic'+str(timestamp)+'.jpg') 
  • Thank you so much! That solved it!! – Vani Sep 30 '20 at 12:47
  • 1
    Please mark the answer as correct. Thanks. – CoderMike Sep 30 '20 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.