---
title: "W5500 TCP/IP Ethernet"
url: "https://maker.wiznet.io/taylor/projects/w5500-tcp-ip-ethernet/"
markdown_url: "https://maker.wiznet.io/taylor/projects/w5500-tcp-ip-ethernet/md"
type: "UCC: User Created Content"
author: "smartlogig"
author_url: "https://smartlogig.com/w5500/"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "smartlogig"
original_url: "https://smartlogig.com/w5500/"
published: "2023-09-04"
language: "en"
tags: ["Arduino"]
hardware: ["WIZnet W5500", "Raspberry Pi Pico"]
likes: 0
views: 2383
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# W5500 TCP/IP Ethernet

> The W5500 is a popular Ethernet controller chip manufactured by WIZnet.

Original author: smartlogig (source: https://smartlogig.com/w5500/)

## Components

- **WIZnet W5500** x 1 ([docs](https://docs.wiznet.io/Product/Chip/Ethernet/W5500))
- **Raspberry Pi Pico** x 1 ([docs](https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html))
- Software: **Arduino IDE** ([docs](https://www.arduino.cc/en/software))

WIZnet parts: W5500 ([Datasheet](https://docs.wiznet.io/Product/Chip/Ethernet/W5500/datasheet?utm_source=maker&utm_medium=project&utm_campaign=w5500), [product hub](https://maker.wiznet.io/products/w5500/))

## Documents and links

- [W5500-ATMEGA328P.ino](https://maker.wiznet.io/_lib/download.asp?path=project/33&downfile=W5500%2DATMEGA328P%2Eino) (code)
- [W5500-RaspberryPiPico.py](https://maker.wiznet.io/_lib/download.asp?path=project/33&downfile=W5500%2DRaspberryPiPico%2Epy) (code)

## Article

Original : <https://smartlogig.com/w5500/>

Author : Smartlogig
Published On : 2023-08-06

**This content was created with the assistance of ChatGPT, an artificial intelligence language model developed by OpenAI.**

### W5500 TCP/IP Ethernet

The W5500 is a hardwired TCP/IP embedded Ethernet controller produced by WIZnet. This chip is known for its low power consumption, high performance, and suitability for a variety of IoT projects.

**W5500 Overview:**

- The [W5500](https://www.wiznet.io/product-item/w5500/) is an Ethernet controller chip made by WIZnet.

- It facilitates TCP/IP communication over an Ethernet network.

- **Hardwired TCP/IP Stack**: The W5500 comes with an integrated hardwired TCP/IP stack, supporting major internet protocols such as TCP, UDP, ICMP, IPv4, ARP, IGMP, and PPPoE.

- **SPI (Serial Peripheral Interface)**: The W5500 communicates with various microcontrollers via the SPI interface. This simplifies design and offers fast data transfer speeds.

- **8 Independent Sockets**: The W5500 supports 8 independent hardware sockets, allowing it to manage multiple network connections simultaneously.

**Setting up a TCP server with W5500:**

1. **Hardware Setup:**
  - Connect the W5500 to a microcontroller or microprocessor.
  - Ensure proper pin connections and use necessary external components.
  - Connect the chip to the Ethernet network using an RJ45 connector.

2. **Software Setup:**
  - Use the [WIZnet iolibrary driver](https://github.com/Wiznet/ioLibrary_Driver) or any other suitable library.
  - Initialize the W5500 and set its network configurations.
  - Set the chip in TCP server mode.
  - Implement logic to handle incoming connections and data processing.

3. **TCP Server Operation:**
  - The W5500 monitors for incoming connection requests.
  - On a new connection, read data from the client and respond accordingly.
  - Handle the data and manage the connection.

**Security Consideration:** Secure the TCP server if exposed to untrusted networks.

### W5500 Applications

The W5500 is versatile and has applications in:

- Web servers
  - [Web server google search on maker.wiznet.io](https://www.google.com/search?client=firefox-b-d&q=webserver+site%3Amaker.wiznet.io%2F)

- IoT devices
  - [IoT google search on maker.wiznet.io](https://www.google.com/search?q=iot+site%3Amaker.wiznet.io%2F&newwindow=1&client=firefox-b-d&sca_esv=562459021&sxsrf=AB5stBiR6MFu8j54EvTwtPsNRF9LpJAHNg%3A1693811459512&ei=A4P1ZO3cHvmN2roP2YGM4Ak&ved=0ahUKEwit6vCys5CBAxX5hlYBHdkAA5wQ4dUDCA8&uact=5&oq=iot+site%3Amaker.wiznet.io%2F&gs_lp=Egxnd3Mtd2l6LXNlcnAiGWlvdCBzaXRlOm1ha2VyLndpem5ldC5pby9I7BNQng1Y9A5wAXgAkAEAmAFkoAGoAqoBAzIuMbgBA8gBAPgBAeIDBBgBIEGIBgE&sclient=gws-wiz-serp)

- Industrial automation
  - [Industrial google search on maker.wiznet.io](https://www.google.com/search?q=industry+site%3Amaker.wiznet.io%2F&newwindow=1&client=firefox-b-d&sca_esv=562459021&sxsrf=AB5stBjS6T6ir4fQ_zupE41X8wZoDEXv_g%3A1693811476361&ei=FIP1ZNfIFZql2roPjaWxwAs&ved=0ahUKEwjXovW6s5CBAxWaklYBHY1SDLgQ4dUDCA8&uact=5&oq=industry+site%3Amaker.wiznet.io%2F&gs_lp=Egxnd3Mtd2l6LXNlcnAiHmluZHVzdHJ5IHNpdGU6bWFrZXIud2l6bmV0LmlvL0jwEFCDB1jJDnABeACQAQGYAeEBoAG-B6oBBTEuNi4xuAEDyAEA-AEB4gMEGAEgQYgGAQ&sclient=gws-wiz-serp)

- Networked sensors and data loggers
  - [Sensor data logger google search on maker.wiznet.io](https://www.google.com/search?q=sensor+data+logger++site%3Amaker.wiznet.io%2F&newwindow=1&client=firefox-b-d&sca_esv=562459021&sxsrf=AB5stBg9EcMGdqJk7uW-0u1mi3Dr1tkScQ%3A1693811549848&ei=XYP1ZN2wM6vg1e8P7ci46AI&ved=0ahUKEwid0_rds5CBAxUrcPUHHW0kDi0Q4dUDCA8&uact=5&oq=sensor+data+logger++site%3Amaker.wiznet.io%2F&gs_lp=Egxnd3Mtd2l6LXNlcnAiKXNlbnNvciBkYXRhIGxvZ2dlciAgc2l0ZTptYWtlci53aXpuZXQuaW8vSKuzA1CykgNYw6kDcAF4AJABAJgBkAGgAZIQqgEENC4xNbgBA8gBAPgBAeIDBBgBIEGIBgE&sclient=gws-wiz-serp)

- Home automation
  - [Home automation google search on maker.wiznet.io](https://www.google.com/search?q=home+automation+site%3Amaker.wiznet.io%2F&newwindow=1&client=firefox-b-d&sca_esv=562459021&sxsrf=AB5stBjB2vwsZ2s8qXLU13sLnB9QaHk4nA%3A1693811607474&ei=l4P1ZMfGHNTr-AaI_ZGYDw&ved=0ahUKEwiH7rf5s5CBAxXUNd4KHYh-BPMQ4dUDCA8&uact=5&oq=home+automation+site%3Amaker.wiznet.io%2F&gs_lp=Egxnd3Mtd2l6LXNlcnAiJWhvbWUgYXV0b21hdGlvbiBzaXRlOm1ha2VyLndpem5ldC5pby9IqDBQmgVYwC5wAXgAkAEAmAHPAaAB8BCqAQYzLjE1LjG4AQPIAQD4AQHiAwQYASBBiAYB&sclient=gws-wiz-serp)

- Remote monitoring and control
  - [Remote monitoring google search on maker.wiznet.io](https://www.google.com/search?q=remote+monitoring+site%3Amaker.wiznet.io%2F&newwindow=1&client=firefox-b-d&sca_esv=562459021&sxsrf=AB5stBhv0LMXt_r6L_yjx8LYvPodipvdbA%3A1693811690592&ei=6oP1ZNHnI9nWhwOPs6joBw&ved=0ahUKEwjRhImhtJCBAxVZ62EKHY8ZCn0Q4dUDCA8&uact=5&oq=remote+monitoring+site%3Amaker.wiznet.io%2F&gs_lp=Egxnd3Mtd2l6LXNlcnAiJ3JlbW90ZSBtb25pdG9yaW5nIHNpdGU6bWFrZXIud2l6bmV0LmlvL0i4HlDaAliJHXABeACQAQCYAXigAeAPqgEEMy4xNrgBA8gBAPgBAeIDBBgBIEGIBgE&sclient=gws-wiz-serp)

- Robotics
  - [Robotics google search on maker.wiznet.io](https://www.google.com/search?q=robotics+site%3Amaker.wiznet.io%2F&newwindow=1&client=firefox-b-d&sca_esv=562459021&sxsrf=AB5stBgTNdRvNhbWDFuYFQiI3APILtfmSA%3A1693811705847&ei=-YP1ZP6tM5Ha-Qakq6KIAg&ved=0ahUKEwi-jqyotJCBAxURbd4KHaSVCCEQ4dUDCA8&uact=5&oq=robotics+site%3Amaker.wiznet.io%2F&gs_lp=Egxnd3Mtd2l6LXNlcnAiHnJvYm90aWNzIHNpdGU6bWFrZXIud2l6bmV0LmlvL0iREFCUBViqDHABeACQAQCYAX2gAfEGqgEDMC44uAEDyAEA-AEB4gMEGAEgQYgGAQ&sclient=gws-wiz-serp)

- Ethernet-to-Serial bridges
  - [Serial to Ethernet google search on maker.wiznet.io](https://www.google.com/search?q=serial+to+ethernet+site%3Amaker.wiznet.io%2F&newwindow=1&client=firefox-b-d&sca_esv=562459021&sxsrf=AB5stBgSJhmE5ZgHNLjBXnis5BLPwIqGTg%3A1693811718962&ei=BoT1ZLawOoXt1e8P5bejsAs&ved=0ahUKEwi2y8yutJCBAxWFdvUHHeXbCLYQ4dUDCA8&uact=5&oq=serial+to+ethernet+site%3Amaker.wiznet.io%2F&gs_lp=Egxnd3Mtd2l6LXNlcnAiKHNlcmlhbCB0byBldGhlcm5ldCBzaXRlOm1ha2VyLndpem5ldC5pby9I9xNQ4QFYsRJwAXgAkAEBmAHxAaABgBCqAQYyLjE1LjG4AQPIAQD4AQHiAwQYASBBiAYB&sclient=gws-wiz-serp)

- Networked audio/video streaming
  - [Streaming google search on maker.wiznet.io](https://www.google.com/search?q=streaming+site%3Amaker.wiznet.io%2F&newwindow=1&client=firefox-b-d&sca_esv=562459021&sxsrf=AB5stBj0R9cwWnRFim2-_nca5R7t_oIqjw%3A1693811733905&ei=FYT1ZMv1No3r1e8P2cWSmAg&ved=0ahUKEwiL1Ny1tJCBAxWNdfUHHdmiBIMQ4dUDCA8&uact=5&oq=streaming+site%3Amaker.wiznet.io%2F&gs_lp=Egxnd3Mtd2l6LXNlcnAiH3N0cmVhbWluZyBzaXRlOm1ha2VyLndpem5ldC5pby9IsR1QgwVYkhtwAXgAkAEAmAGHAaABqweqAQM1LjS4AQPIAQD4AQHiAwQYASBBiAYB&sclient=gws-wiz-serp)

- Networked gaming and multimedia
  - [multimedia google search on mekr.wiznet.io](https://www.google.com/search?q=multimedia+site%3Amaker.wiznet.io%2F&newwindow=1&client=firefox-b-d&sca_esv=562459021&sxsrf=AB5stBiWWPFlw-50kVb6FrIeWlBkkbh0Aw%3A1693811795742&ei=U4T1ZPTuLOXK1e8Py421wA0&ved=0ahUKEwi05JrTtJCBAxVlZfUHHctGDdgQ4dUDCA8&uact=5&oq=multimedia+site%3Amaker.wiznet.io%2F&gs_lp=Egxnd3Mtd2l6LXNlcnAiIG11bHRpbWVkaWEgc2l0ZTptYWtlci53aXpuZXQuaW8vSKQaUOcYWOcYcAF4AJABAJgBYqABYqoBATG4AQPIAQD4AQHiAwQYASBBiAYB&sclient=gws-wiz-serp)

### W5500 with ATMEGA328P

**Steps to use W5500 with ATmega328P:**

1. **Hardware Setup:** Connect the W5500 to the ATmega328P using SPI pins and other necessary connections.

2. **Library Setup:** Download the WIZnet Ethernet library for Arduino.

3. **Code Implementation:**
  - Include necessary libraries.
  - Define network settings.
  - Initialize the Ethernet library.
  - Set up a TCP server and handle client connections.

I've refined the code using ChatGPT and introduced a few improvements:

1. **Function Modularization**: I'll break down the code into smaller functions to improve readability and maintainability.
2. **Consistent Commenting**: I'll ensure comments are clear and consistent throughout the code.

```cpp
#include <SPI.h>
#include <Ethernet.h>

// Network configuration constants
const byte MAC_ADDRESS[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
const IPAddress IP(192, 168, 0, 100);
const IPAddress GATEWAY(192, 168, 0, 1);
const IPAddress SUBNET(255, 255, 255, 0);
const uint16_t SERVER_PORT = 80;

EthernetServer server(SERVER_PORT);

void setup() {
  initializeSerial();
  initializeEthernet();
  startServer();
}

void loop() {
  handleClientConnections();
}

void initializeSerial() {
  Serial.begin(9600);
}

void initializeEthernet() {
  Ethernet.begin(MAC_ADDRESS, IP, GATEWAY, SUBNET);
}

void startServer() {
  server.begin();
  Serial.print("Server started at IP: ");
  Serial.println(Ethernet.localIP());
}

void handleClientConnections() {
  EthernetClient client = server.available();

  if (client) {
    Serial.println("New client connected");
    processClientData(client);
    client.stop();
    Serial.println("Client disconnected");
  }
}

void processClientData(EthernetClient& client) {
  while (client.connected()) {
    if (client.available()) {
      char c = client.read();
      Serial.print(c);
    }
  }
}
```

### W5500 with Raspberry Pi Pico

**Steps to use W5500 with Raspberry Pi Pico:**

1. **Hardware Setup:** Connect the W5500 to the Raspberry Pi Pico using SPI pins and other necessary connections.

2. **MicroPython Setup:** Ensure MicroPython is installed on the Raspberry Pi Pico.

3. **Code Implementation:**
  - Copy the W5500 MicroPython driver to the Raspberry Pi Pico.
  - Create a new MicroPython script and implement the necessary code.

I've refined the code using ChatGPT and introduced a few improvements:

1. Utilized functions to enhance the code structure and increase reusability.
2. Managed network configurations within a single function.
3. Segregated client handling into a separate function.

```cpp
import machine
import w5500

def initialize_w5500():
    # SPI setup
    spi = machine.SPI(0)
    cs = machine.Pin(5, machine.Pin.OUT)
    
    # Initialize the W5500
    w5500.init(spi, cs)

def set_network_config(ip, subnet_mask, gateway, mac):
    w5500.set_ip(ip)
    w5500.set_subnet_mask(subnet_mask)
    w5500.set_gateway(gateway)
    w5500.set_mac(mac)

def handle_client(conn):
    try:
        while True:
            # Receive data from the client
            data = conn.recv(1024)
            if not data:
                break
            print("Received data:", data)
            # Send a response back to the client if needed
            # conn.send("Hello from Raspberry Pi Pico!")
    except Exception as e:
        print("Error:", e)
    finally:
        conn.close()
        print("Client disconnected.")

# Network configuration
ip = '192.168.0.100'
subnet_mask = '255.255.255.0'
gateway = '192.168.0.1'
mac = (0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED)

initialize_w5500()
set_network_config(ip, subnet_mask, gateway, mac)

# Create a TCP server socket
sock = w5500.socket(w5500.SOCK_STREAM)
sock.bind(80)
sock.listen()

print("Server is running.")

while True:
    # Wait for incoming connections
    conn, addr = sock.accept()
    print("New client connected from:", addr)
    handle_client(conn)
```

**Thank you for reading.**

---

Source: https://maker.wiznet.io/taylor/projects/w5500-tcp-ip-ethernet/
