Skip to content
This repository was archived by the owner on Jan 29, 2023. It is now read-only.

Commit 754935e

Browse files
authored
v1.4.1 to use Ethernet_Generic library, etc.
### Releases v1.4.1 1. Use new [Ethernet_Generic library](https://github.com/khoih-prog/Ethernet_Generic) as default for W5x00. 2. Add support to SPI1 for RP2040 using [arduino-pico core](https://github.com/earlephilhower/arduino-pico) 3. Rewrite all the examples to support new features 4. Update `Packages' Patches`
1 parent 9a9cf4a commit 754935e

File tree

23 files changed

+1411
-602
lines changed

23 files changed

+1411
-602
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
1515
Please ensure to specify the following:
1616

1717
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
18-
* `SAMD` Core Version (e.g. Arduino SAMD core v1.8.12, Adafruit SAMD core v1.7.7, Seeed Studio SAMD v1.8.2)
18+
* Board Core Version (e.g. Arduino SAMDUE core v1.6.12, ESP32 core v2.0.2, ESP8266 core v3.0.2, ArduinoCore-mbed v3.0.1, etc.)
1919
* Contextual information (e.g. what you were trying to achieve)
2020
* Simplest possible steps to reproduce
2121
* Anything that might be relevant in your opinion, such as:
@@ -27,9 +27,10 @@ Please ensure to specify the following:
2727

2828
```
2929
Arduino IDE version: 1.8.19
30-
Arduino SAMD Core Version 1.8.12
30+
RASPBERRY_PI_PICO board
31+
ArduinoCore-mbed v3.0.1
3132
OS: Ubuntu 20.04 LTS
32-
Linux xy-Inspiron-3593 5.4.0-96-generic #109-Ubuntu SMP Wed Jan 12 16:49:16 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
33+
Linux xy-Inspiron-3593 5.13.0-39-generic #44~20.04.1-Ubuntu SMP Thu Mar 24 16:43:35 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
3334
3435
Context:
3536
The board couldn't autoreconnect to Local Blynk Server after router power recycling.

README.md

Lines changed: 192 additions & 172 deletions
Large diffs are not rendered by default.

changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
## Table of Contents
1414

1515
* [Changelog](#changelog)
16+
* [Releases v1.4.1](#releases-v141)
1617
* [Releases v1.4.0](#releases-v140)
1718
* [Releases v1.3.1](#releases-v131)
1819
* [Releases v1.3.0](#releases-v130)
@@ -28,6 +29,13 @@
2829

2930
## Changelog
3031

32+
### Releases v1.4.1
33+
34+
1. Use new [Ethernet_Generic library](https://github.com/khoih-prog/Ethernet_Generic) as default for W5x00.
35+
2. Add support to SPI1 for RP2040 using [arduino-pico core](https://github.com/earlephilhower/arduino-pico)
36+
3. Rewrite all the examples to support new features
37+
4. Update `Packages' Patches`
38+
3139
### Releases v1.4.0
3240

3341
1. Fix `multiple-definitions` linker error.

examples/Ethernet/DiscoveringServices/DiscoveringServices.ino

Lines changed: 209 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -35,87 +35,244 @@ MDNS mdns(udp);
3535
void serviceFound(const char* type, MDNSServiceProtocol proto, const char* name, IPAddress ip,
3636
unsigned short port, const char* txtContent);
3737

