---
title: "やっと解決！Arduino Ethernet Shield2（シールド２）通信"
url: "https://maker.wiznet.io/lawrence/projects/%E3%82%84%E3%81%A3%E3%81%A8%E8%A7%A3%E6%B1%BA%EF%BC%81arduino-ethernet-shield2%EF%BC%88%E3%82%B7%E3%83%BC%E3%83%AB%E3%83%89%EF%BC%92%EF%BC%89%E9%80%9A%E4%BF%A1/"
markdown_url: "https://maker.wiznet.io/lawrence/projects/%E3%82%84%E3%81%A3%E3%81%A8%E8%A7%A3%E6%B1%BA%EF%BC%81arduino-ethernet-shield2%EF%BC%88%E3%82%B7%E3%83%BC%E3%83%AB%E3%83%89%EF%BC%92%EF%BC%89%E9%80%9A%E4%BF%A1/md"
type: "UCC: User Created Content"
author: "mgo-tec"
author_url: "https://www.mgo-tec.com/blog-entry-11.html"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "mgo-tec"
original_url: "https://www.mgo-tec.com/blog-entry-11.html"
published: "2023-03-03"
language: "ja"
likes: 4
views: 294
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# やっと解決！Arduino Ethernet Shield2（シールド２）通信

> やっと解決！Arduino Ethernet Shield2（シールド２）通信

Original author: mgo-tec (source: https://www.mgo-tec.com/blog-entry-11.html)

## Article

#### NTP?

Network Time Protocol (NTP) is a protocol used to synchronize computer clock times in a network of computers. It is designed to scale to a large number of nodes across a wide area network and provides accuracy of a few milliseconds. It is used in embedded systems to synchronize time across multiple devices, allowing accurate time tracking and automated scheduling of tasks. NTP is used in applications such as remote access, network management, and distributed file systems.

**Ethernet2 library support W5100, W5200, W5500:**

https://github.com/arduino-libraries/Ethernet/releases/tag/2.0.0

**Arduino NTP client example code with Ethernet 2 lib:**

// NTP Client for Arduino Ethernet 2 Library
// Author: Andy Gelme
// Date: 10 April 2015

#include &lt;Ethernet2.h>
#include &lt;NTPClient.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 177);

// Define NTP Client to get time
NTPClient timeClient(ntpUDP, "time.nist.gov");

void setup() {
Serial.begin(9600);
// Connect to the ethernet:
Ethernet.begin(mac, ip);
delay(1000);
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());

// Initialize the NTP client:
timeClient.begin();
// By default, the time client will send requests every 15 minutes.
// This can be changed by calling setUpdateInterval(interval). timeClient.setUpdateInterval(60000);
}

void loop() {
// Update the time:
timeClient.update();

// Get the Unix time:
unsigned long epochTime = timeClient.getEpochTime();
// Print the time:
Serial.print("Unix time = ");
Serial.println(epochTime);

// You can then convert the Unix time to whatever format you want:
Serial.print("The UTC time is ");
// print the hour, minute and second:
Serial.print((epochTime % 86400L) / 3600);
// print the hour (86400 equals secs per day)
Serial.print(':');

if ( ((epochTime % 3600) / 60) &lt; 10 ) {
// In the first 10 minutes of each hour, we'll want a leading '0'
Serial.print('0');
}

Serial.print((epochTime % 3600) / 60);
// print the minute (3600 equals secs per minute)
Serial.print(':');
if ( (epochTime % 60) &lt; 10 ) {
// In the first 10 seconds of each minute, we'll want a leading '0'
Serial.print('0');
}

Serial.println(epochTime %60);
// print the second
delay(10000);
}

---

Source: https://maker.wiznet.io/lawrence/projects/%E3%82%84%E3%81%A3%E3%81%A8%E8%A7%A3%E6%B1%BA%EF%BC%81arduino-ethernet-shield2%EF%BC%88%E3%82%B7%E3%83%BC%E3%83%AB%E3%83%89%EF%BC%92%EF%BC%89%E9%80%9A%E4%BF%A1/
