---
title: "How to Test Static-IP UDP Networking with WIZnet W5500 on ESP32 MicroPython?"
url: "https://maker.wiznet.io/ronpang/projects/how-to-test-static-ip-udp-networking-with-wiznet-w5500-on-esp32-micropython/"
markdown_url: "https://maker.wiznet.io/ronpang/projects/how-to-test-static-ip-udp-networking-with-wiznet-w5500-on-esp32-micropython/md"
type: "UCC: User Created Content"
author: "Groundwork Explorer"
author_url: "https://blog.csdn.net/iot2022/article/details/153522149?ops_request_misc=%257B%2522request%255Fid%2522%253A%25226b5c40e822200d23e4a2afd2f0444bc6%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=6b5c40e822200d23e4a2afd2f0444bc6&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~time_text~default-5-153522149-null-null.142^v102^pc_search_result_base4&utm_term=w5500%20micropython&spm=1018.2226.3001.4187"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "Groundwork Explorer"
original_url: "https://blog.csdn.net/iot2022/article/details/153522149?ops_request_misc=%257B%2522request%255Fid%2522%253A%25226b5c40e822200d23e4a2afd2f0444bc6%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=6b5c40e822200d23e4a2afd2f0444bc6&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~time_text~default-5-153522149-null-null.142^v102^pc_search_result_base4&utm_term=w5500%20micropython&spm=1018.2226.3001.4187"
published: "2026-06-15"
language: "en"
likes: 0
views: 337
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# How to Test Static-IP UDP Networking with WIZnet W5500 on ESP32 MicroPython?

> This robotics-focused ESP32 MicroPython project tests a WIZnet W5500 Ethernet module with a direct cable connection to a PC using static IP settings.