38-
void setup()
38+
uint16_t macIndex;
39+
40+
void initEthernet()
3941
{
40-
Serial.begin(115200);
41-
while (!Serial);
42+
#if USE_ETHERNET_PORTENTA_H7
43+
MDNS_LOGWARN(F("======== USE_PORTENTA_H7_ETHERNET ========"));
44+
#elif USE_NATIVE_ETHERNET
45+
MDNS_LOGWARN(F("======== USE_NATIVE_ETHERNET ========"));
46+
#elif USE_ETHERNET_GENERIC
47+
MDNS_LOGWARN(F("=========== USE_ETHERNET_GENERIC ==========="));
48+
#elif USE_ETHERNET_ESP8266
49+
MDNS_LOGWARN(F("=========== USE_ETHERNET_ESP8266 ==========="));
50+
#elif USE_ETHERNET_ENC
51+
MDNS_LOGWARN(F("=========== USE_ETHERNET_ENC ==========="));
52+
#else
53+
MDNS_LOGWARN(F("========================="));
54+
#endif
4255

43-
Serial.print("\nStart DiscoveringServices on "); Serial.print(BOARD_NAME);
44-
Serial.print(" using "); Serial.println(SHIELD_TYPE);
45-
Serial.println(MDNS_GENERIC_VERSION);
56+
#if !(USE_NATIVE_ETHERNET || USE_ETHERNET_PORTENTA_H7)
57+
58+
#if (USING_SPI2)
59+
#if defined(CUR_PIN_MISO)
60+
MDNS_LOGWARN(F("Default SPI pinout:"));
61+
MDNS_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI);
62+
MDNS_LOGWARN1(F("MISO:"), CUR_PIN_MISO);
63+
MDNS_LOGWARN1(F("SCK:"), CUR_PIN_SCK);
64+
MDNS_LOGWARN1(F("SS:"), CUR_PIN_SS);
65+
MDNS_LOGWARN(F("========================="));
66+
#endif
67+
#else
68+
MDNS_LOGWARN(F("Default SPI pinout:"));
69+
MDNS_LOGWARN1(F("MOSI:"), MOSI);
70+
MDNS_LOGWARN1(F("MISO:"), MISO);
71+
MDNS_LOGWARN1(F("SCK:"), SCK);
72+
MDNS_LOGWARN1(F("SS:"), SS);
73+
MDNS_LOGWARN(F("========================="));
74+
#endif
75+
76+
#if defined(ESP8266)
77+
// For ESP8266, change for other boards if necessary
78+
#ifndef USE_THIS_SS_PIN
79+
#define USE_THIS_SS_PIN D2 // For ESP8266
80+
#endif
81+
82+
MDNS_LOGWARN1(F("ESP8266 setCsPin:"), USE_THIS_SS_PIN);
83+
84+
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
85+
// For ESP8266
86+
// Pin D0(GPIO16) D1(GPIO5) D2(GPIO4) D3(GPIO0) D4(GPIO2) D8
87+
// EthernetGeneric X X X X X 0
88+
// Ethernet_ESP8266 0 0 0 0 0 0
89+
// D2 is safe to used for Ethernet, Ethernet2, Ethernet3, EthernetLarge libs
90+
// Must use library patch for Ethernet, EthernetLarge libraries
91+
Ethernet.init (USE_THIS_SS_PIN);
92+
93+
#elif USE_CUSTOM_ETHERNET
94+
95+
// You have to add initialization for your Custom Ethernet here
96+
// This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough
97+
Ethernet.init(USE_THIS_SS_PIN);
98+
99+
#endif //( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
100+
101+
#elif defined(ESP32)
46102

47-
Serial.println(("========================="));
48-
Serial.println(("Default SPI pinout:"));
49-
Serial.print("MOSI:");
50-
Serial.println(MOSI);
51-
Serial.print("MISO:");
52-
Serial.println(MISO);
53-
Serial.print("SCK:");
54-
Serial.println(SCK);
55-
Serial.print("SS:");
56-
Serial.println(SS);
57-
Serial.println(("========================="));
103+
// You can use Ethernet.init(pin) to configure the CS pin
104+
//Ethernet.init(10); // Most Arduino shields
105+
//Ethernet.init(5); // MKR ETH shield
106+
//Ethernet.init(0); // Teensy 2.0
107+
//Ethernet.init(20); // Teensy++ 2.0
108+
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
109+
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
58110

