ESP32-Cam Modul als Netzwerkkamera für den 3D-Drucker - AZ-Delivery

3D printing is fun. But unfortunately, the printing of some objects takes some time. Every now and then, the printer doesn't do what it's supposed to. And who wants to sit next to the printer all the time and wait for the print? That's why camera solutions for 3D printers have been around for some time.

The simplest way of monitoring is of course to install a webcam and a corresponding program on the PC and set it up. With the right software, this then acts as a webcam server. An example under Windows would be Yawcam (https://yawcam.com/). The disadvantage, the PC must remain on all the time. There are also solutions with Raspberry Pi as a webcam server (e.g. Motion: https://motion-project.github.io/).

Of course, camera solutions with a built-in web interface are better. There are also many of this kind. Some even with the possibility to control the camera via the web interface. Unfortunately, all these solutions are quite expensive. That's why I was looking for a cheaper solution and found the ESP32 CAM Set.

The plan

The ESP32-CAM Set consists of a special ESP32 board and a small camera.

The ESP-32 is a 32-bit dual-core microcontroller from Espressif with 160MHz or 240MHz and built-in 512MB RAM and is the big brother of the ESP8266. The program memory (Flash) is built in only in some variants. Usually, as with the ESP8266, an external serial flash is installed on the controller board. Other special features of the ESP32 are the built-in WiFi, similar to the ESP 8266, and Bluetooth. Usually, ESP32-S modules are installed in the camera sets. These have a 32MBit (4MB) flash built-in. Besides the internal antenna, there is also the possibility to connect an external antenna.

A programming interface is usually not built into the camera set. So the ESP32 has to be programmed with an external FTDI adapter. On the board's front side, there is beside the reset button and the power supplies an additional 8MB PSRAM, which can be used for fast image processing. On the back of the module you will find the camera connector, a bright white LED (can serve as flash and video light), and a MicroSD card slot. The camera connector is arranged in such a way that you can stick the camera directly onto the SD card slot. As a camera, a 2MP OV2640 is common. So this set includes everything you need for a WLAN-enabled WebCam. And that for only a few euros.

Now let's get to work.

Hardware setup description

Parts list

For the Printercam you need:

or also https://www.thingiverse.com/thing:4192842

  • a MicroUSB cable
  • USB power supply

So much for the hardware.

Structure

On some boards, the camera is already mounted and only has to be fixed on the SD slot with double-sided tape. When mounting the camera, you should first test if the position fits with the camera cutout in the housing. For other sets, the camera still has to be mounted. First, fold the small gray bar at the camera connector upwards. Now you can carefully push in the flat cable of the camera. Then the gray part is folded down again and pressed together with the white fixed part. Now you can carefully stick the camera onto the MicroSD slot. Some cameras still have protection on the lens. This should be removed before use - done.

Hardware connections for programming/operation

To be able to program the ESP32, you need the FTDI adapter. This is connected according to the following connection diagram. The left picture is used if the adapter supplies +3V3 at the VCC connector. The middle connection scheme can be used if the adapter supplies 3V3 at the data ports, but the VCC port is fixed to 5V (best measure the voltage before!).

Programming bridgeIf the ESP32 should be programmed, the jumper (between IO0, and GND) must be plugged in before a reset. If the program is to be executed in the ESP32, the jumper must be opened.

Drawings for download

For the installation and later operation, the right plan is important. The MicroUSB breakout is connected to the ESP32 board as shown. You don't need the USB connection, the USB is only used for power supply. Of course, you can supply the ESP32 with power in another way.

Case installation

The housing installation is done quickly. The ESP32 board together with the camera fits exactly into the housing. If you have soldered the pins onto the ESP, make sure that you use the deeper housing version. The same applies to the USB breakout. There are different covers for each of the different variants. I just secured the ESP32 board with some hot glue. The USB board I fixed with 2 screws to the back cover.

Under the housing I glued a standard camera tripod block. Now the camera fits on every camera tripod (https://www.thingiverse.com/thing:4200944).

There are also ready ESP32 camera housings with tripod connections.

Software

Installation of Arduino board manager

First, you have to add the ESP32 CAM board to the board manager of the Arduino IDE. This is done by adding the following URL to the list "additional board manager URLs" in the preferences.

https://dl.espressif.com/dl/package_esp32_index.json

Now go to Tools/Board/Board Manager and search for ESP32. The "esp32" entry contains our board. One installs this then.

The last step of the hardware setup is to select the ESP32 Wrover as an active board. The other parameters are then selected according to the requirements.

Installation of the software

The software can be downloaded from my Github repository. https://github.com/willie68/PrinterCamESP32

The download of the sources works via the button "Clone or Download" and then Download ZIP. The downloaded ZIP file (PrinterCamESP32-master.zip) contains a folder PrinterCamESP32-master. This folder contains README and LICENSE files. Below this folder is the folder PrinterCam, which contains the files for the Arduino IDE. You can either extract this folder into your Sketch directory, or you can extract the whole ZIP file into a directory of your choice. In the Arduino IDE, you have to open the PrinterCam.ino. Now the other files should be opened automatically.

If the board and parameters are set correctly, you can compile the program and upload it to the ESP32 board. First, plug the jumper on the ESP32 and press the reset button. Now press the "Upload" button in the Arduino IDE.

The program

The program itself was created based on the webcam example CameraWebServer was built. First, all face detection was taken out and the camera model was limited to the camera included in the set.

The wifi network connection was built a bit more stable. Now a reconnect is also possible after the connection is broken.

Then the index page was reduced significantly and limited to the points that are necessary for the use of PrinterCam. The index page is no longer stored in the GZIP format, but as plain text in the new_index.h-file. This also makes it easier to make changes. If you want, you can convert it back to GZIP format later and save it as ByteArray. But that is not part of this blog.

Additionally, the possibility to use the Flash LED was implemented. A timer was built in, especially for this purpose, which automatically turns off the LED after 1 min. The LED consumes a lot of power and emits a lot of heat. However, since the housing is printed from PLA and thus somewhat heat-sensitive, too much heat could cause it to soften.

The last thing I did was to include the web interface of my 3D printer (Malyan M200). So now I can read the two parameters extruder and platform temperature and even control them from this web interface. I also get feedback about the printing status. To activate this, I only have to set the following parameters in the app_httpd.cpp the #include "new_index.h"by #include "new_index_malyan.h" must be replaced. The IP of the printer must also be set in the file. (Line 418: var printerUrl = 'http://192.168.178.61' )

Hint: Remember to configure your WLAN router or DHCP so that the same IP is always assigned to the ESP32 module and the 3D printer.

Call up the IP in the browser:

Screenshot of the new camera from the PC browser

Screenshot of the new camera in use from an Apple iPad.

Last

I have been using this camera for several months now. And it works great. Have fun with the rebuild.
I hope you enjoyed this little blog! See you next time.

Wilfried Klaas

Esp-32Projekte für anfängerSmart home

12 comments

Peter Jordan

Peter Jordan

Danke – funktinierte fast auf Anhieb, nur dass ich unterhalb von SVGA als Auflöung (also auch beim start mit CIF) kein Bild bekomme, aber je nach Auflösung Fehlermeldungen.

10:31:04.427 → Item psram alloc failed. Size: 355200 × 1
10:31:04.427 → matrix3du item alloc failed.
10:31:04.427 → dl_matrix3du_alloc failed

10:31:21.028 → Item psram alloc failed. Size: 230400 × 1
10:31:21.028 → matrix3du item alloc failed.
10:31:21.028 → dl_matrix3du_alloc failed

Andreas Wolter

Andreas Wolter

@Geyer Mario: der Fehler müsste mit der Version des ESP Core zu tun haben. Normalerweise reicht es, die Version auf 1.0.6 zurückzustellen. Das haben Sie scheinbar schon getan. Haben Sie bei der Auswahl auch den Core installiert?

Sie könnten alternativ den neueren Link für den Core einsetzen:
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
und dort Version 2.0.1 auswählen (bis zu der Version sollte es funktioieren, darüber nicht, da die fd_forward.h aus dem ESP Arduino Core entfernt wurde.

Siehe auch hier:
https://github.com/easytarget/esp32-cam-webserver/issues/191

Grüße,
Andreas Wolter
AZ-Delivery Blog

Geyer Mario

Geyer Mario

hallo, ich arbeite mit der Arduino IDE 1.8.19, https://dl.espressif.com/dl/package_esp32_index.json ist eingestellt.
ESP32 Espressif Version 1.0.6 ist eingestellt. ESP32 Wrover Module ist gewählt.

Beim Kompillieren kommt trotzdem
exit status 1
fd_forward.h: No such file or directory

Hat jemand noch eine Idee?

Andreas Wolter

Andreas Wolter

@Frank: in der Funktion doFlashLight() wird die LED ein- und ausgeschaltet.
digitalWrite(4,0); schaltet Pin 4 aus.
digitalWrite(4,1); schaltet Pin 4 ein.

Damit müsste man die LED steuern können.

Grüße,
Andreas Wolter
AZ-Delivery Blog

Frank

Frank

Moin,

wie spreche ich denn die LED an?

Gruß Frank

Thorsten Hartwig

Thorsten Hartwig

Noch zwei Tips von mir.
Das nervige Ermitteln der vom DHCP vergebenen IP-Adresse (entweder per Serial Monitor oder per Webinterface des AccessPoints) kann man sich sparen. ESP32 unterstützt ein Protokoll Namens MDNS.
Dazu an den Anfang der PrinterCam.ino die Zeile
#include
einfügen und nach der Zeile “reconnect();” noch dies einfügen:
if (!MDNS.begin(“PrinterCam”))
Serial.println(“Error setting up MDNS responder!”);
Danach lässt sich das Gerät mit der URL “PrinterCam.local” ansprechen. Ohne http o.ä.

Das zweite Problem ist das Hardcoden der SSID und des Passworts. Wer gibt schon gern sein Passwort fest in Code. Ruckzuck ist der Code versehentlich irgendwie gepublished und alle kennen das Passwort.
Stattdessen hat Espressif das SmartConfig ins Feld gebracht.
Es gibt eine App im Android PlayStore namens “EspTouch: SmartConfig”.
Damit kann ein Android-Gerät die Zugangsdaten auf einen ESP32 übertragen, solange er darauf, noch ohne WLAN-Verbindung, wartet.
Die Zugangsdaten bleiben über den Neustart hinaus erhalten. Löschen ist umständlicher… z.B. WLAN abschalten, dann wartet der ESP auf SmartConfig, dann absichtlich falsche Zugangsdaten übertragen.

Vorgehen wäre so:
1) Die Vorkommen von “WiFi.begin(ssid, password)” ersetzen durch “WiFi.begin();”
2) Die Funktion “AwaitConfig einfügen:
void AwaitSmartConfig()
{
#define MDNS_TIMEOUT 30000 // Wait 20 seconds for smartconfig
WiFi.disconnect(); delay(500);
WiFi.mode(WIFI_STA); delay(500);//Init WiFi as Station
WiFi.setHostname(”PrinterCam"); //define hostname
digitalWrite(4, 1); // LED indicates waiting for smartconfig
WiFi.beginSmartConfig();
unsigned long now = millis();
while (!WiFi.smartConfigDone() && ((millis() – now) < MDNS_TIMEOUT))
;
digitalWrite(4, 0); // LED off as SmartConfig is finished
WiFi.stopSmartConfig();
}

3) Die Funktion reconnect() so erweitern:
void reconnect()
{
if (WiFi.status() != WL_CONNECTED) // makes no sense to leave this method while WiFi is not connected
{
#define CONNECT_TIMEOUT 8000 // Wait 8 seconds for WiFi connect
unsigned long now = millis();
while ((WiFi.status() != WL_CONNECTED) && ((millis() – now) < CONNECT_TIMEOUT))
;
if (WiFi.status() == WL_CONNECTED)
{
Serial.println();
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
return;
}

Serial.println(“Not connected after timeout.”);
AwaitSmartConfig();
now = millis();
while ((WiFi.status() != WL_CONNECTED) && ((millis() – now) < CONNECT_TIMEOUT))
;
if (WiFi.status() == WL_CONNECTED)
{
Serial.println();
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
return;
}
}
}

Thorsten Hartwig

Thorsten Hartwig

Ganz so einfach war es wirklich nicht.
Egal, ob ich die Arduino IDE 1.8.19, die 2.0.0.rc3 oder Visual Studio mit der vMicro extension probiert habe, beim compilieren kam “fd_forward.h: file not found”. Googeln half nur vage: irgendwie gibt es da zwei unterschiedliche Boradverwalter-URLs. Bevor noch andere reinfallen, hier die Lösung.
Mit der oben angegebenen
https://dl.espressif.com/dl/package_esp32_index.json
bekommt man einen Boardverwalter von Espressif mit der Version 1.0.6, wie im Bild oben.
Damit ist alles wie gewünscht compilierbar. Läuft auf Anhieb, vielen Dank dafür.
Mit der von Arduino selbst propagierten URL
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
bekommt man Version 2.03. Darin fehlen besagte Dateien und weitere Teile.
Der langen Rede kurzer Sinn: downgraden auf 1.06 hilft

Wilfried Klaas

Wilfried Klaas

Hallo Jörg,
Ja, es kann durchaus sein, das ein anderes Board dort zu wählen ist. Bei der Boardauswahl immer das Board wählen, was der Hersteller angibt. Damit sollte es zumindest funktionieren. Manchmal ändert sich auch das eingesetzte Modul bei unterschiedlichen Chargen.
#Repetier-Server: Ich hab mir den Repetier Server nicht in der Tiefe angeschaut. Deswegen kann ich da leider keine genaueren Aussagen treffen. Die CAM funktioniert nicht als klassische WebCam, liefert also keinen konstanten Stream. Statt dessen ruft der WebClient immer wieder eine URL auf und bekommt dort ein JPEG. Wenn der Repetier Server das nachstellen und verarbeiten kann, dann sollte das funktionieren. In der Doku hab ich allerdings nichts dergleichen gefunden.

Jörg

Jörg

Hat klasse geklappt, nachdem ich erstmal mein altes defekten Adapter gegen einen neuen FT232RL von AZ getauscht habe.
Dann noch das AZ Board “Al Thinker ESP32-CAM” ausgewählt und schon hat es funktioniert.

FRAGE: Kann man die Cam unter WebCam bei Repetier-Server im Bereich “Dynamische Bild URL”
oder sonstwie einbinden???
Danke für eine Info!

VG
Jörg

Andreas Wolter

Andreas Wolter

@Georg: das Problem gibt es scheinbar schon länger. Vielleicht hilft Ihnen das hier weiter:

https://github.com/espressif/esp32-camera/issues/102

Grüße,
Andreas Wolter
AZ-Delivery Blog

georg

georg

hallo,
meine ESP32cam stammt vom AZ-delivery, leider wird der start des codes mit der fehlermeldung:
-————————-
rst:0×1 (POWERON_RESET),boot:0×13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0×00,q_drv:0×00,d_drv:0×00,cs0_drv:0×00,hd_drv:0×00,wp_drv:0×00
mode:DIO, clock div:1
load:0×3fff0018,len:4
load:0×3fff001c,len:1216
ho 0 tail 12 room 4
load:0×40078000,len:10944
load:0×40080400,len:6388
entry 0×400806b4

] camera_probe(): Detected camera not supported.
[E][camera.c:1379] esp_camera_init(): Camera probe failed with error 0×20004
-——————-
beendet. Woran kann das liegen?

Dave

Dave

Die ESP32CAM ist genial und unschlagbar zu dem Preis. Ich hatte sie mehrere Wochen zur Beobachtung eines kranken Haustieres im Einsatz. Aktuell bin ich am entwickeln einer temporären Rückfahrkamera zum Ankuppeln vom Wohnwagen, eingesteckt und versorgt aus der KFZ-Anhängerkupplung und Anzeige des Bildes auf dem Smartphone. Ich bin schon gespannt, ob die Latenzzeit geringer ist, wie die der winkenden und rufenden Ehefrau zum Fahrer :-) Die Verbesserungen zum Verbindungsaufbau und die reduzierte Oberfläche gefällt mir gut. Vielen Dank für die tollen und gut nachvolziehbaren Projekte und Blogbeiträge hier!

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. ESP32 jetzt über den Boardverwalter installieren - AZ-Delivery
  2. Internet-Radio mit dem ESP32 - UPDATE - AZ-Delivery
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1 - AZ-Delivery
  4. ESP32 - das Multitalent - AZ-Delivery