(1) – Temperature measurement data transfer W5500 Ethernet Shield (Raspberry Pi Pico) – Server(Python)

Temperature measurement data transfer W5500 Ethernet Shield (Raspberry Pi Pico) - Server(Python)
ORIGINAL POST
By Louis_m
components
Hardware Components
WIZnet W5500 Ethernet Shield
X 1
Pico Shield
details

pico_w5500+wizfi360.png

The W5500 chip is a Hardwired TCP/IP embedded Ethernet controller that enables easier internet connection for embedded systems using SPI (Serial Peripheral Interface)

img

 

Instructions

imgimg

W5500_TCP_Server

Circuit Python Installation

img

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

  • Drag and drop the CircuitPython 6.2.0 .uf2 file onto the RPi-RP2 volume. Your Pico will reboot. You are now running CircuitPython.

  • Then, you can see “CIRCUITPY” drive on your system.

  • Now, We’re ready to enjoy the code on python code.py with CircuitPython.

img

 

W5500 Ethernet Shield pin map

img

  • Use SPI0 on Raspberry Pi Pico.

  • Be aware of the direction and insert it carefully. If you look at the Ethernet shield, there is a mark indicating the shape of the USB. The USB direction of the Raspberry Pi Pico should be the same.

 

img

img

 

W5500 adafruit_wiznet5k python library

We need to prepare some libraries from the Adafruit learning page before ping test.

https://learn.adafruit.com/ethernet-for-circuitpython/circuitpython-setup

Make sure your board’s lib folder contains the following files and folders copied:

adafruit_wiznet5k
adafruit_bus_device
adafruit_requests.mpy

img

 

REPL, Open serial terminal for printf()

Now, let’s open the PuTTY terminal.
Under Connection type: choose the button next to Serial.
In the box under Serial line, enter the serial port you found that your board is using.
In the box under Speed, enter 115200.

img

Once settings are entered, you’re ready to connect to the serial console.

Click “Open” at the bottom of the window. A new window will open.

 

  • Check the COM port in Device Manager

img

 

W5500 Ethernet connect

This is the code to set the IP of 192.168.1.100

I hope that the PC also has an environment that communicates with 192.168.1.xxx.

W5500_Ethernet_Shield_Server.py


import board
import busio
import digitalio
import time
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket

SPI0_SCK = board.GP2
SPI0_TX = board.GP3
SPI0_RX = board.GP4
SPI0_CSn = board.GP5
W5500_RSTn = board.GP20

print(“Wiznet5k Ping Test (DHCP)”)

# Setup your network configuration below
# random MAC, later should change this value on your vendor ID
MY_MAC = (0x00, 0x01, 0x02, 0x03, 0x04, 0x05)
IP_ADDRESS = (192, 168, 1, 100)
SUBNET_MASK = (255, 255, 255, 0)
GATEWAY_ADDRESS = (192, 168, 1, 1)
DNS_SERVER = (8, 8, 8, 8)

led = digitalio.DigitalInOut(board.GP25)
led.direction = digitalio.Direction.OUTPUT

ethernetRst = digitalio.DigitalInOut(W5500_RSTn)
ethernetRst.direction = digitalio.Direction.OUTPUT

# For Adafruit Ethernet FeatherWing
cs = digitalio.DigitalInOut(SPI0_CSn)
# For Particle Ethernet FeatherWing
# cs = digitalio.DigitalInOut(board.D5)
spi_bus = busio.SPI(SPI0_SCK, MOSI=SPI0_TX, MISO=SPI0_RX)

# Reset W5500 first
ethernetRst.value = False
time.sleep(1)
ethernetRst.value = True

# Initialize ethernet interface with DHCP
# eth = WIZNET5K(spi_bus, cs)
# Initialize ethernet interface without DHCP
eth = WIZNET5K(spi_bus, cs, is_dhcp=True, mac=MY_MAC)

# Set network configuration
eth.ifconfig = (IP_ADDRESS, SUBNET_MASK, GATEWAY_ADDRESS, DNS_SERVER)

print(“Chip Version:”, eth.chip)
print(“MAC Address:”, [hex(i) for i in eth.mac_address])
print(“My IP address is:”, eth.pretty_ip(eth.ip_address))

# 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 = 5000 # Port to listen on
server.bind((server_ip, server_port)) # Bind to IP and Port
server.listen() # Begin listening for incoming clients

conn, addr = server.accept() # Wait for a connection from a client.
print(“socket connected”)

while True:
led.value = not led.value
time.sleep(1)
with conn:
# data = conn.recv()
# print(data)
# conn.send(data) # Echo message back to client
while True:
data = conn.recv(10)
if data:
print(‘received’, data)
conn.send(data) # Echo message back to client
#break

