Skip to content

Commit 64f2cb5

Browse files
committed
ethernet breakout examples
adding circuitpython and arduino examples for the wiz5500 ethernet breakout
1 parent 1be135c commit 64f2cb5

File tree

3 files changed

+176
-0
lines changed

3 files changed

+176
-0
lines changed

Wiz5500_Ethernet_Breakout/Arduino_Wiz5500_Breakout/.uno.test.only

Whitespace-only changes.
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
/*
6+
Web client
7+
8+
This sketch connects to a website (http://wifitest.adafruit.com)
9+
using an Adafruit Wiz5500 Ethernet Breakout
10+
11+
Circuit:
12+
* Ethernet breakout attached to pins 10, 11, 12, 13
13+
14+
created 18 Dec 2009
15+
by David A. Mellis
16+
modified 9 Apr 2012
17+
by Tom Igoe, based on work by Adrian McEwen
18+
modified 10 June 2025
19+
by Liz Clark
20+
21+
*/
22+
23+
#include <SPI.h>
24+
#include <Ethernet.h>
25+
26+
// Enter a MAC address for your controller below.
27+
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
28+
29+
char server[] = "wifitest.adafruit.com";
30+
31+
// Set the static IP address to use if the DHCP fails to assign
32+
IPAddress ip(192, 168, 0, 177);
33+
IPAddress myDns(192, 168, 0, 1);
34+
35+
// Initialize the Ethernet client library
36+
// with the IP address and port of the server
37+
// that you want to connect to (port 80 is default for HTTP):
38+
EthernetClient client;
39+
40+
// Variables to measure the speed
41+
unsigned long beginMicros, endMicros;
42+
unsigned long byteCount = 0;
43+
bool printWebData = true; // set to false for better speed measurement
44+
45+
void setup() {
46+
// You can use Ethernet.init(pin) to configure the CS pin
47+
// Here you're using pin 10 for CS
48+
// SCK: 13, MISO: 12, MOSI: 11
49+
Ethernet.init(10); // Most Arduino shields
50+
51+
// Open serial communications and wait for port to open:
52+
Serial.begin(115200);
53+
while (!Serial) {
54+
; // wait for serial port to connect. Needed for native USB port only
55+
}
56+
57+
// start the Ethernet connection:
58+
Serial.println("Initialize Ethernet with DHCP:");
59+
if (Ethernet.begin(mac) == 0) {
60+
Serial.println("Failed to configure Ethernet using DHCP");
61+
// Check for Ethernet hardware present
62+
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
63+
Serial.println("Ethernet breakout was not found. Check your wiring.");
64+
while (true) {
65+
delay(1); // do nothing, no point running without Ethernet hardware
66+
}
67+
}
68+
if (Ethernet.linkStatus() == LinkOFF) {
69+
Serial.println("Ethernet cable is not connected.");
70+
}
71+
// try to configure using IP address instead of DHCP:
72+
Ethernet.begin(mac, ip, myDns);
73+
} else {
74+
Serial.print(" DHCP assigned IP ");
75+
Serial.println(Ethernet.localIP());
76+
}
77+
// give the Ethernet a second to initialize:
78+
delay(1000);
79+
Serial.print("connecting to ");
80+
Serial.print(server);
81+
Serial.println("...");
82+
83+
// if you get a connection, report back via serial:
84+
if (client.connect(server, 80)) {
85+
Serial.print("connected to ");
86+
Serial.println(client.remoteIP());
87+
// Make a HTTP request:
88+
client.println("GET /testwifi/index.html HTTP/1.1");
89+
client.println("Host: wifitest.adafruit.com");
90+
client.println("Connection: close");
91+
client.println();
92+
} else {
93+
// if you didn't get a connection to the server:
94+
Serial.println("connection failed");
95+
}
96+
beginMicros = micros();
97+
}
98+
99+
void loop() {
100+
// if there are incoming bytes available
101+
// from the server, read them and print them:
102+
int len = client.available();
103+
if (len > 0) {
104+
byte buffer[80];
105+
if (len > 80) len = 80;
106+
client.read(buffer, len);
107+
if (printWebData) {
108+
Serial.write(buffer, len); // show in the serial monitor (slows some boards)
109+
}
110+
byteCount = byteCount + len;
111+
}
112+
113+
// if the server's disconnected, stop the client:
114+
if (!client.connected()) {
115+
endMicros = micros();
116+
Serial.println();
117+
Serial.println("disconnecting.");
118+
client.stop();
119+
Serial.print("Received ");
120+
Serial.print(byteCount);
121+
Serial.print(" bytes in ");
122+
float seconds = (float)(endMicros - beginMicros) / 1000000.0;
123+
Serial.print(seconds, 4);
124+
float rate = (float)byteCount / seconds / 1000.0;
125+
Serial.print(", rate = ");
126+
Serial.print(rate);
127+
Serial.print(" kbytes/second");
128+
Serial.println();
129+
130+
// do nothing forevermore:
131+
while (true) {
132+
delay(1);
133+
}
134+
}
135+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
import adafruit_connection_manager
5+
import adafruit_requests
6+
import board
7+
import busio
8+
import digitalio
9+
10+
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
11+
12+
print("Wiz5100 Breakout WebClient Test")
13+
14+
TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
15+
16+
cs = digitalio.DigitalInOut(board.D10)
17+
spi_bus = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
18+
19+
# Initialize ethernet interface with DHCP
20+
eth = WIZNET5K(spi_bus, cs)
21+
22+
# Initialize a requests session
23+
pool = adafruit_connection_manager.get_radio_socketpool(eth)
24+
ssl_context = adafruit_connection_manager.get_radio_ssl_context(eth)
25+
requests = adafruit_requests.Session(pool, ssl_context)
26+
27+
print("Chip Version:", eth.chip)
28+
print("MAC Address:", [hex(i) for i in eth.mac_address])
29+
print("My IP address is:", eth.pretty_ip(eth.ip_address))
30+
print("IP lookup adafruit.com: %s" % eth.pretty_ip(eth.get_host_by_name("adafruit.com")))
31+
32+
33+
# eth._debug = True
34+
print("Fetching text from", TEXT_URL)
35+
r = requests.get(TEXT_URL)
36+
print("-" * 40)
37+
print(r.text)
38+
print("-" * 40)
39+
r.close()
40+
41+
print("Done!")

0 commit comments

Comments
 (0)