Video Tutorial (Optional)
Watch first if you want to see the full ESP32-CAM MicroPython setup and workflow in real time.
Project Overview
ESP32-CAM + onboard camera: In this guide, you set up MicroPython on the ESP32-CAM so you can use the onboard camera and connect to WiFi, then re-run scripts from Thonny without constantly hard-resetting the board.
By the end, you will be able to work from the MicroPython REPL and run your camera and network code reliably, with simple do and do not guidelines for cleanup.
Reminder: an interactive version of this project with code samples is available on Razzl: https://share.razzl.com/hMLn
- Time: 20 to 45 minutes
- Skill level: Beginner to Intermediate
- What you will build: A working ESP32-CAM MicroPython setup that can connect to WiFi and run camera scripts from Thonny
Parts List
From ShillehTek
- No ShillehTek product links were provided in the original guide.
External
- ESP32-CAM development board (with onboard camera)
- USB-to-serial adapter and wiring to connect the ESP32-CAM to your computer
- Computer with a terminal/command prompt
- Thonny (or another MicroPython IDE) for REPL access
- MicroPython ESP32-CAM firmware repository (micropython-camera-driver)
- esptool (installed via pip)
Note: The flash commands below include an example serial port path (/dev/ttyUSB0). Use the correct port name for your system.
Step-by-Step Guide
Step 1 - Install MicroPython on the ESP32-CAM
Goal: Flash a MicroPython firmware build that includes camera support onto the ESP32-CAM.
What to do: Download the MicroPython firmware from this repository, then install esptool and flash the firmware.
- Download the MicroPython firmware from: micropython-camera-driver
- Install esptool from a terminal/command prompt.
Code:
pip install esptool
Open a terminal/command prompt, navigate to where your firmware file is located, then run the following commands (replace /dev/ttyUSB0 with your actual port and adjust the firmware filename as needed):
Code:
esptool.py --chip esp32 --port /dev/ttyUSB0 erase_flash
esptool.py --chip esp32 --port /dev/ttyUSB0 write_flash -z 0x1000 micropython_camera_feeeb5ea3_esp32_idf4_4.bin
Hard reset: Perform a hard reset after flashing (unplug the ESP32-CAM and plug it back into your computer).
Access MicroPython REPL: Connect the ESP32-CAM to your computer and open Thonny (or your preferred MicroPython IDE) to access the REPL.
Expected result: The ESP32-CAM boots into MicroPython and you can interact with it through the REPL.
Step 2 - Use the code sample and follow cleanup best practices
Goal: Run camera and WiFi scripts repeatedly without needing to hard reset after each run.
What to do: Use the code from the video (available on Razzl) and follow these best practices for deinitialization, package installs, and WiFi credentials management.
You can download the code shown in the video via the interactive project here: https://share.razzl.com/hMLn
Deinitialization and disconnection: Deinitialize the camera (camera.deinit()) and disconnect from WiFi (sta_if.disconnect()) after use. This ensures cleanup and resource release. Otherwise, you may need a hard reset each time you use the camera or network.
MicroPython packages: Use upip to install additional packages. Example:
import upip
upip.install("urequests")
Configuration file (config.py): Store WiFi credentials in a separate config.py file as constants. Example:
# config.py
ssid = "YourWiFiSSID"
password = "YourWiFiPassword"
Update config.py with your real WiFi credentials before running your scripts.
Expected result: You can connect to WiFi, run camera scripts, and re-run them from Thonny with fewer lockups by cleaning up camera and network resources after each run.
Conclusion
You set up MicroPython on the ESP32-CAM and learned the key habits for running the onboard camera and WiFi reliably from Thonny. With proper camera deinitialization and WiFi disconnects, you can re-run scripts without needing constant hard resets.
Want parts and tools for builds like this? Grab what you need from ShillehTek.com. If you want help adapting this ESP32-CAM MicroPython workflow for your product or a custom IoT build, check out our IoT consulting services.
Channel links from the original post: Youtube and https://www.buymeacoffee.com/mmshilleh