From ca983e2ee91fa50d6ec12395f4d2965bc1a10b81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Giera=C5=82towski?= Date: Fri, 27 Jan 2023 11:09:55 +0100 Subject: [PATCH] Add example of using with Arduino Ethernet Shield (#111) --- .../ArduinoEthernetShield.ino | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 examples/ArduinoEthernetShield/ArduinoEthernetShield.ino diff --git a/examples/ArduinoEthernetShield/ArduinoEthernetShield.ino b/examples/ArduinoEthernetShield/ArduinoEthernetShield.ino new file mode 100644 index 0000000..5d142e9 --- /dev/null +++ b/examples/ArduinoEthernetShield/ArduinoEthernetShield.ino @@ -0,0 +1,45 @@ +#include +#include + +#define ethernetShieldPin 10 // Most Arduino shields +// #define ethernetShieldPin 5 // MKR ETH shield +// #define ethernetShieldPin 0 // Teensy 2.0 +// #define ethernetShieldPin 20 // Teensy++ 2.0 +// #define ethernetShieldPin 15 // ESP8266 with Adafruit Featherwing Ethernet +// #define ethernetShieldPin 33 // ESP32 with Adafruit Featherwing Ethernet + +byte localMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; +unsigned int localUdpPort = 8888; +EthernetUDP udp; + +NTPClient timeClient(udp); + +void setup() { + Serial.begin(115200); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Ethernet.init(ethernetShieldPin); + Serial.println("Initialize Ethernet with DHCP"); + if (Ethernet.begin(localMac) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found."); + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + while (true) { + delay(1); + } + } + udp.begin(localUdpPort); +} + +void loop() { + if(timeClient.update()) { + Serial.print("Updated current time: "); + Serial.println(timeClient.getFormattedTime()); + } +}