Skip to content

Instantly share code, notes, and snippets.

@anecdata
Last active March 29, 2024 00:19
Show Gist options
  • Save anecdata/8152eba03eefd0a587747e551c683543 to your computer and use it in GitHub Desktop.
Save anecdata/8152eba03eefd0a587747e551c683543 to your computer and use it in GitHub Desktop.
CircuitPython with 4 Networks: W5100S + W5500 + ESP32-S2 + ESP32SPI
import board
from digitalio import DigitalInOut, Direction
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
import adafruit_wiznet5k.adafruit_wiznet5k_socket as wiznet5k_socket
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_esp32spi.adafruit_esp32spi_socket as esp_socket
import wifi
import socketpool
import ssl
import adafruit_requests
# local
from secrets import secrets
TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
spi = board.SPI()
#
# WIZNET5K - W5100S WIZnet Pico Hat via Keyboard FeatherWing
#
MAC_ADDR_5100S = (0xDE, 0xAD, 0xBE, 0xEF, 0x06, 246)
eth_5100S_rst = DigitalInOut(board.A3) # should be A2 ?
eth_5100S_rst.direction = Direction.OUTPUT
# eth_cs = digitalio.DigitalInOut(board.D10)
# Pico-side CS pin isn't connected to the FeatherWing side, so jumper is needed
eth_5100S_cs = DigitalInOut(board.D6)
eth_5100S = WIZNET5K(spi, eth_5100S_cs, reset=eth_5100S_rst, mac=MAC_ADDR_5100S)
print("W5100S IP Address:", eth_5100S.pretty_ip(eth_5100S.ip_address))
#
# WIZNET5K - W5500 FeatherWing
#
# eth_cs = digitalio.DigitalInOut(board.D10)
MAC_ADDR_5500 = (0xDE, 0xAD, 0xBE, 0xEF, 0x06, 247)
# customized CS pin b/c ESP32 needs GPIO0 available for reboots:
eth_5500_cs = DigitalInOut(board.A5)
eth_5500 = WIZNET5K(spi, eth_5500_cs, mac=MAC_ADDR_5500)
print("W5500 IP Address:", eth_5500.pretty_ip(eth_5500.ip_address))
#
# ESP32SPI Airlift FeatherWing
#
esp32_cs = DigitalInOut(board.D13) # LED on some Feathers
esp32_ready = DigitalInOut(board.D11)
esp32_reset = DigitalInOut(board.D12)
# esp32_gpio0 = DigitalInOut(board.D10) # optional
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
esp.connect_AP(secrets['ssid'], secrets['password'])
print("ESP32SPI IP Address:", esp.pretty_ip(esp.ip_address))
#
# Adafruit Feather ESP32-S2
#
wifi.radio.connect(secrets['ssid'], secrets['password'])
print("ESP32-S2 IP Address:", wifi.radio.ipv4_address)
print()
# Initialize a requests object with an ethernet socket and interface
adafruit_requests.set_socket(wiznet5k_socket, eth_5100S)
print("Fetching text via W5100S from", TEXT_URL)
with adafruit_requests.get(TEXT_URL) as r:
print(r.text)
# Initialize a requests object with an ethernet socket and interface
adafruit_requests.set_socket(wiznet5k_socket, eth_5500)
print("Fetching text via W5500 from", TEXT_URL)
with adafruit_requests.get(TEXT_URL) as r:
print(r.text)
# Initialize a requests object with an ESP32SPI wi-fi socket and interface
adafruit_requests.set_socket(esp_socket, esp)
print("Fetching text via ESP32SPI from", TEXT_URL)
with adafruit_requests.get(TEXT_URL) as r:
print(r.text)
# Initialize a requests object with an ESP32-S2 wi-fi socket and interface
pool = socketpool.SocketPool(wifi.radio)
requests = adafruit_requests.Session(pool, ssl.create_default_context())
print("Fetching text via ESP32-S2 from", TEXT_URL)
with requests.get(TEXT_URL) as r:
print(r.text)
print("Done!")
@anecdata
Copy link
Author

anecdata commented Dec 5, 2021

Follow-on to:
CircuitPython with 3 Networks: FeatherS2 + Airlift FeatherWing + Ethernet FeatherWing
https://gist.github.com/anecdata/cdf0d931d8b2dee21775d34d0df69879
and
Feather M4 + Airlift FeatherWing (ESP32SPI) + Ethernet FeatherWing (WIZNET5K)
https://gist.github.com/anecdata/cc4f091cb50fdb665bfe6586dd079999

@anecdata
Copy link
Author

Native wifi + WIZnet W5100S + W5500 + W6100:
https://gist.github.com/anecdata/c708dd9e5a0e0b582f01f27d24fc3aab

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