111+
#ifndef USE_THIS_SS_PIN
112+
#define USE_THIS_SS_PIN 5 //22 // For ESP32
113+
#endif
114+
115+
MDNS_LOGWARN1(F("ESP32 setCsPin:"), USE_THIS_SS_PIN);
116+
117+
// For other boards, to change if necessary
118+
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
119+
// Must use library patch for Ethernet, EthernetLarge libraries
120+
// ESP32 => GPIO2,4,5,13,15,21,22 OK with Ethernet, Ethernet2, EthernetLarge
121+
// ESP32 => GPIO2,4,5,15,21,22 OK with Ethernet3
122+
123+
//Ethernet.setCsPin (USE_THIS_SS_PIN);
124+
Ethernet.init (USE_THIS_SS_PIN);
125+
126+
#elif USE_CUSTOM_ETHERNET
127+
128+
// You have to add initialization for your Custom Ethernet here
129+
// This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough
130+
Ethernet.init(USE_THIS_SS_PIN);
131+
132+
#endif //( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
133+
134+
#elif ETHERNET_USE_RPIPICO
135+
136+
pinMode(USE_THIS_SS_PIN, OUTPUT);
137+
digitalWrite(USE_THIS_SS_PIN, HIGH);
138+
139+
// ETHERNET_USE_RPIPICO, use default SS = 5 or 17
140+
#ifndef USE_THIS_SS_PIN
141+
#if defined(ARDUINO_ARCH_MBED)
142+
#define USE_THIS_SS_PIN 5 // For Arduino Mbed core
143+
#else
144+
#define USE_THIS_SS_PIN 17 // For E.Philhower core
145+
#endif
146+
#endif
147+
148+
MDNS_LOGWARN1(F("RPIPICO setCsPin:"), USE_THIS_SS_PIN);
149+
150+
// For other boards, to change if necessary
151+
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
152+
// Must use library patch for Ethernet, EthernetLarge libraries
153+
// For RPI Pico using Arduino Mbed RP2040 core
154+
// SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5
155+
// For RPI Pico using E. Philhower RP2040 core
156+
// SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17
157+
// Default pin 5/17 to SS/CS
158+
159+
//Ethernet.setCsPin (USE_THIS_SS_PIN);
160+
Ethernet.init (USE_THIS_SS_PIN);
161+
162+
#endif //( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
163+
164+
#else //defined(ESP8266)
59165
// unknown board, do nothing, use default SS = 10
60-
#ifndef USE_THIS_SS_PIN
61-
#define USE_THIS_SS_PIN 10 // For other boards
62-
#endif
166+
#ifndef USE_THIS_SS_PIN
167+
#define USE_THIS_SS_PIN 10 // For other boards
168+
#endif
63169

64-
MDNS_LOGERROR3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN);
170+
#if defined(BOARD_NAME)
171+
MDNS_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN);
172+
#else
173+
MDNS_LOGWARN1(F("Unknown board setCsPin:"), USE_THIS_SS_PIN);
174+
#endif
65175

66176
// For other boards, to change if necessary
67-
#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 )
177+
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET )
68178
// Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries
69179

70180
Ethernet.init (USE_THIS_SS_PIN);
71181

72-
#elif USE_ETHERNET3
73-
// Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer
74-
#ifndef ETHERNET3_MAX_SOCK_NUM
75-
#define ETHERNET3_MAX_SOCK_NUM 4
76-
#endif
182+
#elif USE_CUSTOM_ETHERNET
77183

78-
Ethernet.setCsPin (USE_THIS_SS_PIN);
79-
Ethernet.init (ETHERNET3_MAX_SOCK_NUM);
184+
// You have to add initialization for your Custom Ethernet here
185+
// This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough
186+
Ethernet.init(USE_THIS_SS_PIN);
187+
188+
#endif //( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
189+
190+
#endif // defined(ESP8266)
80191

81-
#endif //( USE_ETHERNET || USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE )
192+
#endif // #if !(USE_NATIVE_ETHERNET)
82193

