아두이노 나노 ESP32 - 이더넷 | Arduino Nano ESP32 - Ethernet

이 가이드에서는 W55010 이더네트 모듈을 사용하여 인터넷 또는 로컬 네트워크에 Arduino Nano ESP32를 연결하는 방법을 보여줍니다. 다음을 배우게 됩니다:

아두이노 나노 ESP32 이더넷

Hardware Preparation

1×Arduino Nano ESP32 Amazon
1×USB Cable Type-C 쿠팡 | Amazon
1×W5500 Ethernet Module Amazon
1×Ethernet Cable Amazon
1×Jumper Wires Amazon
1×Breadboard 쿠팡 | Amazon
1×(Recommended) Screw Terminal Adapter for Arduino Nano 쿠팡 | Amazon
공개: 이 섹션에서 제공된 링크 중 일부는 제휴 링크입니다. 이 링크를 통해 구매한 경우 추가 비용없이 수수료를 받을 수 있습니다. 지원해 주셔서 감사합니다.

W5500 이더넷 모듈에 대하여

W550io 이더넷 모듈에는 두 가지 종류의 연결이 있습니다:

  • RJ45 인터페이스: 이더넷 케이블을 사용하여 라우터나 스위치에 연결하세요.
  • SPI 인터페이스: 이를 아두이노 나노 ESP32 보드에 연결하는 데 사용하세요. 10개의 핀이 포함되어 있습니다:
    • NC 핀: 이 핀은 연결하지 마세요.
    • INT 핀: 이 핀은 연결하지 마세요.
    • RST 핀: 이는 리셋 핀입니다; 아두이노 나노 ESP32의 EN 핀에 연결하세요.
    • GND 핀: 아두이노 나노 ESP32의 GND 핀에 연결하세요.
    • 5V 핀: 이 핀은 연결하지 마세요.
    • 3.3V 핀: 아두이노 나노 ESP32의 3.3V 핀에 연결하세요.
    • MISO 핀: 아두이노 나노 ESP32의 SPI MISO 핀에 연결하세요.
    • MOSI 핀: 아두이노 나노 ESP32의 SPI MOSI 핀에 연결하세요.
    • SCS 핀: 아두이노 나노 ESP32의 SPI CS 핀에 연결하세요.
    • SCLK 핀: 아두이노 나노 ESP32의 SPI SCK 핀에 연결하세요.
    이더넷 모듈 핀배열
    image source: diyables.io

아두이노 나노 ESP32와 W5500 이더넷 모듈 간의 배선도

아두이노 나노 ESP32 이더넷 모듈 배선도

이 이미지는 Fritzing을 사용하여 만들어졌습니다. 이미지를 확대하려면 클릭하세요.

image source: diyables.io

아두이노 나노 ESP32 이더넷 모듈 코드 - 이더넷을 통한 HTTP 요청 실행

이 코드는 웹 클라이언트처럼 작동합니다. http://example.com/에 있는 웹 서버로 HTTP 요청을 보냅니다.

/* * 이 Arduino Nano ESP32 코드는 newbiely.kr 에서 개발되었습니다 * 이 Arduino Nano ESP32 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/arduino-nano-esp32/arduino-nano-esp32-ethernet */ #include <SPI.h> #include <Ethernet.h> // replace the MAC address below by the MAC address printed on a sticker on the Arduino Shield 2 byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF }; EthernetClient client; int HTTP_PORT = 80; String HTTP_METHOD = "GET"; // or POST char HOST_NAME[] = "example.com"; String PATH_NAME = "/"; void setup() { Serial.begin(9600); delay(1000); Serial.println("Arduino Nano ESP32 - Ethernet Tutorial"); // initialize the Ethernet shield using DHCP: if (Ethernet.begin(mac) == 0) { Serial.println("Failed to obtaining an IP address"); // check for Ethernet hardware present if (Ethernet.hardwareStatus() == EthernetNoHardware) Serial.println("Ethernet shield was not found"); // check for Ethernet cable if (Ethernet.linkStatus() == LinkOFF) Serial.println("Ethernet cable is not connected."); while (true) ; } // connect to web server on port 80: if (client.connect(HOST_NAME, HTTP_PORT)) { // if connected: Serial.println("Connected to server"); // make a HTTP request: // send HTTP header client.println(HTTP_METHOD + " " + PATH_NAME + " HTTP/1.1"); client.println("Host: " + String(HOST_NAME)); client.println("Connection: close"); client.println(); // end HTTP header while (client.connected()) { if (client.available()) { // read an incoming byte from the server and print it to serial monitor: char c = client.read(); Serial.print(c); } } // the server's disconnected, stop the client: client.stop(); Serial.println(); Serial.println("disconnected"); } else { // if not connected: Serial.println("connection failed"); } } void loop() { }

Detailed Instructions

