Manage cookies

We use cookies to improve our services. Read more about how we use cookies and how you can refuse them.

The necessary cookies help to make the website work properly.

Anonymous statistical cookies help to understand how visitors use the website.

  • MicroPython
    2 min | 26579

    #MicroPython: Portable time-lapse camera using an ESP32-CAM

    MicroPython | 2 min | 26579

    This tutorial extends the article MicroPython: Taking photos with an ESP32 and in this case, the ESP32-CAM running MicroPython takes a photo every 5 seconds and saves it on the microSD card. The photos can be then combined into a time-lapse video! :)

    The MicroPython official version doesn't support I2S interface. However, tsaarni wrote a driver for the OV2640 and forked the MicroPython repository to include it. Thus, you need to follow the instructions in this article: MicroPython: Taking photos with an ESP32 to install the right firmware.

    Hardware and Software

    In the following table, you will find the hardware and software that you can use on this tutorial:

    There are two new articles about this topic:Check out those, before you keep reading this article and instructions.


    After flashing the MicroPython firmware, clone the repository lemariva/uPyCam typing:

    git clone -b timelapse-camera

    then rename the file to and configure the Wi-Fi access settings:

    # wlan access
    ssid_ = ""
    wpa2_pass = ""

    The ESP32-CAM uses Wi-Fi to connect to an NTP-server and to get the actual time. Additionally, you can check, if everything is working because the code enables an FTP server.

    Use VSCode with the PyMakr extension to upload all the files to the ESP32. If you need some help, follow the instructions from this tutorial.

    Then, connect your ESP32-CAM to a 5V battery and enjoy the results! :)

    If you need a datasheet of the ESP32-CAM, here is one available, I needed to define the pins that are connected to the MicroSD slot.

    Error on saving photos

    Some of the photos were saved with error on the MicroSD card, and I got an error when I tried to export the video sequence. So, I wrote some code lines to repair the photos. The error that I got was the following: Premature end of JPEG file.

    Create a file with the following code:

    import os
    import cv2
    import shutil
    from os import listdir
    from os.path import isfile, join
    basedir = os.path.abspath(os.getcwd())
    onlyfiles = [f for f in listdir(basedir) if isfile(join(basedir, f))]
    new_folder = "numerated" 
    for idx, filename in enumerate(onlyfiles):   
        base, extension = os.path.splitext(filename)
        if extension == ".jpg":
            img = cv2.imread(filename)
            cv2.imwrite(filename, img)

    Then, install the dependencies (opencv) using pip:

    pip install opencv-python

    and run the code typing python


    This article presents an example code to use the ESP32-CAM as a time-lapse camera using MicroPython. The module takes a photo every 5 seconds and saves it on the SD. Then, using x264vfw and VirtualDub is possible to generate a time-lapse video. Some of the photos are saved on the microSD with errors and I included a some code lines to repair them.


    Mohamed Ali. A 03.07.2020

    I want built camera for blind people. Blind person , with help of ESP 32 , CAM and SD card will take photo, this photo will be compared database in SD card . This will inform over voice what is the in-front of him. Please send necessary microphython code. Mohamed Ali Chennai, India []

    Colin 04.05.2020

    This article says nothing of how to mount the sdcard. It appears that it is writing to the filesystem.

    Stan92 04.12.2020

    Thanks for sharing...

    Amy 05.12.2020

    Hi, I gotthe camera working but I just cannot get the sd card respond. Is it working? import machine, sdcard, os

        # sd mount
        spi = machine.SPI(1, baudrate=100000, phase=0, polarity=0, sck=machine.Pin(14), mosi=machine.Pin(15), miso=machine.Pin(2))
        sd = sdcard.SDCard(spi, machine.Pin(13))
    except AssertionError as e:
    MPY: soft reboot
    I (5749) spi_master: Allocate TX buffer for DMA
    I (5759) spi_master: Allocate TX buffer for DMA
    I (5759) spi_master: Allocate TX buffer for DMA
    I (5759) spi_master: Allocate TX buffer for DMA
    I (5759) spi_master: Allocate TX buffer for DMA
    Traceback (most recent call last):
      File "", line 32, in 
      File "", line 22, in 
      File "", line 48, in __init__
      File "", line 76, in init_card
    OSError: no SD card

    MicroPython v1.10-128-g584bc5b2a on 2019-09-01; ESP32 module with ESP32 Type "help()" for more information.

    abeowitz 10.11.2020

    How do I build without nimble? It keeps stopping at "no rule to make target nimble.c"

    It seems to ignore MICROPY_PY_BLUETOOTH=0 MICROPY_NIMBLE=0 as suggested by reading the Makefile...