How I built a simple timelapse system with Raspberry Pi and a PiCamera

Nov 1, 2023

Andrea Favero

Dunja Djudjic is a multi-talented artist based in Novi Sad, Serbia. With 15 years of experience as a photographer, she specializes in capturing the beauty of nature, travel, and fine art. In addition to her photography, Dunja also expresses her creativity through writing, embroidery, and jewelry making.

How I built a simple timelapse system with Raspberry Pi and a PiCamera

Nov 1, 2023

Andrea Favero

Dunja Djudjic is a multi-talented artist based in Novi Sad, Serbia. With 15 years of experience as a photographer, she specializes in capturing the beauty of nature, travel, and fine art. In addition to her photography, Dunja also expresses her creativity through writing, embroidery, and jewelry making.

Join the Discussion

Share on:

Raspberry Pi PiCamera timelapse diptych

I’ve always been fascinated by timelapse videos, perhaps because my patience is dwindling as I grow older.

Anyhow, I wanted to capture memories of an event where I wouldn’t have been able to take pictures, and none of my family members could join me to help. This was the trigger to start the timelapse project, giving a purpose to the spare Raspberry Pi 4b I had lying around for some time.

Yes, you’re right, I was just searching for an excuse to start this project, and I did find it…

YouTube video

In internet there are many tutorials for Timelapse systems, based on Raspberry Pi; Compared to others, this system offer an interesting combination of features, like:

  • Setting the parameters in a simple text file.
  • Automatic erasing of the old pictures.
  • Automatic video rendering.
  • Shared folder to easily access the pictures/movies via the file manager from your PC.
  • Based on a rather recent version of Raspberry Pi OS as well as PiCamera model.

Main timelapse characteristics are:

  1. Raspberry Pi 4b
  2. PiCamera V3 wide
  3. Mini display for feedback
  4. 3D printed case, with:
  5. standard fixing for a tripod
  6. rotating arm for the camera
  7. storage for the excess of camera ribbon cable
  8. easy to access microSD
  9. Raspberry Pi OS “Bullseys”
  10. Programmed in Python, using picamera2 library
  11. Timelapse settings are stored in an easy to edit json text file.
  12. Some of the parameters in the settings file provide insight into the Timelapse capabilities:
  13. start shooting time (hh:mm)
  14. stop shooting time (hh:mm)
  15. shooting interval (seconds)
  16. consecutive shooting days (unit)
  17. HDR (y/n)
  18. autofocus (y/n)
  19. automatic video rendering (y/n); the video lenght can be set to:
  20. predefined fps (frame per second value)
  21. predefined video time (in seconds), and the fps will be adapted
  22. automatic pictures erasing and wastebin emptying (y/n)
  23. and more….

The used camera is a PiCamera V3, having interesting features like autofocus, hdr and it’s available on different FoV / UV-lenses combinations; My choice went for the V3 Wide version, having more than 100degrees as horizontal angle…. quite a wide FoV.

When HDR is enabled, the max resolution for this camera is 3Mb allowing full HD timelapse video (1920×1080). More info about the V3 camera here.

My purpose:

My intention has been to document the visitors approaching the CUBOTino stand at Hannover Maker Faire 2023. Anyhow, by testing the system at sunrise and sunset, I had already been rewarded by this project.

Possible usage:

Sunset, sunrise, plant and flowers growing, slow-moving events, etc

Other tutorials:

There are many tutorials on the internet to make timelapse systems. I found an interesting and well made the one from Carolin Dunn

Supplies

The total cost of the project, on July 2023, has been ca 130€ (shipments excluded)

Screws, nuts, and washers:

  • 1x 1/4″-20 UNC (nut with thread for tripods)
  • 2x M2.5x4mm cylindrical head
  • 4x M2.5x5mm cylindrical head
  • 4x M3x14mm cylindrical head
  • 1x M3x8mm cylindrical head
  • 6x M3x8mm conical head
  • 6x M3 nuts
  • 11x Washers for M3