83194
// start the ethernet connection and the server:
84-
// Use Static IP
85-
//Ethernet.begin(mac, ip);
86195
// Use DHCP dynamic IP and random mac
87-
uint16_t index = millis() % NUMBER_OF_MAC;
196+
//uint16_t macIndex = millis() % NUMBER_OF_MAC;
197+
macIndex = millis() % NUMBER_OF_MAC;
198+
// Use Static IP
199+
//Ethernet.begin(mac[macIndex], ip);
200+
Ethernet.begin(mac[macIndex]);
201+
202+
#if !(USE_NATIVE_ETHERNET || USE_ETHERNET_PORTENTA_H7)
203+
MDNS_LOGWARN(F("========================="));
204+
205+
#if defined( ESP32 )
206+
// Just info to know how to connect correctly
207+
// To change for other SPI
208+
MDNS_LOGWARN(F("Currently Used SPI pinout:"));
209+
MDNS_LOGWARN1(F("MOSI:"), PIN_MOSI);
210+
MDNS_LOGWARN1(F("MISO:"), PIN_MISO);
211+
MDNS_LOGWARN1(F("SCK:"), PIN_SCK);
212+
MDNS_LOGWARN1(F("SS:"), PIN_SS);
213+
#else
214+
#if defined(CUR_PIN_MISO)
215+
MDNS_LOGWARN(F("Currently Used SPI pinout:"));
216+
MDNS_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI);
217+
MDNS_LOGWARN1(F("MISO:"), CUR_PIN_MISO);
218+
MDNS_LOGWARN1(F("SCK:"), CUR_PIN_SCK);
219+
MDNS_LOGWARN1(F("SS:"), CUR_PIN_SS);
220+
#else
221+
MDNS_LOGWARN(F("Currently Used SPI pinout:"));
222+
MDNS_LOGWARN1(F("MOSI:"), MOSI);
223+
MDNS_LOGWARN1(F("MISO:"), MISO);
224+
MDNS_LOGWARN1(F("SCK:"), SCK);
225+
MDNS_LOGWARN1(F("SS:"), SS);
226+
#endif
227+
#endif
228+
229+
MDNS_LOGWARN(F("========================="));
230+
231+
#elif (USE_ETHERNET_PORTENTA_H7)
232+
if (Ethernet.hardwareStatus() == EthernetNoHardware)
233+
{
234+
Serial.println("No Ethernet found. Stay here forever");
235+
236+
while (true)
237+
{
238+
delay(1); // do nothing, no point running without Ethernet hardware
239+
}
240+
}
241+
242+
if (Ethernet.linkStatus() == LinkOFF)
243+
{
244+
Serial.println("Not connected Ethernet cable");
245+
}
246+
#endif
247+
248+
Serial.print(F("Using mac index = "));
249+
Serial.println(macIndex);
250+
251+
Serial.print(F("Connected! IP address: "));
252+
Serial.println(Ethernet.localIP());
253+
}
88254

89-
Ethernet.begin(mac[index]);
255+
void setup()
256+
{
257+
Serial.begin(115200);
258+
while (!Serial && millis() < 5000);
90259

91-
// Just info to know how to connect correctly
92-
Serial.println("=========================");
93-
Serial.println("Currently Used SPI pinout:");
94-
Serial.print("MOSI:");
95-
Serial.println(MOSI);
96-
Serial.print("MISO:");
97-
Serial.println(MISO);
98-
Serial.print("SCK:");
99-
Serial.println(SCK);
100-
Serial.print("SS:");
101-
Serial.println(SS);
102-
Serial.println("=========================");
260+
Serial.print("\nStart DiscoveringServices on "); Serial.print(BOARD_NAME);
261+
Serial.print(" using "); Serial.println(SHIELD_TYPE);
262+
Serial.println(MDNS_GENERIC_VERSION);
103263

104-
Serial.print("Using mac index = ");
105-
Serial.println(index);
264+
initEthernet();
106265

107-
Serial.print("Connected! IP address: ");
108-
Serial.println(Ethernet.localIP());
109-
110266
// Initialize the mDNS library. You can now reach or ping this
111267
// Arduino via the host name "arduino.local", provided that your operating
112268
// system is mDNS/Bonjour-enabled (such as MacOS X).
113269
// Always call this before any other method!
114-
String hostname = String(BOARD_NAME) + "_" + String(index);
270+
String hostname = String(BOARD_NAME) + "_" + String(macIndex);
115271

116272
//hostname.toUpperCase();
117273
hostname.toLowerCase();
118274
hostname.replace(" ", "-");
275+
hostname.replace(".", "-");
119276
hostname.replace("_", "-");
120277

121278
Serial.print("Registering mDNS hostname: "); Serial.println(hostname);

0 commit comments

Comments
 (0)