print(“Done!”)
server.socket.close()


Copy the content to code.py on your RPi Pico and save.

img

Server is ready...

pico_w5500+wizfi360.png

The W5500 chip is a Hardwired TCP/IP embedded Ethernet controller that enables easier internet connection for embedded systems using SPI (Serial Peripheral Interface)

img

 

Instructions

imgimg

W5500_TCP_Server

Circuit Python Installation

img

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

  • Drag and drop the CircuitPython 6.2.0 .uf2 file onto the RPi-RP2 volume. Your Pico will reboot. You are now running CircuitPython.

  • Then, you can see “CIRCUITPY” drive on your system.

  • Now, We’re ready to enjoy the code on python code.py with CircuitPython.

img

 

W5500 Ethernet Shield pin map

img

  • Use SPI0 on Raspberry Pi Pico.

  • Be aware of the direction and insert it carefully. If you look at the Ethernet shield, there is a mark indicating the shape of the USB. The USB direction of the Raspberry Pi Pico should be the same.

 

img

img

 

W5500 adafruit_wiznet5k python library

We need to prepare some libraries from the Adafruit learning page before ping test.

https://learn.adafruit.com/ethernet-for-circuitpython/circuitpython-setup

Make sure your board’s lib folder contains the following files and folders copied:

adafruit_wiznet5k
adafruit_bus_device
adafruit_requests.mpy

img

 

REPL, Open serial terminal for printf()

Now, let’s open the PuTTY terminal.
Under Connection type: choose the button next to Serial.
In the box under Serial line, enter the serial port you found that your board is using.
In the box under Speed, enter 115200.

img

Once settings are entered, you’re ready to connect to the serial console.

Click “Open” at the bottom of the window. A new window will open.

 

  • Check the COM port in Device Manager

img

 

W5500 Ethernet connect

This is the code to set the IP of 192.168.1.100

I hope that the PC also has an environment that communicates with 192.168.1.xxx.

W5500_Ethernet_Shield_Server.py


import board
import busio
import digitalio
import time
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket

SPI0_SCK = board.GP2
SPI0_TX = board.GP3
SPI0_RX = board.GP4
SPI0_CSn = board.GP5
W5500_RSTn = board.GP20

print(“Wiznet5k Ping Test (DHCP)”)

# Setup your network configuration below
# random MAC, later should change this value on your vendor ID
MY_MAC = (0x00, 0x01, 0x02, 0x03, 0x04, 0x05)
IP_ADDRESS = (192, 168, 1, 100)
SUBNET_MASK = (255, 255, 255, 0)
GATEWAY_ADDRESS = (192, 168, 1, 1)
DNS_SERVER = (8, 8, 8, 8)

led = digitalio.DigitalInOut(board.GP25)
led.direction = digitalio.Direction.OUTPUT

ethernetRst = digitalio.DigitalInOut(W5500_RSTn)
ethernetRst.direction = digitalio.Direction.OUTPUT

# For Adafruit Ethernet FeatherWing
cs = digitalio.DigitalInOut(SPI0_CSn)
# For Particle Ethernet FeatherWing
# cs = digitalio.DigitalInOut(board.D5)
spi_bus = busio.SPI(SPI0_SCK, MOSI=SPI0_TX, MISO=SPI0_RX)

# Reset W5500 first
ethernetRst.value = False
time.sleep(1)
ethernetRst.value = True

# Initialize ethernet interface with DHCP
# eth = WIZNET5K(spi_bus, cs)
# Initialize ethernet interface without DHCP
eth = WIZNET5K(spi_bus, cs, is_dhcp=True, mac=MY_MAC)

# Set network configuration
eth.ifconfig = (IP_ADDRESS, SUBNET_MASK, GATEWAY_ADDRESS, DNS_SERVER)

print(“Chip Version:”, eth.chip)
print(“MAC Address:”, [hex(i) for i in eth.mac_address])
print(“My IP address is:”, eth.pretty_ip(eth.ip_address))

# 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 = 5000 # Port to listen on
server.bind((server_ip, server_port)) # Bind to IP and Port
server.listen() # Begin listening for incoming clients

conn, addr = server.accept() # Wait for a connection from a client.
print(“socket connected”)

while True:
led.value = not led.value
time.sleep(1)
with conn:
# data = conn.recv()
# print(data)
# conn.send(data) # Echo message back to client
while True:
data = conn.recv(10)
if data:
print(‘received’, data)
conn.send(data) # Echo message back to client
#break

print(“Done!”)
server.socket.close()


Copy the content to code.py on your RPi Pico and save.

img

Server is ready...

documents
Code
W5500_Ethernet_Shield_Server.py

COMMENTS

Please Login to comment
  Subscribe  
Notify of
POSTED BY
Reusable S/W