Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wiznet w550-evb-pico UDP server #3

Open
andrewmk opened this issue May 6, 2024 · 2 comments
Open

Wiznet w550-evb-pico UDP server #3

andrewmk opened this issue May 6, 2024 · 2 comments

Comments

@andrewmk
Copy link

andrewmk commented May 6, 2024

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())
@anecdata
Copy link
Owner

anecdata commented May 6, 2024

Thanks. I don't recall why I never got around to doing a WIZnet server, but I'll try to add an example for completeness. WIZnet socket examples should work like native wifi (once the custom setup is done).

@andrewmk
Copy link
Author

andrewmk commented May 6, 2024

I had great difficulty finding a working example of receiving UDP packets. Maybe it's because I wanted to use CircuitPython 9.04, or maybe it's that the Adafruit wiznet library seems to have changed recently, or both. Anyway in the end I picked apart the adafruit_ntp library and some other examples and got it working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants