My first experiments with the Arduino Ethernet Shield and the Ethernet library weren’t terribly satisfying, because the Arduino (Duemillanove) could satisfy five (5) TCP connects/disconnects before crashing – well, it didn’t crash, but it no longer connected to the network. In spite of using the newest version of the Arduino software (0015), I wasn’t able to solve the problem. From a posting on the Arduino Forum, I got a pointer to the Ethernet2 library, and that solved the issue. I downloaded the code, dropped it into my arduino-0015/hardware/libraries/Ethernet2 directory and modified my sketch to use

#include <Ethernet2.h>

instead. (The Ethernet2 library has the same interface as the Ethernet library.) The sketch I used is:

    #include <Ethernet2.h>
    #include <stdio.h>
    byte     mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x02};
    byte     ip[] = {192, 168, 1, 177};
    byte     server[] = {192, 168, 1, 20};
    Client   client(server, 80);
    void setup()
       Ethernet.begin(mac, ip);
    void loop()
       long     count = 0;
       char     buf[128];
       if (client.connect()) {
          sprintf(buf, "GET /arduino.php?n=%ld HTTP/1.0", count++);
       } else {
          Serial.println("connection failed");
       Serial.print("client.status = ");
       Serial.println(client.status(), DEC);
       while (client.available() && client.connected()) {
          char     c =;

That solved it. The Arduino can now satisfy four (4) connects, read, disconnect cycles to an Apache server per second, which is more than enough for my needs. The photo above shows my test setup (not very fascinating, yet). The blue cable is Ethernet, the one below USB. Note how small those boards are: the coin to the right is a 1 Euro coin. Since writing this, a new version of Client.cpp has been submitted which fixes the problem I described above in the Ethernet library.

Hardware and Arduino :: 24 Apr 2009 :: e-mail


blog comments powered by Disqus