Raspberry Pi Time Lapse
by rjconcepcion in Circuits > Raspberry Pi
594 Views, 3 Favorites, 0 Comments
Raspberry Pi Time Lapse
I bought a Raspberry Pi Zero W kits some months ago and I have not had time to work with it. I decided to make an easy project with a camera.
This project will help you to start learning to use a Raspberry Pi and you will see that board as a great tool for your future projects.
We need a Raspberry Pi Zero W kit. That contains all the components that we will need. We also need a camera module.
Supplies
Install Raspberry Pi OS
First, you need to write the Raspberry Pi OS image in the micro-sd card. You can use Raspberry Pi Imager software to do that.
You can choose the OS in the software. It will take a lot of time if you do not have a good internet connection. That is why I prefer download the image first. I recommend download the Raspberry Pi OS (32-bit) with desktop and recommended software. Then you can use the Raspberry Pi imager to write that image in the micro-sd card.
Initial Settings
After writing the image on the micro-sd card, you should insert it in the Raspberry Pi, plug a monitor or TV, keyboard, mouse and turn it on.
You should see the screens that I show you in the pictures.
Do not worry, you just must wait until the OS installation finish.
You should finish the installation by completing the wizard. It will ask for a password, time zone, configure a wifi network. Make sure to activate the camera, ssh, and VNC interfaces.
Access to the Raspberry Pi
After the initial settings, you can access the Raspberry Pi using the VNC remote desktop program.
If you do not have a VNC Viewer, you should download it.
Run VNC Viewer. It will ask for an IP address. You should put the Raspberry Pi IP address. After that, it will ask for the user and password.
After inserting the credentials you will be inside your Raspberry Pi. If you want, you can unplug the monitor, keyboard, and mouse. You only need your Raspberry connected to your network and you use VNC.
Connect the Camera
Now you should turn off the Raspberry Pi. In the next video, you can see how you should connect the camera to the Raspberry Pi. After that turn on the Raspberry Pi.
Folder to Store the Pictures
You should create a folder to store the pictures and the Python script. Go to the file explorer and create a folder in the same way you use to create it in Windows.
Writing the Script
Let write the code for our script. You will use Python. Open the MU application locate it in the programming section in the main menu. If it asks for the language you should choose Python.
# time lapse script
#import libraries and functions
from time import sleep import picamera
espera = 60 #time between pictures
with picamera.PiCamera() as foto:
foto.resolution = (1280, 960) #picture resolution for filename in foto.capture_continuous('/home/pi/fotos/img{timestamp:%H-%M-%S-%f}.jpg'):
sleep(espera)
You should replace the path where your pictures will be saved. In my case I use /home/pi/fotos/ You can test the code click on the play bottom. You should wait for 60 seconds after that time checks the folder where you store the pictures. You can change that time if you want. After that paste the code and save it. You can put the name that you prefer. The extension should be.py.
Run the Script at the Start
We need our script to start when the Raspberry turns on. For that activity, we will create a file with that instruction.
Open a terminal a write the following commands:
mkdir /home/pi/.config/autostart
nano /home/pi/.config/autostart/programa.desktop
we have created a file call programa.desktop. Now you should write the following inside that file:
[Desktop Entry]
Type=Application
Name=programa
Exec=/usr/bin/python3 /home/pi/yournamescript.py
Change yournamescript with the name that you put to your script. To save the changes use ctrl + o and ctrl + x to exit.
Test Autostart
Reboot the Raspberry and when it is up, open a terminal and write the following command:
sudo ps -ax | grep python
Another Way
There is another way to take pictures every certain time. I will show you how do it using a shell script and the crontab tool. You can use this way instead write a Python code and configure the autostart execution.
Shell Script
You could write a shell script and save it in the same folder that you create for the pictures.
Open an empty file and write the following:
#!/bin/bash
FECHA=$(date +'%Y-%m-%d_%H%M')
raspistill -w 1280 -h 960 -o /home/pi/fotos/$FECHA.jpg
Save the file putting the extension.sh. After that, you should set execute permission to that script. For that use the following command:
chmod +x nameyourscript.sh
Crontab Tool
Now you need to configure a task to execute your script every certain time. FOr that propose we will use crontab.
Open a terminal window and write the following:
crontab -e
At the end of the file write the following:
*/1 * * * * /home/pi/fotos/yourscriptname.sh
That crontab executes your script every one minute. You can change that value by replacing the number one for the number of minutes you prefer.
Conclusion
You have to choose what option you prefer for your time-lapse project. I recommend using one of them.
I hope you enjoy this project as much as I have. See you in the next project.