Original author: Groundwork Explorer (source: https://blog.csdn.net/iot2022/article/details/153522149?ops_request_misc=%257B%2522request%255Fid%2522%253A%25226b5c40e822200d23e4a2afd2f0444bc6%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=6b5c40e822200d23e4a2afd2f0444bc6&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~time_text~default-5-153522149-null-null.142^v102^pc_search_result_base4&utm_term=w5500%20micropython&spm=1018.2226.3001.4187)

## Article

## How to Test Static-IP UDP Networking with WIZnet W5500 on ESP32 MicroPython?

### Summary

This robotics-focused ESP32 MicroPython project tests a WIZnet W5500 Ethernet module with a direct cable connection to a PC using static IP settings. The ESP32 drives W5500 over SPI, disables DHCP for direct-link testing, manually writes IP/subnet/gateway/DNS values, binds the W5500 driver to a MicroPython socket abstraction, and sends UDP packets to a PC test program. W5500 provides the wired Ethernet interface, hardware TCP/IP stack, socket state machine, and packet buffering needed for deterministic robot-node communication.

### What the Project Does

The project validates W5500 networking under MicroPython on ESP32. The author starts with a direct Ethernet cable connection to a PC and finds that the default driver path assumes DHCP is available. In a direct cable setup without a DHCP server, initialization fails with `AssertionError: Failed to configure DHCP Server!`, so the W5500 driver must be created with DHCP disabled.

The next issue is static IP configuration. The article shows that assigning dotted IPv4 strings directly to `nic.ifconfig` causes `TypeError: can't convert str to int`, because the driver expects byte-form IP values. The fix is to convert strings such as `172.16.30.119` into byte arrays before writing the W5500 network registers.

For robotics, this pattern maps well to camera nodes, sensor nodes, motor-control test stations, or embedded controllers that need a stable wired debugging path to a laptop or robot supervisor. A robot node can stream compact UDP telemetry such as pose, encoder count, target coordinates, or status flags without depending on Wi-Fi association or a router-side DHCP service.

### Where WIZnet Fits

The exact WIZnet product is **W5500**. In this architecture, W5500 is the SPI-connected Ethernet controller between the ESP32 MicroPython runtime and the wired LAN or direct PC link. ESP32 runs the Python application and driver calls; W5500 handles Ethernet MAC/PHY operation, TCP/IP offload, hardware sockets, socket status, and internal packet buffering.

The article uses a W5500 Lite module wiring pattern: `sck=Pin(26)`, `mosi=Pin(25)`, `miso=Pin(13)`, `cs=Pin(27, Pin.OUT)`, and 3.3 V power. It also uses a reset object in software, although the note says the referenced reset GPIO can be effectively tied high in that hardware setup.

W5500 is suitable for this role because it provides 8 independent hardware sockets, with each socket having its own register group and strict state machine. The article explicitly describes states such as `SOCK_CLOSED`, `SOCK_INIT`, `SOCK_LISTEN`, `SOCK_ESTABLISHED`, and `SOCK_UDP`, and notes that the maximum concurrent hardware socket count is 8.

### Implementation Notes

**File: **`**application test script**`
**What it configures:** ESP32 SPI pins, W5500 chip select, static IP mode, socket interface binding, and UDP transmission.
**Why it matters:** the W5500 driver must be initialized without DHCP for a direct PC link, and the socket abstraction must be explicitly bound to the W5500 interface before creating sockets.

```plaintext
from wiznet5k import WIZNET5K
from machine import Pin, SPI
import wiznet5k_socket as socket
import time

spi = SPI(2, baudrate=8000000, sck=Pin(26), mosi=Pin(25), miso=Pin(13))
cs = Pin(27, Pin.OUT)
rst = Pin(39)

nic = WIZNET5K(spi, cs, rst, is_dhcp=False)
socket.set_interface(nic)

udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
dest_addr = ('172.16.30.133', 8080)
```

This code exists because the direct-cable test does not provide DHCP. The article also states that calling `socket.set_interface(nic)` before creating a socket is the key step that prevents the `'NoneType' object has no attribute 'get_socket'` error.

**File: **`**wiznet5k.py**`
**What it configures:** static network parameters as byte values instead of strings.
**Why it matters:** the W5500 register write path expects byte-form IP values when writing local IP, subnet, gateway, and DNS-related fields.

```plaintext
def ip_to_bytes(ip_str):
    return bytes([int(part) for part in ip_str.split('.')])

nic.ifconfig = (
    ip_to_bytes('172.16.30.119'),
    ip_to_bytes('255.255.255.0'),
    ip_to_bytes('172.16.30.254'),
    ip_to_bytes('8.8.8.8')
)
```

This conversion exists because passing normal dotted IPv4 strings caused a type conversion error in the driver. In register terms, the MicroPython layer must eventually write four-byte values into W5500 network configuration registers, not text strings.

**File: **`**wiznet5k_socket.py**`
**What it configures:** the MicroPython socket abstraction layer over W5500 hardware sockets.
**Why it matters:** application code should not directly manage every W5500 socket register. The abstraction layer maps standard socket-style calls onto W5500 socket allocation, state checks, TCP/UDP mode selection, and data movement.

```plaintext
_the_interface = None

def set_interface(iface):
    global _the_interface
    _the_interface = iface

SOCK_STREAM = const(0x21)  # TCP
SOCK_DGRAM = const(0x02)   # UDP
AF_INET = const(3)
SOCKET_INVALID = const(255)
```

The article describes a three-layer model: application layer using a standard socket API, `wiznet5k_socket.py` as the abstraction bridge, and `wiznet5k.py` as the hardware driver that directly operates W5500 registers through SPI.

### Practical Tips / Pitfalls

- For direct PC-to-W5500 testing, disable DHCP and use static IP on both sides.

- Convert IPv4 strings to byte values before assigning `nic.ifconfig`; the driver does not accept dotted strings in that path.

- Call `socket.set_interface(nic)` before creating TCP or UDP sockets.

- Keep SPI conservative during bring-up. The test uses an 8 MHz SPI baud rate, which is a practical starting point before optimizing throughput.

- Track W5500 socket count. The chip has 8 physical sockets, including listening sockets and data sockets.

- For robot telemetry, add sequence numbers and timestamps to UDP packets so the PC or robot supervisor can detect drops, repeats, and jitter.

- Keep Ethernet data compact. Send coordinates, status, and control values first; avoid raw image or high-rate debug streams until socket timing is proven.

### FAQ

**Q: Why use WIZnet W5500 for ESP32 MicroPython robotics networking?**
A: W5500 gives the ESP32 a wired Ethernet path with hardware TCP/IP sockets and packet buffers. That is useful for robot nodes where predictable wired communication is more important than wireless convenience, especially during bench testing, calibration, or competition debugging.

**Q: How does W5500 connect to the ESP32 platform in this project?**
A: The article uses SPI wiring with SCK on GPIO26, MOSI on GPIO25, MISO on GPIO13, chip select on GPIO27, and 3.3 V power. The test script creates `SPI(2, baudrate=8000000, ...)` and passes the SPI bus, chip select, and reset object into `WIZNET5K()`.

**Q: What role does W5500 play in this project?**
A: W5500 is the Ethernet and socket engine. ESP32 MicroPython creates the application payload and calls socket-like APIs, while W5500 handles the lower Ethernet transport, socket states, hardware socket registers, and TX/RX buffering.

**Q: Can beginners follow this project?**
A: Yes, if they understand ESP32 MicroPython, SPI wiring, static IPv4 addressing, and basic UDP sockets. The most important beginner lesson is that a direct cable link usually needs static IP setup, not DHCP.

**Q: What should be checked first when UDP packets do not arrive?**
A: Check SPI wiring, W5500 initialization, static IP/subnet settings on both ESP32 and PC, `socket.set_interface(nic)`, destination IP and port, PC firewall rules, and whether the receiving PC program is listening on the correct port.

### Source

Original article: CSDN, “W5500 micropython 驱动测试 网线直连电脑静态IP,” first published on 2025-10-18 and modified on 2026-02-03. The article is marked CC 4.0 BY-SA.

Reference video link mentioned by the article: Bilibili, “W5500 esp32 mpy 参考视频.”

### Tags

#W5500 #WIZnet #ESP32 #MicroPython #UDP #Robotics #SPI #StaticIP #Ethernet #SocketDriver #Firmware #Registers #Performance #Maker

## ESP32 MicroPython에서 WIZnet W5500으로 Static-IP UDP 네트워킹을 테스트하는 방법은?

### 요약

이 로보틱스 중심 ESP32 MicroPython 프로젝트는 WIZnet W5500 이더넷 모듈을 PC와 직접 케이블로 연결하고, static IP 설정으로 UDP 통신을 테스트합니다. ESP32는 SPI로 W5500을 제어하고, 직접 연결 테스트를 위해 DHCP를 비활성화하며, IP/subnet/gateway/DNS 값을 수동으로 설정합니다. 이후 W5500 드라이버를 MicroPython 소켓 추상화 계층에 연결하고, PC 테스트 프로그램으로 UDP 패킷을 전송합니다. W5500은 결정적인 로봇 노드 통신에 필요한 유선 Ethernet 인터페이스, 하드웨어 TCP/IP 스택, 소켓 상태 머신, 패킷 버퍼링을 제공합니다.

### 프로젝트가 하는 일

이 프로젝트는 ESP32의 MicroPython 환경에서 W5500 네트워킹을 검증합니다. 작성자는 먼저 PC와 Ethernet 케이블로 직접 연결해 테스트를 시작했습니다. 이 과정에서 기본 드라이버 경로가 DHCP 사용을 전제로 한다는 점을 확인했습니다. DHCP 서버가 없는 직접 케이블 연결 환경에서는 초기화가 `AssertionError: Failed to configure DHCP Server!` 오류로 실패하므로, W5500 드라이버를 DHCP 비활성화 모드로 생성해야 합니다.

다음 문제는 static IP 설정입니다. 원문은 `nic.ifconfig`에 `172.16.30.119` 같은 dotted IPv4 문자열을 직접 대입하면 `TypeError: can't convert str to int` 오류가 발생한다고 설명합니다. 드라이버가 IP 값을 문자열이 아니라 byte 형식으로 기대하기 때문입니다. 해결 방법은 IP 문자열을 byte array로 변환한 뒤 W5500 네트워크 레지스터에 기록하는 것입니다.

로보틱스 관점에서 이 패턴은 카메라 노드, 센서 노드, 모터 제어 테스트 스테이션, 임베디드 컨트롤러에 잘 맞습니다. 로봇 노드는 Wi-Fi 연결이나 라우터의 DHCP 서비스에 의존하지 않고, pose, encoder count, target coordinate, status flag 같은 compact UDP telemetry를 안정적인 유선 경로로 전송할 수 있습니다.

### WIZnet이 들어가는 위치

이 프로젝트에서 사용되는 WIZnet 제품은 **W5500**입니다. 이 구조에서 W5500은 ESP32 MicroPython 런타임과 유선 LAN 또는 PC 직접 연결 사이에 위치하는 SPI 연결 Ethernet 컨트롤러입니다. ESP32는 Python 애플리케이션과 드라이버 호출을 실행하고, W5500은 Ethernet MAC/PHY 동작, TCP/IP 오프로딩, 하드웨어 소켓, 소켓 상태, 내부 패킷 버퍼링을 담당합니다.

원문은 W5500 Lite 모듈 배선 예를 사용합니다. `sck=Pin(26)`, `mosi=Pin(25)`, `miso=Pin(13)`, `cs=Pin(27, Pin.OUT)`, 3.3 V 전원을 사용합니다. 소프트웨어에서는 reset 객체도 사용하지만, 원문은 해당 하드웨어 구성에서 참조된 reset GPIO가 사실상 high로 묶일 수 있다고 설명합니다.

W5500은 8개의 독립 하드웨어 소켓을 제공하며, 각 소켓은 자체 레지스터 그룹과 엄격한 상태 머신을 가집니다. 원문도 `SOCK_CLOSED`, `SOCK_INIT`, `SOCK_LISTEN`, `SOCK_ESTABLISHED`, `SOCK_UDP` 같은 상태를 설명하고, 최대 동시 하드웨어 소켓 수가 8개임을 언급합니다.

### 구현 참고 사항

**파일: **`**application test script**`
**설정 내용:** ESP32 SPI 핀, W5500 chip select, static IP 모드, socket interface binding, UDP 전송
**중요한 이유:** PC 직접 연결 테스트에는 DHCP가 없으므로 W5500 드라이버를 DHCP 없이 초기화해야 합니다. 또한 소켓을 생성하기 전에 W5500 인터페이스를 소켓 추상화 계층에 명시적으로 연결해야 합니다.

```plaintext
from wiznet5k import WIZNET5K
from machine import Pin, SPI
import wiznet5k_socket as socket
import time

spi = SPI(2, baudrate=8000000, sck=Pin(26), mosi=Pin(25), miso=Pin(13))
cs = Pin(27, Pin.OUT)
rst = Pin(39)

nic = WIZNET5K(spi, cs, rst, is_dhcp=False)
socket.set_interface(nic)

udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
dest_addr = ('172.16.30.133', 8080)
```

이 코드는 직접 케이블 테스트 환경에 DHCP 서버가 없기 때문에 필요합니다. 원문은 소켓을 생성하기 전에 `socket.set_interface(nic)`를 호출하는 것이 `'NoneType' object has no attribute 'get_socket'` 오류를 방지하는 핵심 단계라고 설명합니다.

**파일: **`**wiznet5k.py**`
**설정 내용:** static network parameter를 문자열이 아니라 byte 값으로 설정
**중요한 이유:** W5500 레지스터 write 경로는 local IP, subnet, gateway, DNS 관련 필드를 기록할 때 byte 형식의 IP 값을 기대합니다.

```plaintext
def ip_to_bytes(ip_str):
    return bytes([int(part) for part in ip_str.split('.')])

nic.ifconfig = (
    ip_to_bytes('172.16.30.119'),
    ip_to_bytes('255.255.255.0'),
    ip_to_bytes('172.16.30.254'),
    ip_to_bytes('8.8.8.8')
)
```

이 변환은 일반 dotted IPv4 문자열을 넘겼을 때 드라이버에서 타입 변환 오류가 발생했기 때문에 필요합니다. 레지스터 관점에서 MicroPython 계층은 최종적으로 텍스트 문자열이 아니라 4바이트 값을 W5500 네트워크 설정 레지스터에 기록해야 합니다.

**파일: **`**wiznet5k_socket.py**`
**설정 내용:** W5500 하드웨어 소켓 위의 MicroPython 소켓 추상화 계층
**중요한 이유:** 애플리케이션 코드가 모든 W5500 소켓 레지스터를 직접 관리하는 것은 좋지 않습니다. 추상화 계층은 표준 socket 스타일 호출을 W5500 소켓 할당, 상태 확인, TCP/UDP 모드 선택, 데이터 이동으로 매핑합니다.

```plaintext
_the_interface = None

def set_interface(iface):
    global _the_interface
    _the_interface = iface

SOCK_STREAM = const(0x21)  # TCP
SOCK_DGRAM = const(0x02)   # UDP
AF_INET = const(3)
SOCKET_INVALID = const(255)
```

원문은 세 계층 모델을 설명합니다. 애플리케이션 계층은 표준 socket API를 사용하고, `wiznet5k_socket.py`는 추상화 브리지 역할을 하며, `wiznet5k.py`는 SPI를 통해 W5500 레지스터를 직접 조작하는 하드웨어 드라이버 역할을 합니다.

### 실무 팁 / 주의점

- PC와 W5500을 직접 연결해 테스트할 때는 DHCP를 비활성화하고 양쪽 모두 static IP를 사용해야 합니다.

- `nic.ifconfig`에 값을 넣기 전에 IPv4 문자열을 byte 값으로 변환해야 합니다. 해당 드라이버 경로는 dotted string을 받지 않습니다.

- TCP 또는 UDP 소켓을 만들기 전에 `socket.set_interface(nic)`를 먼저 호출해야 합니다.

- Bring-up 단계에서는 SPI 속도를 보수적으로 설정하는 것이 좋습니다. 원문 테스트는 8 MHz SPI baud rate를 사용하며, 이는 처리량 최적화 전 실용적인 시작점입니다.

- W5500 소켓 수를 추적해야 합니다. W5500은 listening socket과 data socket을 포함해 8개의 물리 소켓을 제공합니다.

- 로봇 텔레메트리에는 UDP 패킷에 sequence number와 timestamp를 추가하는 것이 좋습니다. PC 또는 robot supervisor가 drop, repeat, jitter를 감지할 수 있습니다.

- Ethernet 데이터는 compact하게 유지해야 합니다. 소켓 타이밍이 검증되기 전에는 raw image나 고속 debug stream보다 좌표, 상태, 제어 값부터 전송하는 것이 좋습니다.

### FAQ

**Q: ESP32 MicroPython 로보틱스 네트워킹에 왜 WIZnet W5500을 사용하나요?**
A: W5500은 ESP32에 하드웨어 TCP/IP 소켓과 패킷 버퍼를 갖춘 유선 Ethernet 경로를 제공합니다. 이는 벤치 테스트, 캘리브레이션, 대회 디버깅처럼 무선 편의성보다 예측 가능한 유선 통신이 중요한 로봇 노드에 유용합니다.

**Q: 이 프로젝트에서 W5500은 ESP32 플랫폼에 어떻게 연결되나요?**
A: 원문은 SCK를 GPIO26, MOSI를 GPIO25, MISO를 GPIO13, chip select를 GPIO27에 연결하고 3.3 V 전원을 사용하는 SPI 배선을 사용합니다. 테스트 스크립트는 `SPI(2, baudrate=8000000, ...)`를 생성하고, SPI bus, chip select, reset 객체를 `WIZNET5K()`에 전달합니다.

**Q: 이 프로젝트에서 W5500은 어떤 역할을 하나요?**
A: W5500은 Ethernet 및 소켓 엔진입니다. ESP32 MicroPython은 애플리케이션 payload를 만들고 socket-like API를 호출하며, W5500은 하위 Ethernet 전송, 소켓 상태, 하드웨어 소켓 레지스터, TX/RX 버퍼링을 처리합니다.

**Q: 초보자도 이 프로젝트를 따라갈 수 있나요?**
A: ESP32 MicroPython, SPI 배선, static IPv4 주소 설정, 기본 UDP 소켓을 이해하고 있다면 가능합니다. 초보자에게 가장 중요한 학습 포인트는 PC와 직접 케이블로 연결할 때 일반적으로 DHCP가 아니라 static IP 설정이 필요하다는 점입니다.

**Q: UDP 패킷이 도착하지 않을 때 무엇을 먼저 확인해야 하나요?**
A: SPI 배선, W5500 초기화, ESP32와 PC 양쪽의 static IP/subnet 설정, `socket.set_interface(nic)`, 목적지 IP와 포트, PC 방화벽 규칙, 수신 PC 프로그램이 올바른 포트에서 listen 중인지 먼저 확인해야 합니다.

### 출처

Original article: CSDN, “W5500 micropython 驱动测试 网线直连电脑静态IP,” 2025-10-18 게시, 2026-02-03 수정, CC 4.0 BY-SA로 표시됨.
[https://blog.csdn.net/iot2022/article/details/153522149](https://blog.csdn.net/iot2022/article/details/153522149?utm_source=chatgpt.com)

Reference video link mentioned by the article: Bilibili, “W5500 esp32 mpy 参考视频.”
[https://blog.csdn.net/iot2022/article/details/153522149](https://blog.csdn.net/iot2022/article/details/153522149?utm_source=chatgpt.com)

### 태그

#W5500 #WIZnet #ESP32 #MicroPython #UDP #Robotics #SPI #StaticIP #Ethernet #SocketDriver #Firmware #Registers #Performance #Maker

---

Source: https://maker.wiznet.io/ronpang/projects/how-to-test-static-ip-udp-networking-with-wiznet-w5500-on-esp32-micropython/
