iDreamMicro - Mot-clé - Ethernet2023-05-17T23:19:49+02:00Julien Le Sechurn:md5:748efb83ba33c51f389cc9cd76987761DotclearEKitsZone W5200 Ethernet Shieldurn:md5:1fb8adbb9afc2058ac9f29e6c73d6b682012-07-25T09:00:00+02:002012-08-21T10:52:24+02:00Julien Le SechArduinoAtmegaAVREthernetWIZnet W5200<p>
<img src="http://www.idreammicro.com/public/posts/ekitszone-w5200-ethernet-shield/P1010077.png" alt="P1010077.png" style="margin: 0 auto; display: block;" title="P1010077.png, juil. 2012" />
</p>
<p>
La plateforme de développement <a href="http://arduino.cc">Arduino</a> bénéficie d'une large communauté et d'un grand nombre de modules, <em>shields</em> ou <em>breakout boards</em> divers et variés. Il existe notamment des <em>shields</em> permettant d'ajouter une connexion réseau <a href="http://fr.wikipedia.org/wiki/Ethernet">Ethernet</a> tels que l'<a href="http://arduino.cc/en/Main/ArduinoEthernetShield">Arduino Ethernet Shield</a>.
</p>
<p>
Le <em>shield</em> officiel embarque un contrôleur Ethernet <a href="http://www.wiznet.co.kr/Sub_Modules/en/product/Product_Detail.asp?cate1=5&cate2=7&cate3=26&pid=1011">WIZnet W5100</a>. Le W5200 Ethernet Shield d'EkitsZone est quant à lui basé sur un contrôleur Ethernet <a href="http://www.wiznet.co.kr/Sub_Modules/en/product/Product_Detail.asp?cate1=5&cate2=7&cate3=56&pid=1144">WIZnet W5200</a>.
</p>
<p>
Cet article présente la mise en œuvre du W5200 Ethernet Shield sur une carte de développement <a href="http://arduino.cc/en/Main/ArduinoBoardUno">Arduino Uno</a>. L'environnement de développement utilisé est <a href="http://arduino.cc/en/Main/Software">Arduino</a> en version 1.0.1.
</p> <h2>Contrôleurs Ethernet WIZnet W5100/W5200</h2>
<p>
Les puces W5100 et W5200 de WIZnet sont des contrôleurs réseaux permettant aux systèmes embarqués qui les emploient de bénéficier simplement d'une connexion réseau Ethernet. Ils intègrent une <a href="http://fr.wikipedia.org/wiki/Suite_des_protocoles_Internet">pile TCP/IP</a> matérielle.
</p>
<p>
<a href="http://www.idreammicro.com/public/posts/ekitszone-w5200-ethernet-shield/W5x00.jpg" title="W5x00.jpg"><img src="http://www.idreammicro.com/public/posts/ekitszone-w5200-ethernet-shield/.W5x00_m.jpg" alt="W5x00.jpg" style="margin: 0 auto; display: block;" title="W5x00.jpg, juil. 2012" /></a>
</p>
<p>
Le W5100 propose au choix une interface <a href="http://fr.wikipedia.org/wiki/Serial_Peripheral_Interface"><acronym title="Serial Peripheral Interface">SPI</acronym></a> ou parallèle tandis que le W5200 ne propose qu'une interface SPI. Par rapport au W5100, le W5200 offre quelques évolutions récapitulées dans le tableau ci-dessous (liste non exhaustive) :
</p>
<table>
<tr><th></th><th>W5100</th><th>W5200</th></tr>
<tr><td>Interface</td><td>Parallèle / SPI</td><td>SPI</td></tr>
<tr><td>Fréquence SPI</td><td>4 MHz</td><td>80 MHz</td></tr>
<tr><td>Nombre de sockets</td><td>4</td><td>8</td></tr>
<tr><td>Buffer RX/TX</td><td>16 ko</td><td>32 ko</td></tr>
<tr><td><em>Power Down mode</em></td><td>non</td><td>oui</td></tr>
<tr><td><a href="http://fr.wikipedia.org/wiki/Wake_on_lan"><em>Wake On LAN</em></a></td><td>non</td><td>oui</td></tr>
</table>
<!--
<ul>
<li>bus SPI haute vitesse (jusqu'à 80 MHz) ;</li>
<li>jusqu'à 8 <a href="http://fr.wikipedia.org/wiki/Socket"><em>sockets</em></a> ;</li>
<li>support du <em>Power Down mode</em> ;</li>
<li>support du <a href="http://fr.wikipedia.org/wiki/Wake_on_lan"><em>Wake On LAN</em></a> ;</li>
<li>boîtier plus petit.</li>
</ul>
-->
<h2>Bibliothèque W5200 Arduino Ethernet Library</h2>
<p>
La bibliothèque <a href="http://arduino.cc/en/Reference/Ethernet">Ethernet</a> livrée avec l'environnement de développement Arduino est conçue pour exploiter l'Arduino Ethernet Shield officiel à base de W5100. Son arborescence est la suivante :
</p>
<pre class="brush: text; gutter: false; highlight: [6, 7, 13];">
Ethernet
|_examples
|_utility
| |_socket.cpp
| |_socket.h
| |_w5100.cpp
| |_w5100.h
|_Dhcp.cpp
|_Dhcp.h
|_Dns.cpp
|_Dns.h
|_Ethernet.cpp
|_Ethernet.h
|_EthernetClient.cpp
|_EthernetClient.h
|_EthernetServer.cpp
|_EthernetServer.h
|_EthernetUdp.cpp
|_EthernetUdp.h
|_util.h
</pre>
<p>
Cependant l'EKitsZone Ethernet Shield est basé sur un W5200. Par conséquent, il est nécessaire de modifier la bibliothèque Ethernet originale.
</p>
<p>
Une petite recherche sur Internet conduit à l'article <a href="http://blog.wiznet.co.kr/w5200-arduino-ethernet-library/">W5200 Arduino Ethernet Library</a> sur le <a href="http://blog.wiznet.co.kr/">blog WIZnet</a>. L'auteur du billet, Jinbuhm Kim, propose sur son dépôt Github la bibliothèque <a href="https://github.com/jbkim/W5200-Arduino-Ethernet-library">jbkim/W5200-Arduino-Ethernet-library</a>.
</p>
<p>
Cette bibliothèque se compose des fichiers <a href="https://github.com/jbkim/W5200-Arduino-Ethernet-library/blob/master/w5100.h"><em>utility/w5100.h</em></a> et <a href="https://github.com/jbkim/W5200-Arduino-Ethernet-library/blob/master/w5100.cpp"><em>utility/w5100.cpp</em></a> modifiés pour le contrôleur W5200.
</p>
<p>
Il est également nécessaire de modifier le fichier <em>Ethernet.h</em> en remplaçant la ligne :
</p>
<pre class="brush: cpp; first-line: 11;">
#define MAX_SOCK_NUM 4
</pre>
<p>
par les lignes suivantes :
</p>
<pre class="brush: cpp; first-line: 11;">
#ifdef W5200
#define MAX_SOCK_NUM 8
#else
#define MAX_SOCK_NUM 4
#endif
</pre>
<h2>Mise en œuvre</h2>
<p>
La mise en œuvre de la bibliothèque présentée précédemment consiste à utiliser un <em>sketch</em> permettent d'obtenir une <a href="http://fr.wikipedia.org/wiki/Adresse_IP">adresse <acronym title="Internet Protocol">IP</acronym></a> auprès d'un serveur <a href="http://fr.wikipedia.org/wiki/DHCP"><acronym title="Dynamic Host Configuration Protocol">DHCP</acronym></a> et de la communiquer via la liaison série. Enfin, un <a href="http://fr.wikipedia.org/wiki/Ping_%28logiciel%29"><em>ping</em></a> de la carte de développement permettra de confirmer son intégration au réseau.
</p>
<h3>Obtention d'une adresse IP</h3>
<p>
On utilise le <em>sketch</em> <em>DhcpAddressPrinter.ino</em> livré avec la bibliothèque Ethernet.
</p>
<pre class="brush: cpp;">
/*
DHCP-based IP printer
This sketch uses the DHCP extensions to the Ethernet library
to get an IP address via DHCP and print the address obtained.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
created 12 April 2011
modified 9 Apr 2012
by Tom Igoe
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
// print your local IP address:
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
}
void loop() {
}
</pre>
<p>
Si tout se passe bien, l'Arduino communique son adresse IP (ici 192.168.1.4) via la liaison série :
</p>
<p>
<a href="http://www.idreammicro.com/public/posts/ekitszone-w5200-ethernet-shield/address.png" title="address.png"><img src="http://www.idreammicro.com/public/posts/ekitszone-w5200-ethernet-shield/address.png" alt="address.png" style="margin: 0 auto; display: block;" title="address.png, juil. 2012" /></a>
</p>
<p>
Dans le cas contraire, l'Arduino envoie le message <q>Failed to configure Ethernet using DHCP</q>.
</p>
<h3>Ping de la carte de développement</h3>
<p>
Pour vérifier l'intégration de l'Arduino au réseau, on propose de lui adresser des requêtes <a href="http://fr.wikipedia.org/wiki/Internet_Control_Message_Protocol"><acronym title="Internet Control Message Protocol">ICMP</acronym></a> à l'aide de la commande <a href="http://linux.die.net/man/8/ping"><em>ping</em></a> :
</p>
<pre class="brush: bash; gutter: false;">
$ ping 192.168.1.4
</pre>
<p>
Si tout fonctionne, on observe les réponses de l'Arduino :
</p>
<p>
<a href="http://www.idreammicro.com/public/posts/ekitszone-w5200-ethernet-shield/ping.png" title="ping.png"><img src="http://www.idreammicro.com/public/posts/ekitszone-w5200-ethernet-shield/ping.png" alt="ping.png" style="margin: 0 auto; display: block;" title="ping.png, juil. 2012" /></a>
</p>
<h2>Conclusion</h2>
<p>
L'adjonction d'un <em>shield</em> Ethernet à une plateforme telle qu'Arduino permet de l'intégrer dans un environnement réseau, local ou distant. Cette intégration laisse entrevoir de très nombreuses perspectives telles que des solutions domotiques ou stations météo connectées.
</p>
<p>
La solution proposée par Jinbuhm Kim fonctionne parfaitement et permet d'utiliser les modules Ethernet basés sur un WIZnet W5200. Toutefois les modifications effectuées ne permettent plus d'utiliser l'Arduino Ethernet Shield à base de WIZnet W5100. <a href="http://www.idreammicro.com">iDreamMicro</a> reviendra sur ce point dans un prochain article et proposera une solution permettant de choisir le type de contrôleur Ethernet.
</p>
<h2>Références</h2>
<ul>
<li><a href="http://arduino.cc/en/Reference/Ethernet">Arduino Ethernet Library</a></li>
<li><a href="http://blog.wiznet.co.kr/w5200-arduino-ethernet-library/">W5200 Arduino Ethernet Library</a></li>
</ul>http://www.idreammicro.com/post/EKitsZone-W5200-Ethernet-Shield#comment-formhttp://www.idreammicro.com/feed/atom/comments/44