Easy Timelapse: Raspberry Pi and PiCamera (V3 Wide)

7.0K10843

Intro: Easy Timelapse: 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:

  • 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 (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. automatic video rendering (y/n); the video lenght can be set to:
  20. predefined fps (frame per second value)
  21. predefind 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 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, etc


Other tutorials:

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

STEP 1: 3D Print the Parts

Notes:

  • Printing orientation as per images
  • Do not use support

STEP 2: Assemble Arm - Cover

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

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: How It Looks Like

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

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 it will stop after period_hhmm.
  • Start and Pause shooting via the buttons at the display.
  • Camera resolution.
  • HDR (High Dinamic Range) function at camera (true/false).
  • 180deg rotation of the captured image.
  • VNC camera image preview (true/false).
  • Camera preview on the tiny display.
  • 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 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.
  • By pressing one of the buttons for 5 seconds the cycle is stopped
  • 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:

  • Set start_now as False and local_control as False.
  • 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:

  • Set start_now as True and local_control as False.
  • Also in this case the pictures quantity are predefined.
  • 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:

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

In all cases:

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

STEP 9: Some Results As Example

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

STEP 10: PWM on Display

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.


STEP 11: 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.


STEP 12: Revisions

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

STEP 13: Provide Feedback

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.

36 Comments

Hi-

I tried running from terminal with the display removed, and it finished but went through a few errors. I have to guess the camera is messing up, but not sure. Since only the pi and the camera are here, the erratic nature suggests hardware, unless you have any other clues. I need to order another camera anyway.

Thanks again for your response - I hate to waste your time with my stupid problems!

John


Hi John, I'm glad to help where I can :-).

Based on https://github.com/raspberrypi/libcamera/issues/61 , the "error iparpi .... pdaf data in unsupported format" seems related to a hardware defect of the camera. You might want to contact the vendor to get the camera exchanged.

For the last error, on erasing a picture, I'm looking into it right now. It is already clear I'll release a fix for it by today.

I hope You'll get the camera replaced.

Regards, Andrea


Edit 07/02/2024: Released updated timelapse.py

Hi Andrea-

Another great project! I have been playing with it, some cool videos. The only problem I have had is if I set it for a couple of hours, it often just stops part way through, no errors, but just stops taking pictures. I have tried a couple of pi's (now pi 4 8 gb) and had the same problem, so my theory is that maybe the camera or display stops responding and it just waits. OS still running fine - is there a way to find out what could be hanging it up here?

Still having fun with Cubotino - working perfect!

Thanks again for a fun project!

John Hanson

Hi John,

I used to shoot for much longer than 2 hours, and without this issue. I'm on a Pi 4 2Gb.

Please try running the code directly from the terminal, as i have done so far (python timelapse.py).

I'm running now a test with settings as per your picture (again from the terminal), yet I believe are very commong settings that I had surely tested: Tomorrow I'll check the result.


Edit 06/02/2024:

I did test the code and it has worked well by running it from the terminal and from Thonny as well; A couple of pictures are attached.

I don't think the code has memory leak, yet you might check the memory ('free') from time to time.

Another attempt would be to use a different microSD: Perhaps the code breaks when tryiong to write a damaged card location.

Regards, Andrea

Update to my last posting:

Hello again Andrea
It works! Even with the camera V2.1

In my first try I used the camera V1.3 - that was my mistake.
Pictures will follow soon.

---------------------------------------------------
The former posting:


Hello Andrea
Again I follow another great project of yours.
I have set it up so far but when trying to start the python-file I get an error.

Do I need to use the camera model V3 or can I use V2.1 as well?
Assuming that I will need V3 I placed an order and it should arrive within this week.

There is a misspelling in your code:
directory folder=07777 <----- 0777?
pubblic=no <-- public?


Thanks a lot for this new gadget.
Matze
Hi Matse,
I'm glad you made this project.
Thank you for reporting the typos; Please note there is one more than those you spotted (mask instead of folder).
I'm surprise the V2 is working, as the code also has commands for the autofocus and HDR ... features not available on V2 camera, anyhow thank you for informing us.
These features are really enriching the Picamera, I'm sure you'll like them once you'll get the ordered V3.
Regards, Andrea
Hi Andrea
The camera V2 works - but only if you press Ctrl-C in the Thonny environment at the beginning of the software start.

Tomorrow the V3 shall arrive............

Meanwhile I tried to add another gizmo to your project:
A tripod with controlable tilt and turn by using two servo motors.
Sorry for the poor quality of the images attached, but they were taken *just as fast as I could* :-)

Best wishes,
Matze

Hello to everyone who is going to make this project.

I firstly set it up with a Raspberry Cam V2.1

