Easy Timelapse: Raspberry Pi and PiCamera (V3 Wide)

by AndreaFavero in Circuits > Raspberry Pi

8093 Views, 112 Favorites, 0 Comments

Easy Timelapse: Raspberry Pi and PiCamera (V3 Wide)

Timelapse system, with Raspberry Pi and Picamera V3 (wide)

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...


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:

  1. setting the parameters in a simple text file.
  2. automatic erasing of the old pictures.
  3. automatic video rendering.
  4. shared folder to easily access the pictures/movies via the file manager from your PC.
  5. based on a rather recent version of Raspberry Pi OS as well as PiCamera model.


Main timelapse characteristics are:

  1. Raspberry Pi 4b (it works well on Zero2 for picture capsuring, it doesn't for video rendering)
  2. PiCamera V3 wide
  3. Mini display for feedbacks
  4. 3D printed case, with:
  5. standard fixing for 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 a 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. stopt shooting time (hh:mm)
  15. shooting interval (seconds)
  16. consecutive shooting days (unit)
  17. HDR (y/n)
  18. autofocus (y/n)
  19. illuminance threshold (lux)
  20. automatic video rendering (y/n); the video lenght can be set to:
  21. predefined fps (frame per second value)
  22. predefind video time (in seconds), and the fps will be adapted
  23. automatic pictures erasing and wastebin emptying (y/n)
  24. 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 enable, the max resolution for this camera is 3Mb allowing full HD timelapse video (1920x1080); More info about the V3 cavera at: camera-module-3-product-brief.pdf (raspberrypi.com)


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, construction cam, etc


Other tutorials:

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

Supplies

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

  1. 1x Raspberry Pi 4b (ca 59€)
  2. 1x Picamera V3 Wide (ca 42€)
  3. 1x Power supply (ca 10€)
  4. 1x Display Mini PI TFT 1.3" (ca 5€ at Aliexpress.com)
  5. 1x microSD V30 32Gb or higher (ca 10€)
  6. Filament for the 3D printer
  7. Screws, see list below


Screws, nuts and washers:

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

3D Print the Parts

`Cover.PNG
Arm.PNG
Base.PNG
Camera_cover.PNG
Camera_support.PNG

Notes:

  • Printing orientation as per images
  • Do not use support

Assemble Arm - Cover

IMG_20230701_134859_rid.jpg
IMG_20230701_134859_rid.jpg
M3_nuts_washers.jpg
  1. 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.
  2. 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....

Insert the Nut for Tripod to the Base

IMG_20230702_120326.jpg
IMG_20230702_120348.jpg

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.

Assemble Display Support Leg

display_foot1.jpg
IMG_20230702_121456_2.jpg

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

Complete the Assembly

display_foot2.jpg
IMG_20230702_121545.jpg
IMG_20230702_123429_2.jpg
  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.

How It Looks Like

IMG_20230716_174430.jpg
IMG_20230716_174056.jpg
IMG_20230716_174141.jpg
IMG_20230716_174227.jpg
IMG_20230702_125252.jpg
IMG_20230702_125115_2.jpg

Raspberry Pi Setup

Setting up the Timelapse:

1. Flash bullseye OS (32 bit) 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, set VNC Display resolution and BOOT type: sudo raspi-config

11.1 Interface Options, SSH  (then YES)

11.2 Interface Options: SPI  (then YES)

11.3 Interface Options: VNC  (then YES)

11.4 Select Display Option, VNC Resolution (choose the one that suits your PC monitor, then OK).

11.5 To enable preview feature, select System Options, Boot / Autologin, Desktop Autologin.

11.6 Select: Finish

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

12. Connect via VNC (i.e. via realVNC)

13. Open the Terminal, and 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=0777

public=no

4. Save and close the samba config file: Ctrl+X then Y then 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.

How to Use It

settings.PNG

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:

  1. shooting start (hh:mm).
  2. shotting stop (hh:mm).
  3. interval between shoots (seconds).

Other options are:

  1. V2 or V3 camera. For the V3 camera, add --v3_camera argument.
  2. Start shooting immediately (true/false); If true, then shooting start and it will stop after period_hhmm.
  3. Start and Pause shooting via the buttons at the display.
  4. Camera resolution.
  5. HDR (High Dinamic Range) function at camera (true/false).
  6. 180deg rotation of the captured image.
  7. VNC camera image preview (true/false).
  8. Camera preview on the tiny display.
  9. Erasing older pictures from the microSD card that includes emptying the Wastebasket (true/false); This is done at the starting of a new job.
  10. Auto video generation after the shooting (true/false); this can be based on:
  11. predefined fps (frame per second value.
  12. 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).
  13. Number of shooting days (integer), for the period defined by start and stop time.
  14. Folder name where saving the pictures and generating the movie.
  15. Usage of the display at Raspberry Pi (true/false).
  16. 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:

  1. Switch on the Raspberry Pi.
  2. Connect to it; If you want a camera preview, a remote desktop connection is necessary like VNC Viewer.
  3. The relevant files are into the timelapse folder: cd timelapse
  4. 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)
  5. Run the script: python timelapse.py (changes at the settings are only loaded at the scrip start). Run python timelapse.py --v3_camera for force using the V3 camera.
  6. Feedbacks on the display:
  7. At the start it shows the main settings, including an estimation of pictures quantity the microSD can store
  8. Time left for the first picture
  9. After the first picture is taken, it indicates the picture progressive number
  10. After the last picture is taken, if set, it indicates the video editing status
  11. In case the movie is not sattisfactory: 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.
  12. By pressing one of the buttons for 5 seconds the cycle is stopped
  13. By pressing one of the buttons for more than 10 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.


Methods defining the shooting approach:

1) Shooting predefined between start_hhmm and stop_hhmm, for one or multiple days:

  1. Set start_now as False and local_control as False.
  2. This method ends automatically, once the stop_hhmm of the last day is reached.

2) Shooting starting once the script is launced (eventually automated at the Raspberry Pi boot), and lasting for the period_hhmm:

  1. Set start_now as True and local_control as False.
  2. Also in this case the pictures quantity are predefined.
  3. Can be imputed more than 2 digits at the hours of period_hhmm, therefore the shooting can be proceed over days, weeks, etc.

3) By manually starting and pausing the shooting, eventually multiple times, via the buttons on the display:

  1. Set local_control as True.
  2. In this case the pictures quantity aren't predefined.

In all cases:

  1. The interval between shots is defined by interval_s
  2. A long press (>10 secs), of one of the buttons, will terminate the shooting and the script.



Power outage:

If the timelapse system is used to capture a long event, like a construction, it might happens to have power outage.

Starting from 07August 2024, the code takes care of this...

This feature works by setting "automatic script start at Raspberry Pi booting (see above)" and by settings "date_folder" : "False" and "erase_pics" : "False".

Once the Raspberry Pi will be powered after the outage, the lates picture suffix will be used as starting reference for the upcoming new pictures.

In case of mutiples day shooting, the days already covered will be counted.

Some Results As Example

IMG_20230818_203255_2.jpg
VIDEO_RECORDING_WARNING.JPG

Faire event (Hannover Maker Faire 2023): https://youtu.be/wAfPYTDUh8o (recording in pubblic might require a proper warning).

Out of the windows: https://youtu.be/wO7wYDtcbZA

PWM on Display

IMG_20231119_223851.jpg
IMG_20231119_223933.jpg
IMG_20231119_223847.jpg
IMG_20231119_223827.jpg

This type of display keeps the backlight always ON; In case you'd like to reduce power consumption, it is possible to control the backlight via PWM via a little modification to the display

1) Make a bridge between Pin 12 (GPIO18) and Pin 15 (GPIO22) as per pictures.

2) Set a couple of parameters to the settings.txt file: modified_disp to True and disp_bright to a integer value between 0 and 100.


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.


Revisions

Rev 0.1 on 19/11/2023: Added multiple features, also in line with the received feedback.

Rev 0.3 on 07/08/2024: Recovery from power outage.

Rev 0.5 on 25/08/2024: Added recovery from power outage also when "start_now". Added Lux based shooting.

Rev 0.7 on 15/10/2024: Solved bug that erased pictures after power outage.

Provide Feedback

Feedback.PNG

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

If you have built this project, please add it to the "I MADE IT !" section: Search for the yellow button "I MADE IT!" below.