prusa3d / Prusa-Firmware-ESP32-Cam

Firmware for ESP32 Cam modules to be used in Prusa Connect
GNU General Public License v3.0
97 stars 10 forks source link

PrusaConnect ESP32-CAM

This repository includes source code and firmware releases for the ESP32-cam module programmed in the Arduino IDE. Currently, several versions of boards built on ESP32/ESP32S3 processors with a camera chip are supported. Below is the list supported boards. Additionally, for each supported board, there is a guide on how to upload the firmware, how to compile code for it, and a basic data informations/issues for the board.

This project uses other libraries. It is necessary to install them in the Arduino IDE.

What we need for functionality

Supported boards

Board name Support Stream Micro SD FLASH LED FW update Documentation
Ai-Thinker ESP32-cam Full Yes Yes Board/Ext Yes here
ESP32-S3-EYE 2.2 Full Yes Yes External Yes here
Freenove ESP32-Wrover cam Full Yes No External Yes here
ESP32-S3-DEV-CAM in Progress External here
Seeed Studio XIAO ESP32S3 in Progress External here
ESP32-S3-CAM in Progress Board/Ext here

The compiled firmware for each supported board is published with every release.

How to flash binary files to ESP32-cam board from Linux/MAC/Windows

Uploading a precompiled version of the firmware to the MCU is possible from either Linux or Windows OS. Since different boards use various processors and modules, it is not possible to create a single universal guide. Therefore, it is necessary to select the board you are using and then refer to the documentation on how to upload the firmware to it. Here is list with currently supported boards.

How to compile software in the Arduino IDE

The software can be compiled and uploaded to the MCU. Software compilation was done in Arduino IDE. To ensure proper functionality, it is necessary to install support for ESP32 boards into Arduino IDE, as well as several other libraries

At the first step we need to install support for ESP32 board.

File -> Preferences -> Additional boards managers URLs

 https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

then go to Tools -> Board -> Boards Manager... and install module ESP32 by Espressif Systems

The next step is to install the necessary libraries. Go to Sketch -> Include Library -> Manage Libraries... or you can use Ctrl+Shift+I. Then you can search for the necessary libraries and install them.

For the installation of the ESPAsyncWebServer and AsyncTCP libraries, it is necessary to download the ZIP archive from the official GIT repository, and then import it using Sketch -> Include Library -> Add .ZIP Library ...

Then it is possible build and upload the firmware to the board. Each board requires a different Arduino IDE configuration. Therefore, it is necessary to select the board from the supported boards and read the documentation on how to build and upload the firmware.

In the file mcu_cfg.h, after line 16 is definitions that specify the version of the board for which the software will be compiled. It is necessary to enable the version of the board that will be used.

How to connect camera board to Prusa Connect

While we are on the ESP camera's configuration page, let's take a quick look at the other options it offers.

Interesting improvements. There is a protective film on the camera module. The protective film needs to be removed from the lens.

The second problem is that the camera module is not usually attached to the micro SD card slot. Therefore, the camera module overheats. This can permanently damage the camera module. If the quality of the camera module decreases, the resulting image starts to have a purple tint. Therefore, it is necessary to attach the camera module to the micro SD card socket with double-sided tape. Ideally, with double-sided thermal tape.

Service AP

After powering on and booting up the camera, it enters AP mode, which serves as a configuration mode for the camera. Essentially, it starts its own Wi-Fi network. The network name (SSID) is ESP32_camera_UID, where UID is the first three numbers from the MCU ID, serving as a unique identifier for the camera. The password for connecting to the AP is 12345678. The camera's IP address is 192.168.0.1. To configure the camera via AP mode, you need to connect to this IP address using a web browser: http://192.168.0.1. Alternatively, you can also use the http://prusa-esp32cam.local hostname (mDNS) instead of the IP Address.

After establishing a successful connection, your computer might display a "No Internet" warning for the given network. This is normal.

If you have set up a Wi-Fi network name (SSID) and password in the camera for it to connect to, then upon powering on, the camera will automatically connect to the configured Wi-Fi network and simultaneously activate AP mode for 5 minutes. AP mode is always enabled after powering on and booting up the camera for 5 minutes. The service Wi-Fi AP is automatically deactivates itself after 5 minutes following each camera startup if no device is connected to the camera.

Service AP is for for the first camera configuration. If the camera is connected to a WiFi network, it is possible to configure it from the local network.

How to reset configuration to factory settings

Each version of the supported board uses a different pin for camera reset. Therefore, it is necessary to refer to the documentation for the specific board to determine which pin is used for reset camera configuration to factory configuration.

The procedure is always the same:

Status LED

On the board, there is a status LED that provides a visual indicator of the module's current status through blinking at defined intervals. Each supported board has the STATUS LED located in a different place. It is necessary to refer to the documentation to locate the STATUS LED on the board.

Upon module activation, the LED illuminates. After processor initialization, the LED exhibits different blinking intervals based on the current mode of the module

The approximate boot time of the device is 15-20 seconds.

Debug logs

It is possible to save debug logs to a microSD card, but the card must be formatted to FAT32. Currently, the maximum tested capacity for a microSD card is 16GB. If a microSD card is inserted into the camera, it is necessary to reboot the camera. When a microSD card is inserted into the camera before boot, logging to the microSD card is automatically enabled. If no microSD card is inserted, the saving of debug logs to the microSD card is automatically disabled. Enabling the saving of debug logs to a microSD card is only possible during camera boot, so it is necessary to restart the camera after inserting the microSD card. Debug logs are saved as plain text in the file Syslog.log

Serial console configuration

Currently, it is possible to set the basic camera configuration using the serial console. Baud speed for communication with MCU is 115200 8N1

Commands for configuration have simple syntax

command separator variable termination line terminator
setwifissid : SSID ; \n or \r or \n\r or \r\n

Currently, available commands are listed in the table below:

Command Description
setwifissid Setting WiFi SSID, where variable SSID is network name
setwifipass Setting WiFi password, where variable PASSWORD is WiFi password
wificonnect Connecting to WiFi network
mcureboot Rebooting the MCU
commandslist Listing currently supported commands via serial console
getwifimode Print current WiFi mode. STA/AP/AP+STA
getwifistastatus Print WiFi STA status. Connected/Disconnected/Connecting....
getwifistaip Print IP address for WiFi STA
getserviceapssid Print service AP SSID name
setauthtoken Set authentication token for Prusa Connect
otaupdate Start OTA update process
resolution Set photo resolution
photoquality Set photo quality
setflash enable/disable LED flash
setlight enable/disable LED light

The standard command sequence for camera basic settings is

WEB API

The camera have a WEB API, allowing several operations to be performed through the web interface.

Command Description
http://IP/action_capture Capture snapshot
http://IP/action_send Capture snapshot, and send to Prusa Connect
http://IP/light?on Light ON
http://IP/light?off Light OFF
http://IP/flash?on FLASH ON
http://IP/flash?off FLASH OFF
http://IP/action_reboot Reboot MCU
http://IP/get_logs Get logs from micro SD card
http://IP/saved-photo.jpg Get last captured photo

Video stream

The video stream is available on the WEB page http://IP/stream.mjpg

Manual camera focus

Usually, the camera module is properly focused. However, the camera module can be manually focused. There are several types of lenses for camera modules. I have created several Tools for manually focusing the camera module.

First, it is necessary to hold the camera with a holder and then put the wrench on the lens. Next, gently turn the wrench by a couple of degrees, and observe the difference.

WARNING! Manual focusing can permanently damage the camera module!

Potential issue