[TriEmbed] Lessons Learned with Arduino Ethernet Shield from a Newbie

Dwight Morgan dwight.w.morgan at gmail.com
Tue Dec 9 22:00:21 CST 2014


I'm putting this out there for any new to Arduino folks like me who might
need the info:

 

Last night at the TriEmbed meeting Paul helped me with a process to make one
of my Ethernet shields work and shared some Ethernet test code. However, I
couldn't get the second shield to work. At first I thought it was broken and
bought a second one because of that. Today I wanted to make sure I could
duplicate making it work and I did, but again only on one of the Ethernet
shields. In Googling and reading comments of others who seemed to be having
similar problems I started paying more attention to the version numbers.
Okay, the old one v1.1 worked and the newer one, v2.2 did not. I finally
found the answer on the Seeed (manufacturer) Web site. After I downloaded
the new version 2 library and put it in the library folder the newer shield
worked fine. The sketch has to call that library in an include statement:
#include <EthernetV2_0.h>

 

One other thing I learned in my struggles:  if your router servicing the
Ethernet shield has the same IP as another one that your pc can detect, you
have to make it so it can't  detect it. I was using an old router for my
testing so I had to kill my home network for a little while because both
have the IP of 192.168.1.1.

 

If anyone is interested here is the Seeed URL for the v2.0 Ethernet library
and instructions on how to test it out:

http://www.seeedstudio.com/wiki/Ethernet_Shield_V2.0

 

I enjoyed the meeting and appreciated the help very much!

 

Dwight

 

 

 

 

From: The MacDougals [mailto:paulmacd at acm.org] 
Sent: Tuesday, December 02, 2014 9:17 AM
To: 'Dwight Morgan'; triembed at triembed.org
Subject: RE: [TriEmbed] Arduino Topic for Dec 7 Meeting?

 

I would guess that the issue is with the IP address.

 

Here is some code fragment that I use.  Note that I do not set the IP
address.

This is a cut-and-paste-and-slim-down job, so it may not even compile, but
you get the idea.

 

---> Paul

 

#include <SPI.h>

#include <Ethernet.h>

 

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address

EthernetServer server(80); //server port

String clientstring;

 

const uint8_t LED_PIN  = 13;

int led = LOW;

 

setup()

{

    pinMode(LED_PIN, OUTPUT);

    led = HIGH;

    digitalWrite(LED_PIN, led);

    delay(200);

    led = LOW;

    digitalWrite(LED_PIN, led);

 

    // Start up the Serial port

    Serial.begin(9600);

    while (!Serial);

    Serial.println(F("Initialized"));

 

    Ethernet.begin(mac /*, ip, gateway, subnet*/);

    server.begin();

 

    IPAddress myIP = Ethernet.EthernetClass::localIP();

    Serial.print(F("IP address: "));

    Serial.print(myIP[0]);

    Serial.print(F("."));

    Serial.print(myIP[1]);

    Serial.print(F("."));

    Serial.print(myIP[2]);

    Serial.print(F("."));

    Serial.println(myIP[3]);

}

 

loop()