After attaching the new V3-Camera it is just a completely new experience.
I can suggest it very much.
Hi Matze, I'm glad the V3 improve the results.
I only have V1, and you simply cannot compare....
Apart the larger FoV for the wide version, the HDR and autofocus are both very good additions in my view.
Regards, Andrea
Hello Andrea

I don't use the display you have built into your case. Therefore this question, please:
Can I use the little display to get a preview of the camera?

Best wishes,
Matze
Hi Matze,
yes, it's possible though the display is rather small (width 240).
In a couple of days I'll release an update, by adding this feature as an option.
Regards, Andrea
Very good, Andrea.
I just ordered the display.
I know: The resolution is very low but it might help to get the tripod with the camera into the desired position.

One more thing:
How can I tilt the camera image?
My tripod construction has the camera module *upside down* ( see attached picture ).

Ciao.
Hi Matze, yes, rotating the image by 180deg is possible and into the code by now.
I still need a couple of days to clean the code before releasing it.
Regards, Andrea
Hello Andrea
Here is another update to all of those guys who want to make that creation.

Raspberry Pi Zero 2 is no longer an option to the Raspberry 3B or 4B.
Why?
It seems to have too low memory while trying to render the pictures into an mp4-file.
After approx. 6 minutes it crashes and the terminal reports an error named *Killed*

So today I had set up a Raspberry Pi 4B.
I did everything just the same as I did when using the Zero.
While trying to install the software for the display I got an unusual message.
Please see attached picture.
What I found out by now so far:
Actually ( 18.11.2023) there is a bug in the firmware you can download via the Raspberry Imager.
This problem only occurs when using the 4B and therefore the 64-bit-version.
Using the 32-bit-version (legacy) of the 3B and anyway set it up on a 4B will be running without any error.

One thing off topic:
If you are using a touch display connected to the display-port of the Pi you will probably notice that the touch function does not work anymore.
It is the same reason.
Change to the 32-bit-version of the 3B-board and you are on again :-)

Hope I could help.
Matze


Hi Matze, thank you for sharing.
The Raspberry Pi Zero2 is an option in case of battery operated wish, yet forcing offline the eventual video creation.
The next script I'm going to release, I believe by tomorrow, excludes the video editing when a Zero board is found.
I'll surely make explicit to stick to the 32 bit OS version.
Regards, Andrea
Hello Andrea


Edit after a few minutes:
I helped myself by downloading the zip-file, unpacking it and copy its whole content to the timelapse directory.
That worked.

One more thing:
Your recognition of the Pi-model does not work correct.
I use a Pi 3B and got a Zero reported and therefore the rendering was set to False.


---------------------------------------------------------------------------------------
On Github I saw that you relaesed a new version of the software.
When trying to update it with the same line as I used for the first installation, I get this error:

fatal: Zielpfad 'timelapse' existiert bereits und ist kein leeres Verzeichnis.fatal:
( path already exists and directory is not empty)
Trying to erase the directory seems to be not an option.


Using Google lead me to use *fetch* instead of *clone*. This time I got the error:

fatal: Kein Git-Repository (oder irgendeines der Elternverzeichnisse): .git
( Kein Elternverzeichnis = no parent directory )


Do I have to set up the sd-card from the beginning?

Best regards,
Matze
Hi Matze,
I'm not quite sure while that error was happening; I'll check.
Please be informed I've just corrected the code as there were a couple of errors.
Apart the corrections, I've cleaned the code and made it more readable.
I used the description "Zero", though the check is on the processor type; If you want to force the Video editing on the raspberry Pi 3 (not sure about performances) you can comment out raw 138 (rpi_zero = check_rpi_zero()) and add a row "rpi_zero = False" right underneath.

Regards, Andrea
Hello Andrea

Yes, you did a great job on making the code more readable.
For me it was a pleasure to find out how things stick together.

The performance is - in my opinion - quite OK. Compared to an external software on a Pi 4B it was about 143% of the time needed to set up the video.
The rows you suggested are absolutely correct. Brillant work!

Thanks again :-)
Matze
Hi Matze,
I'm glad things went ok.
Regards, Andrea
Hello Andrea

I hope I do not bother you by sending another question / suggestion.
I have built the timelapse camera twice.
But this time without the display - it is ordered but not delivered ( couldn't wait for its delivery )

The display - if available - shows all the parameters before the shooting starts.
When *display* is set to *False* - no parameters are sent to the display ( of course :-) )
Can you please find a solution to wether send it to the console in Thonny or even send it to a web-server which is running on the Raspberry?

I am absolutely happy with your work and the timelapse works brillant.
( Not when using HDR - do you also notice that the focus changes and the picture goes from light to almost dark?)

Best wishes from Germany,
Matze
More Comments