Skip to content

Instantly share code, notes, and snippets.

@anecdata
Last active March 2, 2022 00:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anecdata/3c6f37c05a91f7b769dad7517bfe3aa1 to your computer and use it in GitHub Desktop.
Save anecdata/3c6f37c05a91f7b769dad7517bfe3aa1 to your computer and use it in GitHub Desktop.
Test code for WIZnet W5100S-EVB-Pico
import board
import busio
import digitalio
import time
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket
import adafruit_requests as requests
SPI0_SCK = board.GP18
SPI0_TX = board.GP19
SPI0_RX = board.GP16
SPI0_CSn = board.GP17
W5x00_RSTn = board.GP20
MAC_ADDR = (0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED)
TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
def eth_hard_reset(eth_rst, wait):
eth_rst.value = False
time.sleep(wait)
eth_rst.value = True
def eth_soft_reset(eth):
eth.sw_reset()
led = digitalio.DigitalInOut(board.GP25)
led.direction = digitalio.Direction.OUTPUT
eth_rst = digitalio.DigitalInOut(W5x00_RSTn)
eth_rst.direction = digitalio.Direction.OUTPUT
print("Hard reset...")
eth_hard_reset(eth_rst, 1)
print("Init...")
spi = busio.SPI(SPI0_SCK, MOSI=SPI0_TX, MISO=SPI0_RX)
eth_cs = digitalio.DigitalInOut(SPI0_CSn)
eth = WIZNET5K(spi, eth_cs, reset=eth_rst, is_dhcp=True, mac=MAC_ADDR, hostname="W5100S", dhcp_timeout=30, debug=False)
# eth._debug = True
requests.set_socket(socket, eth)
print("Chip Version:", eth.chip)
print("MAC Address:", ":".join("%02X" % _ for _ in eth.mac_address))
print("IP Address:", eth.pretty_ip(eth.ip_address))
print("ifconfig...")
print("IP Address: ", eth.pretty_ip(eth.ifconfig[0]))
print("Subnet Mask:", eth.pretty_ip(eth.ifconfig[1]))
print("Gateway: ", eth.pretty_ip(eth.ifconfig[2]))
print("DNS Server:", eth.ifconfig[3])
while True:
led.value = not led.value
print("Link Status:", eth.link_status)
eth.maintain_dhcp_lease()
print("Fetching text from", TEXT_URL)
with requests.get(TEXT_URL, headers={"User-Agent": "Call My Agent"}) as r:
print(r.status_code, r.reason, r.headers)
print(r.text)
time.sleep(60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment