User Tools

Site Tools


esp32-cam

Introduction

The ESP32-CAM by AI-Thinker is an ESP32 development board with a small camera attached. It can be reprogrammed quite easily for developing projects which require vision.

I wanted to make a small camera which could be set up in a bird box to monitor the bird activity. The ESP32-CAM seems like a good choice due to its size and price.

The Software

I thought it might be difficult to get a streaming server set up on the ESP32 to send footage to a server in real time, but the hard work has already been done. Tasmota32 already has firmware compatible with the ESP32 and it seems to work reliably. Specifically, the firmware “tasmota32-webcam” is what I'm using.

When the ESP32-CAM boots into Tasmota and connects to my network, I am able to access the livestream at /stream on port 81. I am using Shinobi for CCTV recording at home, and it supports the Tasmota camera stream without any significant problems. At full resolution, I am getting about 2-3fps which is reasonable for a bird box or for basic surveillance purposes.

Tasmota supports various commands for configuring the camera, including “WcResolution” which changes the resolution of the camera; by default it is rather low. I used this command to get the full resolution:

WcResolution 10

Other resolutions are available but this gives you the best quality at a lower frame rate.

The “WcInit” command needs to be run to start the streaming server software. The web interface (on port 80) will run this command for you in the background, but if you are using the ESP32-CAM with CCTV recording software and not using the web interface, you need to create a Tasmota rule which will run this command for you on boot. This rule is what you need:

Rule1 ON System#Boot DO WcInit ENDON

Then enable the rule with this command:

Rule1 1

Flashing Instructions

The ESP32-CAM does not have a built-in USB programmer like many other development boards. If you have a USB to UART adapter, it is still quite simple to flash custom code. Wire your ESP32-CAM and UART adapter as shown in this table:

UART Adapter ESP-32 CAM
5v 5v
GND GND
TX U0R
RX U0T

The ESP32 needs to be put into programming mode before it will accept any code. This can be done by removing the power, connecting IO0 to GND, and then re-applying the power. This only needs to be done when reprogramming and you need to remove the connection again to make the ESP32 boot normally.

The Tasmota32 documentation will have up to date information about how to flash the firmware but I used the following command:

esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 115200 --before default_reset --after hard_reset write_flash -z --flash_mode dout --flash_freq 40m --flash_size detect 0x1000 bootloader_dout_40m.bin 0x8000 partitions.bin 0xe000 boot_app0.bin 0x10000 tasmota32-webcam.bin

The “flash files” for ESP32 can be found on Github; this includes boot_app0.bin, bootloader_dout_40m.bin, and partitions.bin. I downloaded tasmota32-webcam.bin from this page on tasmota.com

This command requires that you install esptool.py beforehand and that you have all of the required files in the current working directory. In addition, you need to replace “/dev/ttyUSB0” with the path to your UART adapter; on Windows it is probably COM5 or similar. I lowered the baud rate to 115200 from 921600 because I was having communications issues (presumably my UART adapter isn't fast enough). Tasmota flashed in around 60 seconds at 115200 but you could try increasing it if you are impatient.

Night Vision

The ESP32-CAM has an infrared filter built into the camera lens. This means that infrared night vision isn't possible without replacing or modifying the lens. Some people have successfully removed the IR filter by unscrewing the lens and using a knife: marksbench.com describes the process.

Unfortunately, I have bought 2 different batches of ESP32-CAM boards and neither has an exposed IR filter. I can unscrew the lens easily, but the IR filter is deeper within the lens where I can't reach it.

Night vision ability should be quite easy with the correct (or modified) lens in addition to some IR LEDs. However, removing the IR filter will ruin the colours when exposed to daylight so you should only do this if your camera is always going to be in a dark location such as a bird box.

Some sellers of the ESP32-CAM board offer a selection of different lenses, so the most simple solution would be to buy one without an IR filter at all. I also found an Aliexpress product page where you can buy a new camera (without the ESP32) with the right kind of lens for $2.50. The product description states it is “night version , 850nm” which seems to imply that it contains no IR filter and you can illuminate your subject with standard 850nm IR LEDs. I haven't bought one of these cameras so I can't say for sure how well it would work, but this may be the simplest option to get night vision with your ESP32-CAM.

Summary

The ESP32-CAM is one of the cheapest WiFi cameras around and it has the added benefit of being programmable. Thanks to Tasmota, you can integrate these cameras into your existing CCTV system with ease and be sure there isn't any nasty telemetry or backdoors which violate your privacy.

esp32-cam.txt · Last modified: 2023/02/18 15:34 by 127.0.0.1