Skip to main content

Working with ESP-IDF

This chapter includes the following sections. Please read as needed:

ESP-IDF Getting Started

New to ESP32 ESP-IDF development and looking to get started quickly? We have prepared a general Getting Started Tutorial for you.

Please Note: This tutorial uses the ESP32-S3-Zero as a teaching example, and all hardware code is based on its pinout. Before you start, it is recommended that you check the pinout of your development board to ensure the pin configuration is correct.

Setting Up the Development Environment

This example package is ported based on ESP-IDF 5.5.4. Please refer to the Waveshare ESP-IDF Getting Started - Section 1 Set Up Environment to complete the development environment configuration.

Example Package Structure

The ESP-IDF examples are located in the ESP-IDF/example directory of the example package. In addition to the individual projects, this directory also contains two shared components:

example/
├── 01_IO_Test/
├── ...
├── 12_ETH_Web_CAM/
├── cam_web_common/
└── eth_w5500_common/

cam_web_common

cam_web_common encapsulates the common functionality for the camera and web service, and is reused by 08_WIFI_Web_CAM and 12_ETH_Web_CAM. It mainly includes:

  • GPIO definitions and camera initialization for the ESP32-S3-ETH camera interface;
  • GPIO8 camera enable control;
  • JPEG photo capture and MJPEG video streaming;
  • Parameter control for image quality, brightness, contrast, resolution, etc.;
  • HTTP pages, status queries, and camera register access interfaces.

The two camera examples only handle Wi-Fi or W5500 network connections, respectively. Camera initialization and HTTP service are implemented by this shared component, avoiding duplicate code across the two projects.

eth_w5500_common

eth_w5500_common encapsulates the common initialization process for the onboard W5500 of the ESP32-S3-ETH, and is reused by 09_ETH_DHCP, 10_ETH_StaticIP, 11_ETH_MAC_DHCP_StaticIP and 12_ETH_Web_CAM. It mainly includes:

  • SPI2 and GPIO definitions for the W5500;
  • Optional W5500 hardware reset;
  • 20 MHz SPI bus and W5500 MAC and PHY driver initialization;
  • MAC address configuration;
  • Association of the Ethernet driver with the esp_netif network interface.
W5500 SignalESP32-S3-ETH
MISOGPIO12
MOSIGPIO11
SCLKGPIO13
CSGPIO14
RSTGPIO9
INTGPIO10
Keep the Shared Component Directories

The camera and Ethernet projects reference the sibling shared components via EXTRA_COMPONENT_DIRS in the top-level CMakeLists.txt. When copying the examples, you need to keep the corresponding cam_web_common or eth_w5500_common directory and its relative location. If you move a project individually, you need to copy the shared component as well and modify the EXTRA_COMPONENT_DIRS path in the project.

Example

The ESP-IDF examples are as follows:

ExampleDescriptionShared Component
01_IO_TestGPIO pin high/low level control-
02_RGB_LEDControls the WS2812 RGB LED using RMT-
03_SD_CardMounts a TF card using SDSPI and reads/writes files-
04_WiFi_APSets up a Wi-Fi AP and displays connected device information-
05_WiFi_STAConnects to Wi-Fi and controls GPIO18 via a web page-
06_WIFI_DHCPObtains an IP address via DHCP over Wi-Fi-
07_WIFI_StaticIPUses a static IP address over Wi-Fi-
08_WIFI_Web_CAMStreams camera images over Wi-Ficam_web_common
09_ETH_DHCPObtains an IP address via DHCP over W5500eth_w5500_common
10_ETH_StaticIPUses a static IP address over W5500eth_w5500_common
11_ETH_MAC_DHCP_StaticIPSwitches to a static IP address after DHCP times outeth_w5500_common
12_ETH_Web_CAMStreams camera images over W5500cam_web_common, eth_w5500_common

01_IO_Test

This example initializes 19 GPIOs that can be used as outputs to low level, then pulls them high and low one by one at 300 ms intervals.

Expected Behavior

The serial monitor cyclically displays the initialization and level change information for each GPIO.

ESP-IDF GPIO Test Serial Output

02_RGB_LED

This example uses the ESP-IDF native RMT peripheral to drive the WS2812 RGB LED on GPIO21. The data format is GRB at 800 kHz with a brightness of 50/255. The main loop executes red, green, and blue fill, followed by white, red, and blue theater chase effects.

Expected Behavior

The RGB LED displays fill and chase effects with a 50 ms step interval.

RGB LED Expected Behavior

03_SD_Card

This example uses the ESP-IDF SDSPI and FAT VFS drivers to mount the onboard TF card. The program writes Hello world from Waveshare to /waveshare.txt in append mode, lists the root directory contents, and then reads and prints the file.

tip

