This series of lessons will teach you how to take your Arduino projects to the next level by having the Arduino interact with the Python programming language. Python is a free program you can download. Since you have already learned the fundamentals of programming through our first 20 Arduino lessons, learning Python will be a snap!
Especially, Look over the following 2 lessons.
Python with Arduino LESSON 16: Simple Client Server Configuration over Ethernet. This lesson will help you get your arduino set up as a server, and talking to a client in Python.
Python with Arduino LESSON 17: In this lesson we use the arduino as a server and Python as a client. Python sends a request to measure temperature or pressure. Arduino reads the request, makes the requested measurement, and then sends the data back.
Arduino Ethernet Library 업데이트 내용과 유용한 몇개의 라이브러리와 관련 예제를 정리해 본다.
(Modified) 2019-01-15
Arduino Ethernet Library v2.0 - Arduino official
WIZnet fork version - supports W5100S & W6100
Runtime에 자동으로 연결되어 있는 칩셋을 알아내고, 알맞는 드라이버를 자동으로 선택하도록 개선되었다.
W5100, W5200, W5500 어떤 칩을 사용하는 하드웨어를 연결하더라도 드라이버에서 자동으로 제어할 수 있다.
최근에 출시된 Arduino MKR ETH shield 제품을 사용한다면 필수!!
즉, 칩셋을 변경하기 위해 소스코드를 수정할 필요가 없다!!
WIZnet version, W5100S와 W6100등의 최신 칩셋을 지원하기 위해 WIZnet 에서 개발중인 드라이버 버전
Arduino MKR zero 보드를 이용한 응용 예제
Mobile app 으로 제어하기 ; Arduino Ethernet Library v2.0을 이용한 예제 구현 및 Blogging, WIZnet IoT Tool을 이용하여 Mobile device 에서 간단하게 아두이노 보드를 다룰 수 있다.
스마트폰으로 간단하게 Arduino 제어하기 (1) - Arduino MKR ETH + Arduino MKR Zero platform
스마트폰으로 간단하게 Arduino 제어하기 (2) - WIZnet IoT Tool app
스마트폰으로 간단하게 Arduino 제어하기 (3) - Simple remote display function with WIZnet IoT Tool
과거 Reference
Arduino Ethernet Library 2.0.0 - PJRC - 사실 Arduino Ethenret library v2.0의 원조 라이브러리, 이 저자가 최근 official version 릴리즈를 담당해주었다.
Adafruit Ethernet2
WIZ_Ethernet_Library-IDE1.6.x-master.zip
Seeed Studio Ethernet Shield V2.0 Library
Benchmarks & Test Results 를 포함하고 있다. 이 페이지는 필독!!!!
SPI 속도로 인해 W5100 보다 W5200/W5500 이 나은 속도를 보이고 있음을 알 수 있다. (숫자는 Byte/sec)
Adafruit에서 만든 W5500을 지원하기 위해 만들어진 라이브러리
업데이트 중단 선언! 최근 릴리즈된 Arduino Ethernet library v2.0 를 쓸 것을 권고
Adafruit Ethernet FeatherWing to Ubidots over HTTP
Arduino Ethernet + SD Card
아주 작은 모듈로 제작된 FeatherWing과 대표적인 IoT Cloud 솔루션인 Ubidots 와 연결하는 예제
소스코드와 구현 결과물은 링크페이지에 자세히 나와 있다.
대표적인 웹서버 예제로 Arduino Ethernet shield에 있는 SD 카드의 파일정보를 읽어 제공하는 tutorial이다.
소스코드와 구현방법을 순차적으로 아주 잘 정리해 두어 초보자가 아주 쉽게 따라할 수 있다.
Github source
W5500 을 지원하기 위해 Seeed Studio 에서 수정한 라이브러리
WIZnet 에서 제공하고 있는 WIZ_Ethernet_Library for IDE1.5.x 소스와 유사하다.
Arduino IDE1.6.x 이하 버전에서만 사용해야 하며, compile-time 에 반드시 chipset 을 선택해야 한다. 아래 코드 참조
W5500 Ethernet Shield v1.0 Webserver
Select device: W5100, W5200 or W5500
// In the W5100.h file(\libraries\Ethernet\utility\w5100.h), uncomment the device(shield) you want to use. #ifndef W5100_H_INCLUDED #define W5100_H_INCLUDED #include <avr/pgmspace.h> #include <SPI.h> typedef uint8_t SOCKET; //#define W5100_ETHERNET_SHIELD //#define W5200_ETHERNET_SHIELD #define W5500_ETHERNET_SHIELD
in Main .ino file
// By default, "WIZ550io_WITH_MACADDRESS" is commented and if you uncomment it, you can use the MAC address stored in the WIZ550io. #if defined(W5500_ETHERNET_SHIELD) //#define WIZ550io_WITH_MACADDRESS // Use assigned MAC address of WIZ550io #include "w5500.h" #endif
가장 기본적인 온도와 습도값을 보여주는 웹서버 기능을 잘 구현한 예제로 초보자가 쉽게 따라할 수 있도록 구성되어 있다.
소스코드는 물론 하드웨어 연결구조 및 설명이 자세히 되어 있다.
W5200 Shield 제품 출시와 함께 만들어서 배포
W5200 Shield 제품을 사용하고 있다면 아직도 유용한 라이브러리
Webserver Example
웹서버를 이용한 I/O 제어를 하는 간단하고 명쾌한 예제의 소스코드와 설명이 잘 정리되어 있다.
Von Haus aus kommt der Arduino Uno ohne eine Netzwerklösung daher. Dies kann man recht einfach mit einem Arduino Ethernet Shield aendern. Einfach aufstecken und der Arduino hat eine LAN Anschluss.
Damit nun der Arduino in deinem Netzwerk funktioniert bedarf es noch einem Sketch.
Dank dem gut Dokumentierten Arduino Projekt gibt es auch gute Ethernet Libray's.
Arduino LAN Sketch
/*
Web Server
*/
// Diese beide Libraries sind erforderlich
#include
#include
/*
Hier die MAC Adresse des Shields eingeben
Meistens gibt es einen Aufkleber auf der Rückseite des Shields
*/
byte mac = {
0x90, 0xA2, 0xDA, 0x00, 0xFB, 0x80 };
/*
Nun noch eine freie IP auf aus deinem Netzwerk angeben. Dazu
ist es am einfachsten die IP des Rechners auszulesen.
ifconfig ist hier das Stichwort.
*/
IPAddress ip(192,168,1,177);
// Ethernet Library als Server initialisieren
// Verwendet IPAdress und den Port 80 für http
EthernetServer server(80);
void setup() {
/*
Serielle Kommunikation starten
*/
Serial.begin(9600);
// Ethernet Verbindung und Server starten
Ethernet.begin(mac, ip);
server.begin();
Serial.print("Server gestartet. IP: ");
// IP des Arduino-Servers ausgeben
Serial.println(Ethernet.localIP());
}
void loop() {
/*
server.available() schaut, ob ein Client verfügbar ist und Daten
an den Server schicken möchte. Gibt dann eine Client-Objekt zurück, sonst false
*/
EthernetClient client = server.available();
// Wenn es einen Client gibt, dann...
if (client) {
Serial.println("Neuer Client");
/*
Jetzt solange Zeichen lesen, bis eine leere Zeile empfangen wurde
HTTP Requests enden immer mit einer leeren Zeile
*/
boolean currentLineIsBlank = true;
// Solange Client verbunden
while (client.connected()) {
// client.available() gibt die Anzahl der Zeichen zurück, die zum Lesen
// verfügbar sind
if (client.available()) {
// Ein Zeichen lesen und am seriellen Monitor ausgeben
char c = client.read();
Serial.write(c);
// In currentLineIsBlank merken wir uns, ob diese Zeile bisher leer war.
/*
Wenn die Zeile leer ist und ein Zeilenwechsel (das \n) kommt,
dann ist die Anfrage zu Ende und wir können antworten
*/
if (c == '\n' && currentLineIsBlank) {
// HTTP Header 200 an den Browser schicken
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // Verbindung wird nach Antwort beendet
client.println("Refresh: 2"); // Seite alle 25 Sekunden neu abfragen
client.println();
// Ab hier berginnt der HTML-Code, der an den Browser geschickt wird
client.println("");
client.println("");
client.print("Analogpin 0: ");
client.print(analogRead(A0));
client.println("
");
client.println("");
break;
}
if (c == '\n') {
// Zeilenwechsel, also currentLineIsBlack erstmal auf True setzen
currentLineIsBlank = true;
}
else if (c != '\r') {
// Zeile enthält Zeichen, also currentLineIsBlack auf False setzen
currentLineIsBlank = false;
}
}
}
// Kleine Pause
delay(1);
// Verbindung schliessen
client.stop();
Serial.println("Verbindung mit Client beendet.");
Serial.println("");
}
}
Read the full article