Skip to content

RaspberryPi Pico Web Server w W5100S(W5500) – NeoPixel LED

In the RaspberryPi Pico SIMPLE web server RGB LED control project we will use an WIZnet W5100S, WIZ810Sio and we will create a small http we

WIZnet

Published February 17, 2023

Original author: Bongjun HurOriginal source (new tab)

RaspberryPi Pico Web Server w W5100S(W5500) – NeoPixel LED

Components

Software Apps and online services

x 1


Project description

DETAILS

 

1. Overview

In the RaspberryPi Pico SIMPLE web server RGB LED control project we will use an WIZnet W5100S, WIZ810Sio and we will create a small http web server on our Ethernet LAN which will control an RGB LED with an interactive web interface.

2. Prepare CircuitPython and network library

Before this, you should learn this project.

https://www.hackster.io/bjnhur/how-to-add-w5100s-ethernet-to-raspberry-pi-pico-iot-demo-fed492

3. Hardware connection

Refer to below connection.

3. Hardware connection
 

4. Get the code

This code is based on Adafruit wsgi test code. https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k/blob/main/examples/wiznet5k_wsgiserver_test.py

1. Copy and Paste all /lib directory into your RaspberryPi drive from https://github.com/bjnhur/pico-W5500

library copy
library copy
 

2. Copy the code from https://github.com/bjnhur/pico-W5500/blob/main/Pico_W5100S_wsgiserver_test.py or below code section

3. Paste code into code.py on your RaspberryPi.

4. Save it! Done

In the code, if you want to change endpoint url address or add your endpoint, you can modify the below code on simple webserver. just change “YOUR_ENDPOINT” and “YOUR_ENDPOINT_FUNC” string.

@web_app.route("YOURURL_ENDPOINT")
def YOURURL_ENDPOINT_FUNC(request):  # pylint: disable=unused-argument
    print("LED handler")
    return ("200 OK", [], ["hello endpoint"])

The example is: Get the <color> code value from url and change the Neopixel LED color.

@web_app.route("/led/<color>")
def led_on(request, color):  # pylint: disable=unused-argument
    print("LED handler")
    color_value = int(color, 16)
    pixels.fill(color_value)
    pixels.show()
    html_string_led = html_string.replace("#000000", "#"+color)
    return ("200 OK", [], [html_string_led])

If you change the page view, you just change the “html_string” variable on the code.

html_string = '''
<!DOCTYPE html>
<html lang="en">
<head>
...
<p>
<a href="/code">View code.py</a>
</p>
...
</body>
</html>
'''

5. Test

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() )

RaspberryPi Pico Web Server w W5100S(W5500) – NeoPixel LED, 5. Test
 

On your PC, open the browser (Recommend Chrome).

Type your board IP on the browser. I got “192.168.0.18” from my DHCP server.

Pico web server page
Pico web server page
 

Let’s change the LED color. click “Color Selector” color box, then you can see color picker as below. Select color as you want.

RGB color picker
RGB color picker
 

Then, click “Change Color” link.

change color
change color
 

See your LED~~~

Neopixel LED control via webpage
Neopixel LED control via webpage
 

6. Another functions

There are 2 more functions in simple webserver.

1. File read in RaspberryPi Pico USB drive.

Click “View code.py”, then you can see “code.py” in your RaspberryPi Pico board.

Read File in your Pico board
Read File in your Pico board
 

2. Getting JSON data from other web service.

Click “currentprice/USD.json” link, then you can see JSON data from http://api.coindesk.com/v1/bpi/currentprice/USD.json

Getting JSON data from other webserver
Getting JSON data from other webserver
 

Done. Enjoy the demo code~~~ 🙂

DOCUMENTS
Code
python6. Another functions
 
python
 
Schematics
RaspberryPi Pico + WIZ810Sio + Neopixel Strip

Comments

Similar projects you might like

Comments