{

  // Create a client connection

  EthernetClient client = server.available();

  if (client) {

    Serial.println(F("Created client"));

    while (client.connected()) {

      if (client.available()) {

        char c = client.read();

 

        //read char by char HTTP request

        if (clientstring.length() < 100) {

            Serial.print(F("Got - "));

            Serial.print(c);

            Serial.println(F(" !"));

 

            //store characters to string

            if (c != 0)

                clientstring += c; 

        } else {

            Serial.println(F("String reset at 100"));

            clientstring = ""; // reset

        }

 

        //if HTTP request has ended

        if (c == '\n') {

 

          ///////////////

          Serial.println(clientstring); //print to serial monitor for
debuging

          

          if (clientstring.indexOf("lightoff") >0)//checks for off

          {

            led = LOW;

            digitalWrite(LED_PIN, led);    // set pin 3 low

            Serial.println(F("LED Off"));

          }

          

          if (clientstring.indexOf("lighton") >0)//checks for on

          {

            led = HIGH;

            digitalWrite(LED_PIN, led);    // set pin 3 high

            Serial.println(F("LED On"));

          }

 

          // Return the formatted HTML page

          client.println(F("HTTP/1.1 200 OK"));

          client.println(F("Content-Type: text/html"));

          client.println();

 

          client.println(F("<HTML>"));

          client.println(F("<HEAD>"));

         client.println(F("<TITLE>Test Page</TITLE>"));

          client.println(F("</HEAD>"));

          client.println(F("<BODY>"));

          client.println(F("<H1>Onboard LED</H1>"));

          client.print(F("LED - "));

          if (led==HIGH) {

              client.print("on");

              client.println(F("<br>"));

              client.println(F("<a
href=\"/?lightoff\"\">OFF</a>&nbsp&nbsp&nbsp"));

          } else {

              client.print("off");

              client.println(F("<br>"));

              client.println(F("<a
href=\"/?lighton\"\">ON</a>&nbsp&nbsp&nbsp"));

          }

          

          client.println(F("<br>"));

          client.println(F("</BODY>"));

          client.println(F("</HTML>"));

 

          delay(10);

          //stopping client

          client.stop();

 

          //clearing string for next read

          clientstring = "";

        }

      }

    }

  }

}

 

 

From: TriEmbed [mailto:triembed-bounces at triembed.org] On Behalf Of Dwight
Morgan
Sent: Monday, December 01, 2014 10:48 PM
To: triembed at triembed.org
Subject: [TriEmbed] Arduino Topic for Dec 7 Meeting?

 

I'm a newbie and going through the Simon Monk book, "Programming Arduino
Getting Started with Sketches". I am stuck on chapter 10, "Arduino Ethernet
Programming". I have tried numerous things to get the Arduino to act as a
server but it just won't connect. I'm running Windows 7 on my PC and I have
a Netgear router for my wireless router with 4 wired ports. I've plugged the
RJ45 into the router and my PC and tried different IP addresses that are not
taken by my router already but nothing works. I cut off the firewall once
but that didn't help. I replaced the Ethernet shield and the UNO but that
didn't help. I'm trying to run the simplest code as best I can tell which is
the Monk example code 10-01 copied below for reference:

 

// sketch 10-01 Simple Server Example

 

#include <SPI.h>

#include <Ethernet.h>

 

 

// MAC address just has to be unique. This should work

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// The IP address will be dependent on your local network:

byte ip[] = { 192, 168, 1, 30 };

 

EthernetServer server(80);

 

void setup()

{

  Ethernet.begin(mac, ip);

  server.begin();

  Serial.begin(9600);

}

 

void loop()

{

  // listen for incoming clients

  EthernetClient client = server.available();

  if (client) 

  {

    while (client.connected()) 

    {

      // send a standard http response header

      client.println("HTTP/1.1 200 OK");

      client.println("Content-Type: text/html");

      client.println();

      

      // send the body

      client.println("<html><body>");

      client.println("<h1>Arduino Server</h1>");

      client.print("<p>A0="); 

      client.print(analogRead(0)); 

      client.println("</p>"); 

      client.print("<p>millis="); 

      client.print(millis()); 

      client.println("</p>"); 

      client.println("</body></html>");

      client.stop();

    }

    delay(1);

  }

}

 

One potential thing I have not covered is the power supply. I'm unplugging
the USB as instructed in the book and plugging in a 9 Volt battery pack -
all I have right now for power. I have a 9 Volt 1.5 Amp power supply on
order to get here Friday. I'm not sure if that is a problem or not. 

 

I'm running Arduino IDE 1.0.4. The board is Arduino UNO and the Ethernet
shield is made by Seeed. 

 

If this is something someone with more experience could talk about at the
meeting I definitely have an interest. I have looked online for solutions
but nothing so far has worked. If this topic does not serve the group well,
I understand, but maybe someone who has knowledge of this could just give me
some directions to get me back on the right path. 

 

Thanks! 

 

Dwight

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.triembed.org/pipermail/triembed_triembed.org/attachments/20141209/22a5f6e2/attachment.htm>


More information about the TriEmbed mailing list