---
title: "problem getting micropython loopback example working on PiPico and W5500"
url: "https://maker.wiznet.io/forum/14743"
markdown_url: "https://maker.wiznet.io/forum/14743/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "scottdky"
created: "2022-12-12T23:33:57+09:00"
last_activity: "2022-12-14T21:38:47+09:00"
language: "en"
views: 552
replies: 4
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# problem getting micropython loopback example working on PiPico and W5500

## Question

Asked by scottdky on 2022-12-12 in Ethernet Chips.

I am trying to get the loopback example to work on the PiPico (RP2040) with W550 chip using micropython. I am able to setup an nic, and can ping the board. The problem starts when calling the accept() function of a socket. When calling accept(), the script hangs. I am using this version of the micropython firmware: `rp2_w5500_20221111_v2.0.0.uf2`. Any suggestions on what is wrong?

Here is my code:

```
import socket
from machine import Pin,SPI
import network
import rp2
import time
from sys import stdin, stdout

def w5x00_init():
    spi=SPI(0,2_000_000, mosi=Pin(19),miso=Pin(16),sck=Pin(18))
    nic = network.WIZNET5K(spi,Pin(17),Pin(20)) #spi,cs,reset pin
    nic.active(True)
    nic.ifconfig(('192.168.5.120','255.255.255.0','192.168.5.1','8.8.8.8'))
    startTs = time.time()
    while not nic.isconnected():
        time.sleep(1)
        if time.time() - startTs > 5:
            break
    return nic if nic.isconnected() else False

def main():
    nic = w5x00_init()
    if not nic:
        print('Problem connecting to network')
        return
    else:
        ip = nic.ifconfig()[0]
        print('IP address: ', ip)

    s = socket.socket() #socket.AF_INET, socket.SOCK_STREAM
    s.bind((ip, 5000))
    s.listen(5)
    conn, addr = s.accept() # hangs on this line
    print("Connect to:", conn, "address:", addr) 
    print("Loopback server Open!")
    
    while True:
        data = conn.recv(2048)
        print(data.decode('utf-8'))
        if data != 'NULL':
            conn.send(data)

if __name__ == "__main__":
    main()
```

## Replies

### Reply 1 by Eugeny, 2022-12-13

I suspect

```
s = socket.socket()
```

must have some arguments, supplied, at least W5500 socket number to open socket interface for?

### Reply 2 by scottdky, 2022-12-14 (in reply to reply 1)

I tried it with:

`socket.AF_INET, socket.SOCK_STREAM`

with the same result. The example given by Wiznet does not have any arguments. What arguments should I try?

### Reply 3 by Eugeny, 2022-12-14

Can you provide link to the sources you refer to? Is there any documentation for the library/calls provided?

![](https://avatars.discourse-cdn.com/v4/letter/s/53a042/48.png) scottdky:

> What arguments should I try?

There must be at least indication of the W5500 socket number, W5500 is having 8 of them. In the code I see you set up common registers, I see you open socket, set it to listen on port 5000, but I do no see which W5500 socket you a configuring.

### Reply 4 by scottdky, 2022-12-14

FYI, the Wiznet example code is here - [RP2040-HAT-MicroPython/examples/Loopback at main · Wiznet/RP2040-HAT-MicroPython · GitHub](https://github.com/Wiznet/RP2040-HAT-MicroPython/tree/main/examples/Loopback)

But, I found the problem. In my ignorance, I didn’t understand what the socket.accept function did. After studying python (instead of micropython) documentation, I realized it was waiting for another computer to connect to it. When I did so, the function call returned as expected. I apologize for the newbie mistake.

Also FYI, according to python documentation, `s = socket.socket()` does default to `socket.AF_INET, socket.SOCK_STREAM`.

---

Source: https://maker.wiznet.io/forum/14743
