Push Button Stop Motion With Raspberry Pi!
by drjhxie in Circuits > Raspberry Pi
737 Views, 2 Favorites, 0 Comments
Push Button Stop Motion With Raspberry Pi!
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
- Raspberry Pi of any kind (Be aware that if you use a slow Pi, the video rendering will take a long time.)
- Micro sd card
- Display and HDMI cable (For the Raspberry Pi)
Connect the Camera
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
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:
- Go to www.raspberrypi.com/software/
- Download the imager by clicking the download button when you scroll down
- Open the App, click "Operating System," click Raspberry Pi OS (Other)
- Scroll down and click Raspberry Pi OS Lite
- Insert SD Card
- Click Storage and click on your Micro SD card.
- Click Write
- Insert SD card to the Raspberry Pi
- 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
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!