Push Button Stop Motion With Raspberry Pi!

by drjhxie in Circuits > Raspberry Pi

697 Views, 2 Favorites, 0 Comments

Push Button Stop Motion With Raspberry Pi!

ezgif-1-eac2b0d44a.gif

Push-button stop motion sounds very simple; it is, but it is still very fun to play with and you may even make youtube videos out of it! The video above is a example of what you can make!

Supplies

  1. Raspberry Pi of any kind (Be aware that if you use a slow Pi, the video rendering will take a long time.)
  2. Micro sd card
  3. Display and HDMI cable (For the Raspberry Pi)

Connect the Camera

image.png

Before booting your Pi, you’ll need to connect the camera.


We will need to install the camera. To do this, go to the ribbon slot and use two fingers to pull up on both sides of the connector gently.

Now the connector is open. Insert the ribbon cable with the metal leads facing away from the Ethernet port. Make sure it's lined up, then gently press down on the connector. The cable should be locked in place, and we can now move on.

Connect the Button

picamera-gpio-setup-2.png

Using your breadboard and jumper leads, connect the Pi to the button as shown in the diagram below: (Image credit: RaspberryPi.org)

Install Raspberry Pi OS

The next step is installing Raspberry Pi OS.

If you are new to installing an Operating system on a Raspberry Pi, follow these steps:

  1. Go to www.raspberrypi.com/software/
  2. Download the imager by clicking the download button when you scroll down
  3. Open the App, click "Operating System," click Raspberry Pi OS (Other)
  4. Scroll down and click Raspberry Pi OS Lite
  5. Insert SD Card
  6. Click Storage and click on your Micro SD card.
  7. Click Write
  8. Insert SD card to the Raspberry Pi
  9. Connect a good power supply to the Raspberry Pi

Create a Folder

You must create a new folder to store your individual photos, and using those photos, you can make a short film!

In the terminal window, enter 

mkdir animation

This makes a folder called "animation" that is used to store all your photos that you later turn into a short film.

Enter the Code

thonny_ide_start.png

If you are using the Raspberry Pi directly, you can just open Thonny from the apps list, (Image above), but if you are using a mac or windows, use this link to download and install the app. then, type in the following code:


from picamera import PiCamera
from time import sleep
from gpiozero import Button

button = Button(17)
camera = PiCamera()

camera.start_preview()
frame = 1
while True:
  try:
    button.wait_for_press()
    camera.capture('/home/pi/animation/frame%03d.jpg' % frame)
    frame += 1
  except KeyboardInterrupt:
    camera.stop_preview()
    break

This code basically waits until the button is pressed, then it captures a photo. When we use the Keyboard Interrupt key, (Ctrl + C), the program stops and you can turn the photos into a video.

Start Your First Video!

Set up your animation subject, ready to start the stop motion animation.


Press the button to capture the first frame, then rearrange the animation subject and press the button again to capture each subsequent frame.


Once all the frames have been captured, press Ctrl + C to terminate the program.

Generate the Video!

Right now you have a bunch of still photos and you need to turn them into a real video. Here is how:


To generate the video, begin by returning to the terminal window.

ffmpeg -r 10 -i animation/frame%03d.jpg -qscale 2 animation.mp4


Play your video using vlc!

vlc animation.mp4

You Are Done!

Now you can make any animation you want.


The video above is what I made for this project.


Thank you for reading this and have fun stop-motioning!