Step 1: 3D Print the Parts

Notes:

  • Printing orientation as per images
  • Do not use support

Step 2: Assemble Arm – Cover

  • Inserts the (4x) M3 nuts into the slots, after aligning the nut as per image; Forcing the nuts into the slots requires some force, peraps a little hammer might help.
  • Add (8x) washers in between the arms, as per image; This generates friction between the arms and limit the screws unlocking. Also this step requires some brutal force….

Step 3: Insert the Nut for Tripod to the Base

Force the 1/4″-20 UNC nut into the slot.

Note: Pay attention to the complete insertion of the nut, to prevent it from short circuiting the Raspberry Pi; In case of doubts, add a piece of tape on top of the nut.

Step 4: Assemble Display Support Leg

The display foot can be easily made by a screw, two nuts and three washers.

The foot is necessary to support the display when pressing on the buttons, to prevent from bending inward and damaging its own connector and the GPIO connector.

Step 5: Complete the Assembly

  1. Position Raspberry Pi on the Base, as per image, and fix it with the screws.
  2. Insert the camera ribbon into the CSi connector (ribbon’s contacts oriented as per picture).
  3. (Optional) Insert the display on the GPIO connector (the first 16 pins). The display leg, made with screw and nuts, has to be prepared upfront.
  4. Connect the ribbon to the PiCamera module.
  5. Position the Cover onto the base; Fix it with the 6 screws.
  6. Squeeze the PiCamera module in between the camera_support and camera_cover; Fix the Cover with the 2 screws.

Note: On the base there are a couple of side holes that can be used for other fixing systems. For instance, brackets with suction caps to suspend the system on a window, and for that reason the camera arm har large rotation angle.

Step 6: What It Looks Like

Step 7: Raspberry Pi Setup

Setting up the Timelapse:

