Skip to content

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.

  • 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)
  1. Locate the MIPI CSI connector on the P4-NANO (labeled “CAM” on the board)
  2. Lift the connector latch gently
  3. Insert the OV5647 NoIR flex cable with contacts facing down
  4. Press the latch closed — it should click

Insert a FAT32-formatted MicroSD card containing:

The ESP32-P4 requires ESP-IDF (not Arduino). Follow the official installation guide:

Terminal window
# Clone ESP-IDF (v5.4+)
mkdir -p ~/esp && cd ~/esp
git clone -b v5.4 --recursive https://github.com/espressif/esp-idf.git
cd esp-idf && ./install.sh esp32p4
# Activate the environment (add to your shell profile)
. ~/esp/esp-idf/export.sh

Verify the installation:

Terminal window
idf.py --version
# Should show v5.4.x or later
Terminal window
cd firmware
# Set the target to ESP32-P4
idf.py set-target esp32p4
# Build the firmware
idf.py build
# Flash via USB-C (no FTDI adapter needed)
idf.py flash
# Monitor serial output
idf.py monitor

The serial monitor (115200 baud) should show:

SmartPot Trap Unit v0.2-p4
Camera initialized: OV5647 NoIR (MIPI CSI)
Calibration loaded: focal=500.0px dist=350mm img=320x320
ESP-DL model ready
Door default: UNLOCKED
Tether UART initialized
Waiting for tether connection...

If the camera fails to initialize, verify:

  1. MIPI CSI flex cable is fully seated and latch is closed
  2. The OV5647 module is a NoIR variant (no IR-cut filter)
  3. ESP-IDF MIPI CSI driver is enabled in sdkconfig

If the model fails to load, verify:

  1. MicroSD card is FAT32-formatted and inserted
  2. species_detect.espdl is at the card root
  3. calibration.bin is at the card root

The trap_p4 environment in platformio.ini is configured for ESP-IDF framework:

Terminal window
cd firmware
pio run -e trap_p4
pio run -e trap_p4 --target upload
pio device monitor -e trap_p4
  • 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[]