Flash the ESP32-P4
This guide walks through setting up the ESP-IDF toolchain and flashing the SmartPot firmware onto an ESP32-P4-NANO module for the submerged vision unit.
Prerequisites
Section titled “Prerequisites”- Waveshare ESP32-P4-NANO module
- OV5647 NoIR camera module with MIPI CSI flex cable
- MicroSD card (for model and calibration data)
- USB-C cable (data-capable)
- Computer with ESP-IDF installed (v5.4+ required for P4 support)
Hardware Setup
Section titled “Hardware Setup”MIPI CSI Camera Connection
Section titled “MIPI CSI Camera Connection”- Locate the MIPI CSI connector on the P4-NANO (labeled “CAM” on the board)
- Lift the connector latch gently
- Insert the OV5647 NoIR flex cable with contacts facing down
- Press the latch closed — it should click
MicroSD Card
Section titled “MicroSD Card”Insert a FAT32-formatted MicroSD card containing:
species_detect.espdl— the detection model (see Train the Species Model)calibration.bin— camera calibration data (see Train the Species Model)
Tether Connection
Section titled “Tether Connection”Install ESP-IDF
Section titled “Install ESP-IDF”The ESP32-P4 requires ESP-IDF (not Arduino). Follow the official installation guide:
# Clone ESP-IDF (v5.4+)mkdir -p ~/esp && cd ~/espgit clone -b v5.4 --recursive https://github.com/espressif/esp-idf.gitcd esp-idf && ./install.sh esp32p4
# Activate the environment (add to your shell profile). ~/esp/esp-idf/export.shVerify the installation:
idf.py --version# Should show v5.4.x or laterBuild and Flash
Section titled “Build and Flash”cd firmware
# Set the target to ESP32-P4idf.py set-target esp32p4
# Build the firmwareidf.py build
# Flash via USB-C (no FTDI adapter needed)idf.py flash
# Monitor serial outputidf.py monitorVerify
Section titled “Verify”The serial monitor (115200 baud) should show:
SmartPot Trap Unit v0.2-p4Camera initialized: OV5647 NoIR (MIPI CSI)Calibration loaded: focal=500.0px dist=350mm img=320x320ESP-DL model readyDoor default: UNLOCKEDTether UART initializedWaiting for tether connection...If the camera fails to initialize, verify:
- MIPI CSI flex cable is fully seated and latch is closed
- The OV5647 module is a NoIR variant (no IR-cut filter)
- ESP-IDF MIPI CSI driver is enabled in
sdkconfig
If the model fails to load, verify:
- MicroSD card is FAT32-formatted and inserted
species_detect.espdlis at the card rootcalibration.binis at the card root
PlatformIO Alternative
Section titled “PlatformIO Alternative”The trap_p4 environment in platformio.ini is configured for ESP-IDF framework:
cd firmwarepio run -e trap_p4pio run -e trap_p4 --target uploadpio device monitor -e trap_p4Next Steps
Section titled “Next Steps”- Load the detection model (see Train the Species Model)
- Connect to the smart buoy via tether cable (after pin validation)
- Configure keeper thresholds for your target species in
species_rules[]