1. Flash bullseye OS (or newer) in a fast (V30) microSD card, via Raspberry Pi Imager or other imager tool. The image could be downloaded from this official link (https://downloads.raspberrypi.org/raspios_oldstable_armhf/images/raspios_oldstable_armhf-2023-10-10/2023-05-03-raspios-bullseye-armhf.img.xz)

1.1 It is convenient to set a meaningfull Hostname (i.e. timelapse).

1.2 For convenience with the script, leave Username as “pi”, while you’re invited to set your own password (do not use ‘raspberry’ as password).

1.3 Configure the LAN from which you’re going to initially connect (i.e. via SSH).

2. Into the “boot” folder copy the wpa_supplicant.conf text file with included the wi-fi connections you might need (phone AP is a convenient one); An example of this file is provided as reference, to be personalized with your Country digits, the Wi-Fi SSID and Passwords.

3. Into the “boot” folder make an empty text file named ssh (without extention); An example of this file is provided.

4. Insert the microSD into the Raspberry Pi, power on and wait until the green LED stops blinking.

5. Check for the Raspberry Pi IP in your network.

6. Connect to the Raspberry Pi via SSH (i.e. via Putty).

7. Update the system: sudo apt update

8. Upgrade the system: sudo apt upgrade -y

9. Install the picamera library (it should be already installed): sudo apt install python3-picamera2

10. Install the driver for the display: sudo pip3 install ST7789==0.0.4

11. Enable the SSH, SPI, VNC and VNC Display resolution: sudo raspi-config

11.1 Select: Interface Options

11.2 Select: SSH  (then YES)

11.3 Select: Interface Options

11.4 Select: SPI(then YES)

11.5 Select: Interface Options

11.6 Select: VNC  (then YES)

11.7 Select: Display Options

11.8 Select: VNC Resolution (choose the one tha better suit your PC monitor, then OK).

11.9 Select: Finish

11.10. Confirm the reboot with YES (if you miss it, from the terminal type: sudo reboot)

12. Connect via VNC (i.e. via realVNC); Be noted the IP shoud end with ‘comma one’ (:1)

13. Open the Terminal (this step can be done from step 7)

14. Clone the repository: git clone https://github.com/AndreaFavero71/timelapse.git (this step can be done from step 7)

(Optional) Making a shared folder via SMB protocol:

I found convenient to share a Raspberry Pi folder via SMB protocol, allowing quick access via a pc. For this reason, the pictures_folder is generated in the shared folder, making easy to access and copy the timelpase movie from the Raspberry Pi.

1. Install samba; From the Terminal: sudo apt install samba samba-common-bin (confirm with y, and select yes at DHCP package wins)

2. Make the folder to share: mkdir /home/pi/shared(shared is the folder name for the shared folder)

3. Edit samba config file: sudo nano /etc/samba/smb.conf  (at the file end add the below 6 rows, Ctrl Ins to paste)

[shared]

path=/home/pi/shared

writeable=yes

create mask=0777

directory mask=07777

public=no

4. Save and close the samba config file: Ctrl+Xthen Ythen Enter

5. Associate your username:sudo smbpasswd -a pi  (pi is the username)

  once requested enter your password (the one to access the Raspberry Pi)

  once requested enter your password again (the one to access the Raspberry Pi)

  at this point there should be a confirmation “Added user pi.”

6. Restart smb service: sudo systemctl restart smbd

7. Get the Raspberry Pi IP: hostname -I (capital I)

8. On your File Explorer Adress bar paste the IP, after the prefix “\\” and followed by the postfix “\shared”: \\xx:xx:xx:xx\shared

9. Enter the password, and check it to get memorized.

10. The Raspberry Pi “shared” folder should be visible as a network folder; map it as a drive for convenience.

(Optional) automatic script start at Raspberry Pi booting

  1. Edit the crontab: sudo crontab -e
  2. Add at the end:

@reboot /bin/sleep 5; bash -l touch /home/pi/timelapse/timelapse_terminal.log && chmod 777 &_ (single raw)

@reboot /bin/sleep 5; bash -l /home/pi/timelapse/timelapse_bash.sh > /home/pi/timelapse/timelapse_terminal.log 2>&1 (single raw)

  1. Save and exit: Ctrl X, followed by Y, followed by Enter.
  2. After Raspberry Pi boots, the timepse.py script will be excuted according to parameters saved at settings.txt file.

Note: To prevent the script from executing at boot, edit the crontab, comment out the two commands and save.

(Optional) automatic Raspberry Pi shut-off

Edit the timelapse_bash.sh: nano timelapse_bash.sh

Toward the end of the file, uncomment the row “# sudo halt -p

Save and exit: Ctrl X, followed by Y, followed by Enter.

Step 8: How to Use It

The overall idea is to predefine the job, let it go, and collect the assembled movie once the job is done.

The system is based on a python script and a text file for the settings (the only file to be edited).

The settings.txt file includes:

  • shooting start (hh:mm).
  • shotting stop (hh:mm).
  • interval between shoots (seconds).

Other options are:

  • Start shooting immediately (true/false); If true, then shooting start and shotting stop time are ignored.
  • VNC preview (true/false).
  • Camera resolution.
  • HDR (High Dinamic Range) function at camera (true/false).
  • Erasing older pictures from the microSD card that includes emptying the Wastebasket (true/false); This is done at the starting of a new job.
  • Auto video generation after the shooting (true/false); this can be based on:
  • predefined fps (frame per second value.
  • predefind video time (in seconds), and the fps will be consequently adapted; For this choice fix_movie_t (true/false) and movie_time_s (seconds).
  • Number of shooting days (integer), for the period defined by start and stop time.
  • Folder name where saving the pictures and generating the movie.
  • Usage of the display at Raspberry Pi (true/false).
  • Some parameters for the display, like width, height, horizontal and vertical shif, orientation.

Note: Boolean variables can be set as true/false or 1/0 or yes/no or….

Usage:

  • Switch on the Raspberry Pi.
  • Connect to it; If you want a camera preview, a remote desktop connection is necessary like VNC Viewer.
  • The relevant files are into the timelapse folder: cd timelapse
  • Edit the settings.txt file (quite self explanatory) and set the parameters according to your needs: nano settings.txt (save the file, with Ctrl + X, followed by Y, followed by Enter)
  • Run the script: python timelapse.py (changes at the settings are only loaded at the scrip start)
  • Feedbacks on the display:
  • At the start it shows the main settings, including an estimation of pictures quantity the microSD can store
  • Time left for the first picture
  • After the first picture is taken, it indicates the picture progressive number
  • After the last picture is taken, if set, it indicates the video editing status
  • In case the movie is not satisfactory: Via the script video_render.py the video can be (re)made by changing some parameters. For this reason, when set, the pictures aren’t automatically erased after a job completion; pictures are automatically erased at the start of a new job.
  • By pressing one of the buttons for 2 seconds the cycle is stopped
  • By pressing one of the buttons for more than 6 seconds the script is quitted; If the automating shut-off is set, this is the way to safely close stuff before unpowering the Raspberry Pi.

Step 9: Some Results As Example

Faire event (Hannover Maker Faire 2023). Note that recording in public might require a proper warning:

YouTube video

Out of the windows:

YouTube video

Step 10: Possible Improvements

  1. The screws, at camera arm, tend to unlock by rotating the arm. Self locking nuts will be preferable, yet the design is not adapted for those nuts yet.
  2. Increase and improve feedback via the display (it’s still quite under used).
  3. I’m open for your suggestions.

Some notes on the project:

  • I started this project to a need, and I used the spare Raspberry Pi board I had available back then.
  • To make this system battery efficient, a different Raspberry Pi board (Zero2W) would be a better choice, together with a more efficient control of the display. In this way, it seems possible to reach 24 hours of autonomy with a Raspberry Pi Zero2W powered via a power bank of 10000mA and getting more than 5000 pictures.

Step 11: Provide Feedback

If you’ve enjoyed the project and/or you’ve suggestions, please feedback.

About the Author

Andrea Favero was born in Italy in 1971 and moved with his family to The Netherlands a few years ago. In his free time, he likes to build “useless devices”, a pretest to learn coding and control theory. You can find more of his work on YouTube and GitHub. This article was also published here and shared with permission.

Filed Under:

Tagged With:

Find this interesting? Share it with your friends!

DIPY Icon

We love it when our readers get in touch with us to share their stories. This article was contributed to DIYP by a member of our community. If you would like to contribute an article, please contact us here.

Join the Discussion

DIYP Comment Policy
Be nice, be on-topic, no personal information or flames.

Leave a Reply

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

3 responses to “How I built a simple timelapse system with Raspberry Pi and a PiCamera”

  1. Pete Avatar
    Pete

    Thank you, great tutorial. I am considering it for mushroom growing, which may likely add moisture onto the lens. I will have to use power supply as battery wont be a sustainable option for say 2-5 week timelapse durations.
    Any tips for such long and slow captured events?
    Looking forward to it.

    1. Andrea Avatar
      Andrea

      Hi Pete,
      for the moisture a very little fan pointing to the camera lense should do the job; Fan 30mm x 30mm from 5Vdc as reference: https://www.amazon.com/Dorhea-Raspberry-30x30x7mm-Brushless-Cooling/dp/B07G97L9TL/ref=sr_1_3?crid=29FB4ZCD6ARVO&keywords=30mm%2Bfan%2B5V&qid=1699031558&sprefix=30mm%2Bfan%2B5v%2Caps%2C157&sr=8-3&th=1.
      For the very long coverage the challenging part might be 1) preventing the camera from moving and 2) light conditions.
      If the location has WiFi coverage, 3) the usage of SMB protocol will facilitate the checking if any change is needed (camera positions, settings, etc) and 4) perhaps a daily copy of the pictures to be sure an eventual microSD damage won’t let you empty hands.
      I recently saw something that might better fit your task, though it isn’t open source: https://www.youtube.com/watch?v=yvn7JGhRLxo.

      Please let me know if more info are needed.
      Regards, Andrea