Skip to content

Wiznet w550-evb-pico UDP server #3

Description

@andrewmk

I managed to get a UDP server working on a Wiznet w5500-evb-pico board. Loaded up CircuitPython 9.0.4 from https://downloads.circuitpython.org/bin/wiznet_w5500_evb_pico/en_GB/adafruit-circuitpython-wiznet_w5500_evb_pico-en_GB-9.0.4.uf2 and the matching Adafruit adafruit_wiznet5k and adafruit_ticks libraries.

import board
import busio
import digitalio
import time

from adafruit_wiznet5k.adafruit_wiznet5k import *
import adafruit_wiznet5k.adafruit_wiznet5k_socketpool as socketpool

##SPI0
SPI0_SCK = board.GP18
SPI0_TX = board.GP19
SPI0_RX = board.GP16
SPI0_CSn = board.GP17

##reset
W5x00_RSTn = board.GP20

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

cs = digitalio.DigitalInOut(SPI0_CSn)
spi_bus = busio.SPI(SPI0_SCK, MOSI=SPI0_TX, MISO=SPI0_RX)

# Reset W5x00 first
print("Initialising...")
ethernetRst.value = False
time.sleep(1)
ethernetRst.value = True

MY_MAC = "00:01:02:03:04:05"
PORT = 5000
TIMEOUT = None
MAXBUF = 1024

# Initialize ethernet interface with DHCP
eth = WIZNET5K(spi_bus, cs, is_dhcp=True, mac=MY_MAC, debug=False)
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))

pool = socketpool.SocketPool(eth)
sock = pool.socket(pool.AF_INET, pool.SOCK_DGRAM)
sock.bind((eth.pretty_ip(eth.ip_address), PORT))
buffer = bytearray(MAXBUF)

while True:
    eth.maintain_dhcp_lease()
    size, addr = sock.recvfrom_into(buffer)
    print(buffer[:size].decode())

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions