[EN] Let’s have fun doing time-lapse with ESP32CAM.

This article is an application of the ESP32CAM board to perform continuous photo shooting with a fixed interval between shots, known as time-lapse, in Python. By installing the firmware with the integrated camera library for connection to the camera module on the ESP32CAM, programming is simple and easy code configurable.

(Figure. 1 ESP32CAM )


  1. ESP32CAM
  2. OV2640 camera module
  3. USB-RS232 module
(Figure. 2 ESP32CAM with 2nd generation case and connect to USB2RS232 module.)
(Figure. 3 ESP32CAM with 3rd generation case and USB2RS232 module placed on the back of the board.)

Connection to RS232 Module

To connect the RS232 module so that the ESP32CAM board can communicate with the computer for firmware writing and programming, the following table is required.

โมดูล RS232ESP32CAM

Install firmware

Thanks to Mauro Riva, firmware is available for us on GitHub where readers can download esp32_idf4.x_ble_camera.bin firmware and write ROMs like in this article.

Once the firmware has been installed, test it and run it as follows, And if the result is True, it means the camera module is ready.

import camera
camera.init(0, format=camera.JPEG)


To write firmware, the ESP32CAM’s GPIO0 pin must be connected to GND and reset to enter ROM write mode.

ไลบรารี camera

Running the camera module requires calling the camera library. The library has the following commands:

  1. camera.init(0,format=camera.JPEG) to get the camera ready to work
  2. camera.gramesize( size ) For setting the image size which affects the amount of memory on the board. Image sizes are listed as follows.
    1. camera.FRAME_96X96 
    2. camera.FRAME_QQVGA 
    3. camera.FRAME_QCIF 
    4. camera.FRAME_HQVGA 
    5. camera.FRAME_240X240
    6. camera.FRAME_QVGA 
    7. camera.FRAME_CIF 
    8. camera.FRAME_HVGA 
    9. camera.FRAME_VGA 
    10. camera.FRAME_SVGA
    11. camera.FRAME_XGA 
    12. camera.FRAME_HD 
    13. camera.FRAME_SXGA 
    14. camera.FRAME_UXGA 
    15. camera.FRAME_FHD
    16. camera.FRAME_P_HD 
    17. camera.FRAME_P_3MP 
    18. camera.FRAME_QXGA 
    19. camera.FRAME_QHD 
    20. camera.FRAME_WQXGA
    21. camera.FRAME_P_FHD 
    22. camera.FRAME_QSXGA
  3. camera.whitebalance( WB_Type )  For the camera module to adjust the white balance (WB: White Balance). There are options as follows:
    1. camera.WB_NONE
    2. camera.WB_SUNNY 
    3. camera.WB_CLOUDY 
    4. camera.WB_OFFICE 
    5. camera.WB_HOME
  4. camera.saturation( color_intensity ) The intensity of the color gradient which is the grayscale value range from -2 to 2.
  5. camera.brightness( brightness_value ) It is used to reduce or increase the brightness of the image obtained from the camera module. The value is -2 to 2.
  6. camera.contrast( color_contrast ) For adjusting the color contrast to be less or more with a value range of -2 to 2.
  7. camera.quality( quality_level ) For determining image quality. It ranges from 10 to 63, where a lower value means much higher image quality due to less compression.
  8. camera.flip( flip_value ) To flip the top/bottom image by setting a value of 0 or 1.
  9. camera.mirror( mirror_value ) To flip the left/right image by setting a value of 0 or 1.

Example Code 1

The example code21-1 is to read the values from the camera module and then write the resulting image file named capture.jpg to the SDCard.

import camera
import machine
import os
import time


sd = machine.SDCard()

os.mount(sd, '/sd')
buf = camera.capture()
f = open('/sd/capture.jpg', 'w')

Example Code 2

Example code21-2 is a continuous recording of 100 images every 1 second (approximately).

# code21-2 time-laps
import machine as mc
import time
import camera
import os

sd = mc.SDCard()
if ('sd' in os.listdir()):
os.mount(sd, '/sd')
frameCounter = 0
for i in range(100):
    frameCounter += 1
    buf = camera.capture()
    fname = "/sd/{:04d}.jpg".format(frameCounter)
    f = open(fname, 'w')
    print("Frame No.{}".format(frameCounter))
(Figure. 4 Result of code21-2)
(Figure. 5 Result of code21-2)
(Figure. 6 result of code21-2)


From this article, you will find that programming Python to control the camera module is very easy and simple. even though it needs to install firmware for ESP32CAM specifically, the speed of the camera module is faster than coding in Python alone. And one thing that our team found is that the use of the module requires a power supply that can supply higher current than normal, so the reader must check the current that is supplied to the board when it is actually used.

Finally, we hope this article is more or less useful for readers. And readers will be happy with the program and apply it in the future.

(C) 2020, By Jarut Busarathid and Danai Jedsadathitikul
Updated 2021-09-07