This example only supports the FAT32 file system by default; using a 16 GB or 32 GB TF card is recommended. exFAT and NTFS are not supported. SDXC cards of 64 GB and above usually use the exFAT format by default, and must be backed up and reformatted to FAT32 before use. Formatting will erase all data on the card.

TF Card SignalESP32-S3-ETH
MISOGPIO5
MOSIGPIO6
SCLKGPIO7
CSGPIO4

The project has enabled FATFS long filename support in sdkconfig.defaults. The TF card must use the FAT or FAT32 file system.

TF Card Long File Name Support Configuration

TF Card Hardware Connection

Expected Behavior

The serial monitor displays the TF card capacity, file write result, root directory file list, and file contents.

TF Card Example

04_WiFi_AP

This example creates a WPA2 SoftAP with the SSID ESP32-S3-ETH and password 88888888. When a client connects, it prints the MAC address; after DHCP address assignment completes, it prints the client IP address; when the client disconnects, it prints a prompt.

ESP-IDF Wi-Fi AP Running Result

05_WiFi_STA

This example connects to Waveshare-AP and starts an HTTP service on port 80. Accessing /H sets GPIO18 to high level, and accessing /L sets GPIO18 to low level.

When using another network, modify WIFI_SSID and WIFI_PASSWORD in main/wifi_sta.c.

tip

If possible, refer to the figure on the right to connect an LED in series to visually check the GPIO18 high/low level state, or measure it with a multimeter.

GPIO18 Wiring Diagram

ESP-IDF Wi-Fi STA Connection and Server Address

GPIO18 Low Level Web Page Status

GPIO18 High Level Web Page Status

GPIO18 Restored to Low Level Web Page Status

06_WIFI_DHCP

This example connects to Waveshare-AP and obtains an IPv4 address assigned by the router via DHCP. If the connection drops, the program automatically reconnects.

When using another network, modify the Wi-Fi parameters in main/wifi_dhcp.c.

ESP-IDF Wi-Fi DHCP Running Result

07_WIFI_StaticIP

This example connects to Waveshare-AP and uses the following static network parameters:

  • IP address: 192.168.196.100
  • Gateway: 192.168.196.1
  • Subnet mask: 255.255.255.0
  • DNS: 192.168.196.1

The default password in the example source code is 88888888. Before use, confirm that the router is on the 192.168.196.0/24 subnet and that 192.168.196.100 is not occupied by another device.

ESP-IDF Wi-Fi Static IP Running Result

08_WIFI_Web_CAM

This example connects to the network over Wi-Fi, uses cam_web_common to initialize the camera, and starts the web service. The web page supports MJPEG video streaming, single-frame photo capture, and settings for image quality, brightness, contrast, and more.

Configure Wi-Fi

Run the following command:

idf.py menuconfig

Configure the SSID and password under "Wi-Fi camera configuration". After a successful connection, access the URL output in the serial log.

Camera Hardware Connection

Camera Interface

Camera SignalESP32-S3-ETH
ENABLEGPIO8
VSYNCGPIO1
HREFGPIO2
XCLKGPIO3
PCLKGPIO39
SIOD (SDA)GPIO48
SIOC (SCL)GPIO47
D7GPIO18
D6GPIO15
D5GPIO38
D4GPIO40
D3GPIO42
D2GPIO46
D1GPIO45
D0GPIO41

Camera Web Page

09_ETH_DHCP

This example initializes the W5500 via eth_w5500_common, with the MAC address set to DE:AD:BE:EF:FE:ED. The program waits for a DHCP-assigned address; if no IP address is obtained within 60 seconds, it outputs a failure message and stops waiting.

Ethernet Hardware Connection

ESP-IDF W5500 DHCP Running Result

10_ETH_StaticIP

This example uses the following static network parameters over the W5500:

  • IP address: 192.168.9.200
  • Gateway and DNS: 192.168.9.1
  • Subnet mask: 255.255.255.0
  • MAC address: DE:AD:BE:EF:FE:ED

ESP-IDF W5500 Static IP Running Result

11_ETH_MAC_DHCP_StaticIP

This example performs a hardware reset on the W5500 at startup and attempts to obtain an IP address via DHCP. If no address is obtained within 60 seconds, it switches to the following static network parameters:

  • IP address: 192.168.1.177
  • Gateway and DNS: 192.168.1.1
  • Subnet mask: 255.255.255.0
  • MAC address: DE:AD:BE:EF:FE:ED

ESP-IDF W5500 DHCP Fallback to Static IP Running Result

12_ETH_Web_CAM

This example uses both eth_w5500_common and cam_web_common. The program first initializes the camera and the W5500, waits for a DHCP-assigned IP address, and then starts the camera web service.

After a successful connection, the serial monitor outputs the access URL. Open that URL in a browser on the same network to use MJPEG video streaming, photo capture, and image parameter settings.

Ethernet Camera and PoE Module Connection

Ethernet Camera Page

Documentation Feedback

If you encounter any issues during use, feel free to leave a comment.