sc. ESP32-CAM based secure flash LED camera

There are many ESP32-CAM projects in the Internet, but only a few tackle with camera hardware and firmware improvements. The original ESP32-CAM firmware is primarily designed to transmit live picture to a smart device or PC through the local Wi-Fi network. But an empty micro SD card socket reveals that the module has been designed to record video, or other data.

How to stop the flashing LED?

By searching the Internet for ESP32-CAM video recording software source code from GitHub and other sources can easily be discovered. But an inbuilt ESP32-CAM flash LED blinks violently during video recording or other data transfers to or from micro SD card. Most authors recommend disconnecting a collector pin (C) of the flash LED NPN bipolar transistor switch to permanently disable LED power. Unfortunately, the transistor is often torn off inadvertently. Keeping all the transistor’s contacts soldered and removing an appropriate SMD resistor nearby seems to be a far better solution (see the photo).

However, it is interesting that the original Ai-Thinker firmware for transmitting live picture through a Wi-Fi network offers no option for switching the flash LED on or off, and it seems though that its primary purpose was an indication of micro SD card operation. There are other interesting questions, like whether or not the video may be recorded and transmitted at the same time. The answer is most probably yes, if a not too high image resolution is selected.

Night video recording

The flash LED is useful for night video recording especially when there are no other light sources, but ESP32 has no spare outputs to control and it can only communicate with an external I/O port extender through an SPI, I2C or RS232 interface. Microchip MCP23017 is a factory preprogrammed I2C I/O port extender, but you can also program an arbitrary microcontroller for this functionality. An additional ESP32 or ESP8266 module can also be used as a I/O port extender through the RS232 interface.

Another solution with no additional chips is to rewire GPIO33 for the flash LED control and jump-wire the camera p‑MOSFET switch by permanently connecting source (S) to drain (D). Disabling camera power control slightly increases the ESP32 power consumption for about 20 mA in standby mode, but this negligible compared to expected power usage during camera regular daily operation, or if battery power supply is used only as a backup.

Solving firmware problems

Many authors of ESP32-CAM projects have encountered a frustrating camera frame capture timeout error that usually appears after a longer camera of operation at the 1344-th line of Camera.c programming library source code file. The error seems to be related to wrong data type declarations of 32-variables that hold 32-bit milliseconds counter value. If a common 32-bit integer data type is used, the values of above 2.147.483.647 are misinterpreted as negative, and time difference calculation for instance (such as T1-T0) may return false results. However, if 32-bit unsigned integers (like unsigned long or uint32_t) are used instead, time difference calculations are always right, as long as the difference between T1 and T0 is smaller than the maximum range of 32-bit unsigned integer (4.294.967.295).

Most home grown enthusiast programmers use precompiled programming libraries (*.a files), but the above error hasn’t been solved yet. Luckily, a complete camera libraries source codes may be downloaded from the GitHub, I was able to make corrections and recompile the new libraries source codes together with the main application source code (*.ino file). It suffices to put all the camera libraries source files in the same folder as the *.ino file to compile them in Arduino IDE. Here is a complete a list of the required source files:


camera.c

camera_common.h

esp_camera.h

esp_jpg_decode.c

esp_jpg_decode.h

img_converters.h

jpge.cpp

jpge.h

ov2640.c

ov2640.h

ov2640_regs.h

ov2640_settings.h

ov3660.c

ov3660.h

ov3660_regs.h

ov3660_settings.h

ov5640.c

ov5640.h

ov5640_regs.h

ov5640_settings.h

ov7725.c

ov7725.h

ov7725_regs.h

sccb.c

sccb.h

sensor.c

sensor.h

to_bmp.c

to_jpg.cpp

twi.c

twi.h

SftyCAM.ino

xclk.c

xclk.h

yuv.c

yuv.h

How to deal with an inadequate power supply?

An image frame capture timeout error (at line 1408 in Camera.c file) may also occur due to ESP32-CAM module inadequate power supply. A lite flash LED uses a lot of power and switching it on can be a cause of a sudden power supply voltage drop that causes the above error. +3,3 V AMS1117 voltage regulator has a maximum output current about 1 A. A higher current causes the output voltage drop rapidly and may impair ESP32-CAM operation. Though AMS1117 accepts input voltages up to +15 V=, the input voltage may not exceed +5 V= due to overheating hazard, but sufficing this codition AMS1117 can still provide enough power for MCP2200 and ULN2803 operation. If a +12 V= main power supply is used for instance, you may need two additional 1 A voltage regulators (ex. LM7808 and LM7805), each lowering the voltage for a few volts to prevent overheating. Overheating and potential sudden power supply voltage drops may also damage the camera chip.

The power supply voltage stability can be provided by large enough electrolyte capacitors and reverse current protection diodes. Reverse currents usually occur as short pulses that may severely damage the ESP32-CAM module.

Own USB-to-RS232 converter

A fast and reliable reprogramming of ESP32-CAM module without moving cables or jumpers is a wish of any programmer. The module lacks an inbuilt USB-to-RS232 bridge, so Microchip MCP2200 bridge is a good choice. MCP2200 has purpose pins for serial communication (TX, RX, ~CTS and ~RTS) that are controlled through the USB CDC logical interface as well as a number of GPIOs that can be used by a user application through a USB HID logical interface. MCP2200 also requires an external 12 MHz crystal resonator, a few capacitors and resistors and a voltage converter from +5 V to +3 V to operate. The latter is needed to relay the USB bus power signal, which enables MCP2200 operation by setting ~RST control input to “1” (high voltage level) as a USB cable is connected. There are other functions that require a voltage converter and a protection circuit, so I also added ULN2803 chip with 8 open collector Darlington inverters. I used the first two inverters to relay USB power signal to MCP2200, the third was used to protect the optional camera control input (GPIO32) and the others were used for resetting ESP32 module and switching between regular operation and program download mode, programmatically.

MCP2200 could also be reprogrammed and it would double as a port extender operated through the RS232 port, but I’m still working on this. A blank PIC18F14K50 could also be used for this purpose.

Making Wi-Fi communications safer

There are more hurdles which render the camera more or less useless for many practical applications. The original ESP32-CAM module is operated through Wi-Fi interface as an FTP server and it is exposed to a potential hacker attack. It is safer to have the camera operate independently with Wi-Fi communications offline most of the time, this way ESP32-CAM can hardly be detected by a hacker Wi-Fi scanner. It is also hard to distinguish it from other Wi-Fi devices such as smartphones in urban environments. Wi-Fi functionality is only enabled during an incident or at regular intervals to relay statistics data to a well-hidden central control system.

NOTE:

ESP32-CAM module modifications require a steady hand and a magnification lens or an excellent eyesight and a soldering iron with a very thin tip (0,2 mm recommended). SMD resistors are very small and by removing them you risk losing them, unless they are properly stored.

You are solely responsible for making modifications to your ESP32-CAM module and implementation of projects described on PC USB Projects website. Instructions, schematics and source code on PC USB Projects website may contain errors and programming bugs. Hardware and software was tested, but you use it on your own responsibility and you are solely responsible for the correctness and suitability of its operation, as well as for all possible damage caused by possible errors in the software and hardware.

DOWNLOADS:

VideoRecorder_SftyCAM_v1.0.zip (includes all sources listed above)

PC USB Projects Safety camera photo

A modified ESP32-CAM module with modified hardware from below

A modified ESP32-CAM module with modified hardware from above

Camera mainboard with MCP2200 (click on the photo to enlarge it)

A modified ESP32-CAM module hardware modifications note