Timelapse Photography with Raspberry Pi Zero

long-camera-adaptor-for-pi-zero
PDF Printer    Send article as PDF   

This tutorial will guide you through taking photos using a Pi Zero and camera, to make a simple timelapse-capturing device. Use it to make a timelapse of a plant growing with the delay set to a day, or the progress on your building work with hourly photos, or a soldering project with a photo every 5 seconds.

Enable the camera

This tutorial assumes you have already set up your OctoCam as per the instructions. If you’re using a camera and a Pi, make sure the camera is connected.

In the Terminal, type sudo raspi-config and press Enter. This will bring up a menu on the screen. You’ll need to press 5, then choose option 1 to enable the camera, and then choose yes. Once you finish with the menu you should get prompted to reboot. This needs doing!

Get the libraries for the camera

Once your Pi has rebooted, open a Terminal again and type:

This will install the libraries for the camera that we’re going to use. You don’t need to reboot after this step.

Write some code to take a picture

You can use the code timestamp to time stamp the image name, but it puts colons in it, which makes the filenames tricky, and it’s why we need to create our own timestamp.

If you run this code now, while you’re hooked up to a monitor, you should see a preview of your camera and it will freeze every time it takes a photo. To get out of the preview, you need to press ctrl and d.

It’s a good idea to have a look and check the image is the quality you want, even if you end up with something like this.

Kitten & Raspberry Pi 3

Last step. Running the code.

You can run your code now, and place the camera somewhere, or you can use Cron to make your code run when the Pi starts, which is what I did for this sunrise video.

Open a terminal, and type  crontab -e. If it’s the first time that you’ve edited your crontab, then it will ask you to choose which editor you’d like to use. I prefer to use nano, and this is the default, so you can just press enter to select it.

At the top of the crontab, you’ll see a lot of blurb about how to use it, on lines that are commented out (they begin with #). Scroll all the way down past these lines to the bottom (using the down arrow key) and type, on the last line, the following:

@reboot python /home/pi/TimeLapse/TimeLapse.py

We’re using the full path to the script, all the way from the root. Last, we add  & to the end to run the script in the background, so that the Pi will boot as normal.

Once you’ve added that line, press  control-xy and  enter to exit nano.

It should say  crontab: installing new crontab assuming you saved the crontab successfully.

Type  sudo reboot to reboot your Pi, and the rainbow example should run after a few seconds.

To remove the  @reboot command, just type  crontab -e again, delete the offending line, and then exit and save as before.

Stitching the photos together

There are loads of ways of stitching the photos together, and there’s a guide on the Raspberry Pi website detailing a few methods. We used a variant on the avconv option, called ffmpeg. If you are using Stretch it works straight off, if you’re using Jessie you’ll have to do a sneaky direct install.

Stretch version

Jessie version

Bear in mind that this takes FOREVER – about 5 minutes on my Pi 3 for 429 photos. Go and make yourself a coffee, or two!

Here’s the result:

The super-duper version!

When a Pi is on and taking pictures, if you don’t have a screen connected, it’s difficult to tell if anything is happening. Adding an LED that blinks when it’s about to take a picture is one way of showing this. We took the biggest LED we could find and hooked it up to the GPIO pins.

If you want to do this, you’ll need to connect a 330 Ohm resistor to the short leg of the LED to stop it sucking up too much current. Join the negative (resistor) end to a ground pin, and the positive end to BCM pin 18 on your Pi.

You can do this with a breadboard, or by soldering some jumper jerky onto the components. See the photo for our version.

components

You’ll need to add in a few lines of code to define the LED, switch it on before taking a photo, and off after.

A note on storage space and power consumption

A Pi Zero and camera could draw up to 240mAh. There’s not much difference between the Zero and the Zero W in this case. This means if you have a battery pack that says 1200mAh, it will last this combination 1200/240 = about 5 hours.

If you set the resolution to 1920×1080, where each picture is 1.1MB, then a 16GB SD card with NOOBS installed (approx 11GB left) will store approximately 10,000 photos. At one every second, that’s about 2hrs 45mins or, at one every 10 seconds, that’s about 27 hours! Note: all calculations are approximate!

Previous Post
Pi MusicBox

Build a Raspberry Pi Streaming Music Player

In this tutorial, I will be going through steps to making your very own Raspberry Pi music player. This process is pretty straightforward, so you shouldn’t come across any problems ... Read more

Next Post

Raspberry Pi '3 B+' Review

A new PI is out, but is it a worth upgrade? Before moving any further, it’s however important to note that this is not a brand-new product or a radical ... Read more

Short URL: http://tinyurl.com/y9l2q4g5

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.



Do NOT follow this link or you will be banned from the site!