W55RP20-S2E Loopback Micropython example (TCP/UDP)
This example demonstrates data loopback on W55RP20 S2E via UART/SPI using MicroPython on a Raspberry Pi Pico (Master)
How to Data Loopback Example (MicroPython)
This program demonstrates data loopback applications using the W55RP20 S2E board via UART or SPI interface. The Raspberry Pi Pico (Host) configures the W55RP20 S2E as a TCP Client, TCP Server, or UDP node using AT commands, and then enters Data Mode to echo back any data received from the PC.
Step 1: Prepare software
The following software is required to run and test the MicroPython example.
- Thonny : An integrated development environment for MicroPython. used to write, upload, and run code.
- Hercules : A serial terminal tool capable of TCP/UDP socket testing. (Required to act as the peer for loopback tests).
Step 2: Prepare hardware
1. Connect GPIO13 according to the selected UART/SPI mode of the W55RP20 EVB Pico, as illustrated below.
| GPIO13 Pin | Desc |
| LOW(GND) | UART mode (default) |
| HIGH(3.3V) | SPI mode |
2. Connect the Raspberry Pi Pico and the W55RP20 EVB Pico using jumper wires as shown below, depending on the selected UART/SPI mode.
- Important Note on Mode Switching: In this example setup, GPIO 13 of the W55RP20 EVB Pico is physically connected to GPIO 13 of the Raspberry Pi Pico. The Host Pico sets the mode (High/Low) automatically based on the software configuration.
- If you change the
MODEin the code (e.g., UART ↔ SPI): You MUST reset both boards (Raspberry Pi Pico and W55RP20 EVB Pico) to ensure the mode is switched and recognized correctly.
If UART mode :
| Raspberry Pi Pico | W55RP20 EVB Pico |
| GPIO4 (UART_TX) | GPIO5 (UART_RX) |
| GPIO5 (UART_RX) | GPIO4 (UART_TX) |
| GPIO13 (MODE_SEL) | GPIO13 (MODE_SEL) |
| GND | GND |
If SPI mode :
| Raspberry Pi Pico(Master) | W55RP20 EVB Pico(Slave) |
| GPIO2 (SPI_CLK) | GPIO2 (SPI_CLK) |
| GPIO3 (SPI_TX) | GPIO4 (SPI_RX) |
| GPIO4 (SPI_RX) | GPIO3 (SPI_TX) |
| GPIO5 (SPI_CS) | GPIO5 (SPI_CS) |
| GPIO26 (SPI_INT) | GPIO26 (SPI_INT) |
| GPIO13 (MODE_SEL) | GPIO13 (MODE_SEL) |
| GND | GND |
3. Connect the Raspberry Pi Pico to your PC (desktop or laptop) using a 5-pin Micro USB cable.
4. Connect the W55RP20 EVB Pico to your PC (desktop or laptop) using a USB Type-C cable.
Step 3: Setup Example
- Raspberry Pi Pico (Master) : Getting started with Raspberry Pi Pico (MicroPython)
Please refer to the link below to install the MicroPython firmware on the Raspberry Pi Pico.
- W55RP20 EVB Pico : Getting started with W55RP20 EVB Pico
Please refer to the link below for instructions on how to use the W55RP20 S2E.
Step 4: Upload Code
- Raspberry Pi Pico
Open Thonny IDE and connect to the Raspberry Pi Pico. Upload the following driver and example files to the Pico's storage.
Required Files:
w55rp20_s2e_uart.py(Required for UART mode)w55rp20_s2e_spi.py(Required for SPI mode)
Example Application Files (Choose one to test):
02_tcp_client_loopback.py03_tcp_server_loopback.py04_udp_loopback.py
Configuration: Before running an example, open the Python file you intend to use and modify the User Configuration section at the top.
# Example: 02_tcp_client_loopback.py
MODE = "uart" # Set to "spi" or "uart"
# IP Configuration Mode
USE_DHCP = True # True: DHCP (IM=1), False: Static IP (IM=0)
REMOTE_IP = "192.168.11.2" # Must match your PC's IP address
REMOTE_PORT = "5000" # Port to connect to
.
.- W55RP20 EVB Pico
Following Step 3 in the Getting Started Guide, program the W55RP20 EVB Pico with the UF2 file and write the MAC address to complete the setup.
Step 5: Run
Select the example file you want to test and follow the instructions below.
Run the example script in Thonny (press F5).
Step 5.1: Run TCP Client Loopback
In this mode, the W55RP20 S2E connects to a TCP Server (Hercules) running on your PC.
PC (Hercules)
- Open Hercules and select the TCP Server tab.
- Port: Enter
5000(or the port defined in your Python code). - Click Listen.
Pico (Thonny)
- Open
02_tcp_client_loopback.py. - Update
REMOTE_IPto your PC's IP address. - Run the script (F5).
# NOTE: Connection status check via 'ST' command is only available in SPI mode.
Test
- Hercules will show "Client connected".
- Type a message in Hercules and click Send.
- Verify that the message is echoed back in the Hercules receive window.
Step 5.2: Run TCP Server Loopback
In this mode, the W55RP20 S2E waits for a TCP Client (Hercules) to connect.
Pico (Thonny)
- Open
03_tcp_server_loopback.py. - Run the script (F5).
- Wait for the log to display
Server IP Assigned: 192.168.x.x.
PC (Hercules)
- Open Hercules and select the TCP Client tab.
- Module IP: Enter the IP address displayed in the Thonny log.
- Port:
5000. - Click Connect.
Test
- Once connected, type a message in Hercules and click Send.
- Verify that the message is echoed back.
Step 5.3: Run UDP Loopback
In this mode, data is exchanged via UDP packets without a connection process.
Pico (Thonny)
- Open
04_udp_loopback.py. - Update
REMOTE_IPto your PC's IP address. - Run the script (F5).
- Wait for the log to display
Server IP Assigned: ....
PC (Hercules)
- Open Hercules and select the UDP tab.
- Module IP: Enter the IP address displayed in the Thonny log.
- Port:
5000. - Local Port:
5000. - Click Listen.
Test
- Type a message in Hercules and click Send.
- Verify that the message is echoed back.
- (Note: In UART mode, the response may be buffered and sent in 10ms intervals due to the Packet Time setting.)