Arduino Nano ESP32를 시작하렘 다음 단계를 따르세요:

  • 아두이노 나노 ESP32에 처음 접근하는 경우, 아두이노 IDE에서 아두이노 나노 ESP32 환경 설정 방법에 관한 튜토리얼을 참조하세요.
  • 제공된 다이어그램에 따라 아두이노 나노 ESP32를 이더넷 모듈에 연결하세요.
  • 이더넷 케이블을 사용하여 이더넷 모듈을 라우터 또는 스위치에 연결하세요.
  • USB 케이블을 사용하여 아두이노 나노 ESP32 보드를 컴퓨터에 연결하세요.
  • 컴퓨터에서 아두이노 IDE를 실행하세요.
  • Arduino Nano ESP32 보드와 해당하는 COM 포트를 선택하세요.
  • 아두이노 IDE의 왼쪽 바에 있는 라이브러리들 아이콘을 클릭하세요.
  • “Ethernet”을 검색한 다음, Various에 의한 이더넷 라이브러리를 찾으세요.
  • Install 버튼을 클릭하여 이더넷 라이브러리를 설치하세요.
아두이노 나노 ESP32 이더넷 라이브러리
  • 아두이노 IDE에서 시리얼 모니터를 엽니다.
  • 주어진 코드를 복사하여 아두이노 IDE에 붙여넣습니다.
  • 아두이노 IDE에서 업로드 버튼을 눌러 코드를 ESP25로 전송합니다.
  • 아래와 같이 출력을 표시할 시리얼 모니터를 확인하세요.
COM6
Send
Arduino Nano ESP32 - Ethernet Tutorial Connected to server HTTP/1.1 200 OK Accept-Ranges: bytes Age: 208425 Cache-Control: max-age=604800 Content-Type: text/html; charset=UTF-8 Date: Fri, 12 Jul 2024 07:08:42 GMT Etag: "3147526947" Expires: Fri, 19 Jul 2024 07:08:42 GMT Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT Server: ECAcc (lac/55B8) Vary: Accept-Encoding X-Cache: HIT Content-Length: 1256 Connection: close <!doctype html> <html> <head> <title>Example Domain</title> <meta charset="utf-8" /> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> </head> <body> <div> <h1>Example Domain</h1> <p>This domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.</p> <p><a href="https://www.iana.org/domains/example">More information...</a></p> </div> </body> </html> disconnected
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

※ NOTE THAT:

동일 네트워크 상의 다른 기기가 같은 MAC 주소를 가지고 있다면 문제가 발생할 수 있습니다.

아두이노 나노 ESP32 코드 - 이더넷 모듈용 웹 서버

아래 코드는 아두이노 나노 ESP32를 웹 서버로 변환합니다. 이 서버는 웹 브라우저에 간단한 웹페이지를 전송합니다.

/* * 이 Arduino Nano ESP32 코드는 newbiely.kr 에서 개발되었습니다 * 이 Arduino Nano ESP32 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/arduino-nano-esp32/arduino-nano-esp32-ethernet */ #include <SPI.h> #include <Ethernet.h> // replace the MAC address below by the MAC address printed on a sticker on the Arduino Shield 2 byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF }; EthernetServer server(80); void setup() { Serial.begin(9600); delay(1000); Serial.println("Arduino Nano ESP32 - Ethernet Tutorial"); // initialize the Ethernet shield using DHCP: if (Ethernet.begin(mac) == 0) { Serial.println("Failed to obtaining an IP address"); // check for Ethernet hardware present if (Ethernet.hardwareStatus() == EthernetNoHardware) Serial.println("Ethernet shield was not found"); // check for Ethernet cable if (Ethernet.linkStatus() == LinkOFF) Serial.println("Ethernet cable is not connected."); while (true) ; } server.begin(); Serial.print("Arduino Nano ESP32 - Web Server IP Address: "); Serial.println(Ethernet.localIP()); } void loop() { // listen for incoming clients EthernetClient client = server.available(); if (client) { Serial.println("new client"); // an HTTP request ends with a blank line bool currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); Serial.write(c); // if you've gotten to the end of the line (received a newline // character) and the line is blank, the HTTP request has ended, // so you can send a reply if (c == '\n' && currentLineIsBlank) { // send a standard HTTP response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); // the connection will be closed after completion of the response client.println(); client.println("<!DOCTYPE HTML>"); client.println("<html>"); client.println("<body>"); client.println("<h1>Arduino Nano ESP32 - Web Server with Ethernet</h1>"); client.println("</body>"); client.println("</html>"); break; } if (c == '\n') { // you're starting a new line currentLineIsBlank = true; } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; } } } // give the web browser time to receive the data delay(1); // close the connection: client.stop(); Serial.println("client disconnected"); } }

Detailed Instructions

  • 제공된 코드를 복사하여 아두이노 IDE에 붙여넣으세요.
  • 아두이노 IDE에서 Upload 버튼을 클릭하여 코드를 Arduino Nano ESP32 보드로 전송하세요.
  • 시리얼 모니터를 확인하여 결과를 확인하세요.
COM6
Send
Arduino Nano ESP32 - Ethernet Tutorial Arduino Nano ESP32 - Web Server IP Address: 192.168.0.2
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  
  • 웹 브라우저의 주소 표시줄에 제공된 IP 주소를 입력하세요. Arduino Nano ESP32에서 표시되는 간단한 웹페이지를 볼 수 있습니다.
아두이노 나노 ESP32 이더넷 웹 서버

관련 튜토리얼

※ OUR MESSAGES

  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!