---
title: "Raspberry Pi Pico IoT Demo – W5500 Ethernet + NeoPixel LED"
url: "https://maker.wiznet.io/WIZnet/projects/raspberry-pi-pico-iot-demo-%E2%80%93-w5500-ethernet-neopixel-led/"
markdown_url: "https://maker.wiznet.io/WIZnet/projects/raspberry-pi-pico-iot-demo-%E2%80%93-w5500-ethernet-neopixel-led/md"
type: "UCC: User Created Content"
author: "Bongjun Hur"
author_url: "https://www.hackster.io/bjnhur/raspberry-pi-pico-iot-demo-w5500-ethernet-neopixel-led-8bc31c"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "Bongjun Hur"
original_url: "https://www.hackster.io/bjnhur/raspberry-pi-pico-iot-demo-w5500-ethernet-neopixel-led-8bc31c"
published: "2023-02-09"
language: "en"
likes: 3
views: 336
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# Raspberry Pi Pico IoT Demo – W5500 Ethernet + NeoPixel LED

> HOWTO: Let's make a simple IoT RGB control project with Raspberry Pi Pico, WIZnet W5500, NeoPixel , WIZNET5K Adafruit lib on CircuitPython

Original author: Bongjun Hur (source: https://www.hackster.io/bjnhur/raspberry-pi-pico-iot-demo-w5500-ethernet-neopixel-led-8bc31c)

## Article

### **1. PreviewNo problem to skip this “Preview” Section, but it’s better to read** them for **using Ethernet on RP2040 Board.**

Need to install CircuitPython on Raspberry Pi Pico board. because we can use WIZNET5K, Adafruit NeoPixel library for Ethernet, RGB control. For more detail, I already upload 2 projects with Raspberry Pi Pico, WIZ850io (W5500), Circuit Python env., Hardware connection, Ping demo example. Please visit the below project first.

- [How to add W5500 Ethernet to Raspberry Pi Pico (Python) – 1](https://www.hackster.io/bjnhur/how-to-add-w5500-ethernet-to-raspberry-pi-pico-python-1-c7340c)

- [How to add W5500 Ethernet to Raspberry Pi Pico (Python) – 2](https://www.hackster.io/bjnhur/how-to-add-w5500-ethernet-to-raspberry-pi-pico-python-2-77c78c)

### **2. Simple Install CircuitPython on Raspberry Pi Pico Board**

Follow up below steps.

1. **Download the below uf2 file** link on your computer.

- my github repo – <https://github.com/bjnhur/pico-W5500/blob/main/adafruit-circuitpython-raspberry_pi_pico-en_US-6.2.0.uf2>

- OR original files from adafruit CircuitPython 6.2.0 – [adafruit-circuitpython-raspberry_pi_pico-en_US-6.2.0.uf2](https://downloads.circuitpython.org/bin/raspberry_pi_pico/en_US/adafruit-circuitpython-raspberry_pi_pico-en_US-6.2.0.uf2)

2.** Push and hold the BOOTSEL button** and plug your Pico into the USB port of your Raspberry Pi or other computer. Release the BOOTSEL button after your Pico is connected.

3. It will mount as a Mass Storage Device called **RPI-RP2**.

![RPI-RP2 mount](https://hackster.imgix.net/uploads/attachments/1286727/pic166_QU6MZJ3gL3.png?auto=compress%2Cformat&w=740&h=555&fit=max)

RPI-RP2 mount

4. Drag and drop the CircuitPython 6.2.0 UF2 file onto the RPI-RP2 volume. Your Pico will reboot. You are now running CircuitPython. If you see “CIRCUITPY” drive volume, you’re ready to enjoy CircuitPython on your Pico board as below pic.

![install Circuit python](https://hackster.imgix.net/uploads/attachments/1286729/image_7ScWvgFnti.png?auto=compress%2Cformat&w=740&h=555&fit=max)

install Circuit python

### **3. Install NeoPixel, W5500 Ethernet libraries**

Very Easy. you find “neopixel.mpy”, “adafruit_wiznet5K”, “adafruit_bus_device” and copy the file into lib folder on your Raspberry Pi Pico Board.

![copy CircuitPython lib into your RPi Pico board](https://hackster.imgix.net/uploads/attachments/1286725/pic165_8lqQjxD2K8.png?auto=compress%2Cformat&w=740&h=555&fit=max)

copy CircuitPython lib into your RPi Pico board

For your installation, I upload the files on my github repo. just download all the files and folders. and then copy them into your Raspberry Pi Pico board.

<https://github.com/bjnhur/pico-W5500/tree/main/lib>

For more detail information about this libraries, you visit Adafruit pages.

- [CircuitPython NeoPixel](https://learn.adafruit.com/circuitpython-essentials/circuitpython-neopixel)

- [Ethernet for CircuitPython with Wiznet5K](https://learn.adafruit.com/ethernet-for-circuitpython)

### **4. H/W Connection**

refer the below pic, fritzing file also uploaded in this project

![Raspberry Pi Pico + W850io + Neopixel strip](https://hackster.imgix.net/uploads/attachments/1286730/image_RtsnpabgTU.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Raspberry Pi Pico + W850io + Neopixel strip

### **5. Coding – Network RGB Control function**

Copy below “Pico_W5500_Neopixel.py” code into your code.py on Raspberry Pi Pico board.

or

- 1. Download the code from GitHub. – <https://github.com/bjnhur/pico-W5500/blob/main/Pico_W5500_Neopixel_Demo.py>

- 2. Rename filename “code.py”

- 3. Then, copy it into your board volume(“CIRCUITPY”).

Let’s see the main code about Neopixel, Ethernet socket functions:

1. import neopixel lib, and assign Pin number.

```plaintext
import neopixel

pixel_pin = board.GP3
num_pixels = 2
```

2. init the neopixel lib.

```plaintext
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.1, auto_write=False)
```

3. TCP socket listen & accept

```plaintext
# Initialize a socket for our server
socket.set_interface(eth)
server = socket.socket()  # Allocate socket for the server
server_ip = None # IP address of server
server_port = 50007 # Port to listen on
server.bind((server_ip, server_port))  # Bind to IP and Port
server.listen()  # Begin listening for incoming clients
print("server listen")
conn = None
while True:
if conn is None:
    conn, addr = server.accept()  # Wait for a connection from a client.
    print("socket connected")
    print(conn, addr)
```

4. After TCP connection, change the RGB Color from PC data

```plaintext
if conn is None:
    // accept
else :
    if conn.status in (
        SNSR_SOCK_FIN_WAIT,
        SNSR_SOCK_CLOSE_WAIT,
    ):
        print("socket closed")
        conn.close()
        conn = None
    else :
        # print("socket established", conn.status)
        data = conn.recv()
        if data:
            print(data)
            conn.send(data)  # Echo message back to client
            recvStr = data.decode('UTF-8')
            print(recvStr) # expected data format 255,0,0 - (R,G,B)
            color = recvStr.split(",", 2) # split
            print(color)
            if len(color) != 3 or not "".join(color).isdigit():
                pass
            red = int(color[0]) 
            green = int(color[1])
            blue = int(color[2])

            pixels.fill((red,green,blue))
            pixels.show()
```

### **6. Test Result**

you need simple socket test program like “Hercules”. for more detail about this tool please visit the following site. Very useful socket test tool, UART terminal, Freeware!

- <https://www.hw-group.com/software/hercules-setup-utility>

If the code is ok, you can see the below log from REPL of Pico board. (For REPL open, please refer this page [“How to add W5500 Ethernet to Raspberry Pi Pico (Python) – 1” – 6. REPL, Open serial terminal for printf()](https://www.hackster.io/bjnhur/how-to-add-w5500-ethernet-to-raspberry-pi-pico-python-1-c7340c#toc-6--repl--open-serial-terminal-for-printf--5) )

![code.py running log DHCP, Server listen](https://hackster.imgix.net/uploads/attachments/1286743/image_kShkM92ESB.png?auto=compress%2Cformat&w=740&h=555&fit=max)

code.py running log DHCP, Server listen

I try to connect the board as below, and connection is ok.

![connected to Raspberry Pi Pico board](https://hackster.imgix.net/uploads/attachments/1286744/image_awTUOjZUlv.png?auto=compress%2Cformat&w=740&h=555&fit=max)

connected to Raspberry Pi Pico board

REPL window,

![socket is connected](https://hackster.imgix.net/uploads/attachments/1286745/image_DWD48F9jlE.png?auto=compress%2Cformat&w=740&h=555&fit=max)

socket is connected

I sent the message (RGB code) as below:

255, 0, 0 &lt;– RED

![RED code send](https://hackster.imgix.net/uploads/attachments/1286746/image_sxCyTO4A9p.png?auto=compress%2Cformat&w=740&h=555&fit=max)

RED code send

Board echo the data “255, 0, 0” (3 in pic) and see the RED LED.

![RED On](https://hackster.imgix.net/uploads/attachments/1286747/image_hhjuWN5blv.png?auto=compress%2Cformat&w=740&h=555&fit=max)

RED On

In REPL window,

![Get data from PC](https://hackster.imgix.net/uploads/attachments/1286748/image_VBrB3i2tNw.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Get data from PC

Let’s try to change Green, “0, 255, 0”

![Green On](https://hackster.imgix.net/uploads/attachments/1286762/image_ZX7u2hf6P5.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Green On

Done. Enjoy my demo code~~~

---

Source: https://maker.wiznet.io/WIZnet/projects/raspberry-pi-pico-iot-demo-%E2%80%93-w5500-ethernet-neopixel-led/
