Arduino Ethernet W5100 Network Shield (HCARDU0034)

admin
Site Admin
Posts: 866
Joined: Sun Aug 05, 2012 4:02 pm

Arduino Ethernet W5100 Network Shield (HCARDU0034)

Post by admin » Fri Oct 05, 2012 4:04 pm

Image

This Ethernet Shield is based on the Wiznet W5100 Ethernet Chip and gives you an easy way to get your Arduino online. It is directly supported by the official Arduino Ethernet Library. It also includes an additional micro-SD card slot, which can be used to store files for serving over the network. It is compatible with the Arduino Duemilanove (168 or 328), Uno as well as Mega (1280/2560) and can be accessed using the SD and Ethernet libraries.

The Wiznet W5100 provides a network (IP) stack capable of both TCP and UDP. It supports up to four simultaneous socket connections. Use the Ethernet library to write sketches which connect to the internet using the shield.

Order Yours Here.


Schematic


Image
Ethernet ShieldV2 SCH.zip



Analogue Input Example

Code: Select all

/* FILE:    ARD_Ethernet_Shield_HCARDU0034_Example.pde
   DATE:    25/04/13
   VERSION: 0.2

This is an example of how to use the HobbyComponents Arduino Ethernet shield
(HCARDU0033). This Ethernet shield is based on the W5100 Ethernet controller and 
is compatible with the standard Aduino Ethernet libraries. It requires no additional
libraries to work.

This program will serve a basic webpage at the ip address specified below. As an 
example of content, the webpage contains the current status of the 6 analogue input 
pins.

REVISIONS:

V0.1 Initial version
V0.2 Added line to configure pin 53 as an output on Mega's to stop the SPI
     master potentially being configured as a slave by hardware.

You may copy, alter and reuse this code in any way you like, but please leave 
reference to HobbyComponents.com in your comments if you redistribute this code. 
This software may not be used directly for the purpose of selling products that 
directly compete with Hobby Components Ltd's own range of products. 

THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER 
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF 
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES, 
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY 
REASON WHATSOEVER.

*/


#include <SPI.h>

/* Include the standard Ethernet library */
#include <Ethernet.h>


/* MAC address of the Ethernet shield. If you are using this on your 
own network, then the MAC address below will be fine, but remember if 
you use more than one shield on your network they will need to be assigned
unique MAC addresses */
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

/* The IP address of the shield. Make sure this matches the IP 
   address range of your network and is not in use by any other 
   device on it */    
IPAddress ip(192, 168, 1, 55 );

/* The port number the shield will respond to. Use port 80 
   for standard HTTP requests */
EthernetServer server(80);


/* Start the Ethernet interface */
void setup()
{  
  //pinMode(53, OUTPUT); //Uncomment this line if using a Mega
  Ethernet.begin(mac, ip);
  server.begin();
}


void loop()
{
  /* All client requests are terminated with a blank line. This flag will 
    signify if the current line received from this client is a blank line */
  boolean bBlankLineFlag = true;
  
  /* Used to hold the current byre received from the client */
  char cCurrentByte;
  
  /* Loop counter used for reading the 6 analogue inputs */
  int k;
  
  /* Wait for a request from a client */
  EthernetClient ethernet = server.available();
  
  if (ethernet) 
  {
    /* Continue to read data from the client one byte at a time until 
       there is no more data */ 
    while (ethernet.connected()) 
    {
      /* Is there still data available to be read? ethernet class 
         ethernet.connected() returns the number of bytes available */
      if (ethernet.available()) 
      {
        /* If data is available read the next byte */ 
        cCurrentByte = ethernet.read();

        /* If the next byte read is a new line termination ? */      
        if (cCurrentByte == '\n')
        { 
          /* If so was it a blank line? */
          if (bBlankLineFlag) 
          {
            
            /* If it was then we can now send a response to the client’s http request... */
            ethernet.println("HTTP/1.1 200 OK");
            ethernet.println("Content-Type: text/html");
            ethernet.println();

            /* ...and add some useful content by reading the 6 
               analogue inputs and returning their status */
          
            ethernet.println("<body>");
            ethernet.println("<big><span style=\"font-weight: bold;\">www.hobbycomponents.com Ethernet Shield Example</span></big><br>");
            ethernet.println("****************************************************<br>");
          
            for (k = 0; k < 6; k++)
            {
              ethernet.println("Analogue input ");
              ethernet.print(k);
              ethernet.print(": ");
              ethernet.print(analogRead(k));
              ethernet.print("<br>");
            }
          
            ethernet.println("****************************************************<br>");
            ethernet.println("</body>");

            /* Disconnect from the client */
            ethernet.stop();
          }
        
          /* The last received byte was the start of a new line so flag as no 
             data received for this line yet */
          bBlankLineFlag = true;
        
        /* If the last byte received wasn't a new line then it must be data... */  
        } else if (cCurrentByte != '\r')
        {  
          /* ...and so flag this as not a blank line. */
          bBlankLineFlag = false;
        }
      }
    }
  }
}

SD Card Example

Code: Select all

/* FILE:    ARD_Ethernet_Shield_HCARDU0034_SD_Card_Reader_Example.pde
   DATE:    25/04/13
   VERSION: 0.2

This is an example of how to use the HobbyComponents Arduino Ethernet shield
(HCARDU0033) and its included micro SD card reader. This Ethernet shield is 
based on the W5100 Ethernet controller and is compatible with the standard Arduino
Ethernet libraries. It requires no additional libraries to work.

This example program will serve a web page to a client (i.e. web browser) that 
contains the contents of a text file saved on an inserted micro SD card.

For this example to work you will need to have a micro SD card inserted into the 
card reader containing a text file with the name 'test.txt'. The contents of the text 
file can be anything you like. When a client makes a connection, the program will 
attempt to read the contents of the test.txt file and serve it to the client.

REVISIONS:

V0.1 Initial version
V0.2 Added line to configure pin 53 as an output on Mega's to stop the SPI
     master potentially being configured as a slave by hardware.

You may copy, alter and reuse this code in any way you like, but please leave 
reference to HobbyComponents.com in your comments if you redistribute this code. 
This software may not be used directly for the purpose of selling products that 
directly compete with Hobby Components Ltd's own range of products.  

THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER 
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF 
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES, 
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY 
REASON WHATSOEVER.

*/

/* Include the serial library for communicating with the COM port */
#include <SPI.h>

/* Include the standard Ethernet library */
#include <Ethernet.h>

/* Include the standard SD card library */
#include <SD.h>

/* DIO pin used to control the modules CS pin */
#define SD_CARD_CD_DIO 4 

File SDFileData;


/* MAC address of the Ethernet shield. If you are using this on your 
own network, then the MAC address below will be fine, but remember if 
you use more than one shield on your network they will need to be assigned
unique MAC addresses */
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

/* The IP address of the shield. Make sure this matches the IP 
   address range of your network and is not in use by any other 
   device on it */    
IPAddress ip(192, 168, 1, 55 );

/* The port number the shield will respond to. Use port 80 
   for standard HTTP requests */
EthernetServer server(80);



void setup()
{  
  //pinMode(53, OUTPUT); //Uncomment this line if using a Mega
  /* Start the Ethernet interface */
  Ethernet.begin(mac, ip);
  server.begin();

  /* DIO pin used for the CS function. Note that even if you are not driving this
     function from your Arduino board, you must still configure this as an output 
     otherwise the SD library functions will not work. */
  pinMode(10, OUTPUT);

  
  /* Initialise the serial port */
  Serial.begin(9600);

  /* Initialise the SD card */
  if (!SD.begin(SD_CARD_CD_DIO)) 
  {
    /* If there was an error output this to the serial port and go no further */
    Serial.println("ERROR: SD card failed to initialise");
    while(1);
  }else
  {
    Serial.println("SD Card OK");
  }

}


/* MAIN PROGRAM LOOP */
void loop()
{
  /* All client requests are terminated with a blank line. This flag will 
    signify if the current line received from this client is a blank line */
  boolean bBlankLineFlag = true;
  
  /* Used to hold the current byre received from the client */
  char cCurrentByte;
  
  /* Used to hold the current byte read from the test.txt file located on the SD card */
  char cCurrentSDByte;
    
  
  /* Wait for a request from a client */
  EthernetClient ethernet = server.available();
  
  if (ethernet) 
  {
    /* Continue to read data from the client one byte at a time until 
       there is no more data */ 
    while (ethernet.connected()) 
    {
      /* Is there still data available to be read? ethernet class 
         ethernet.connected() returns the number of bytes available */
      if (ethernet.available()) 
      {
        /* If data is available read the next byte */ 
        cCurrentByte = ethernet.read();

        /* Is the next byte read is a new line termination ? */      
        if (cCurrentByte == '\n')
        { 
          /* If so was it a blank line? */
          if (bBlankLineFlag) 
          {
            
            /* If it was then we can now send a response to the client’s http request... */
            ethernet.println("HTTP/1.1 200 OK");
            ethernet.println("Content-Type: text/html");
            ethernet.println();

            ethernet.println("<body>");
            ethernet.println("<big><span style=\"font-weight: bold;\">www.hobbycomponents.com Ethernet Shield Example</span></big><br>");
            ethernet.println("****************************************************<br>");

            /* ...and the append the contents of the text.txt file */
  
            SDFileData = SD.open("test.txt");
    
 
            /* Sequentially read the data from the file until there is no more data available */
            while (SDFileData.available())
            {
              cCurrentSDByte = SDFileData.read();
             
              /* Check if the current byte is a line break ASCII and if so send an HTML line break */
              if (cCurrentSDByte == '\n')
              {
                ethernet.println("<br>");
              }else
              {
                /* If not then just send it to the client */
                ethernet.print((char)cCurrentSDByte);
              }
            }
     
            /* Close the file */
            SDFileData.close();  
           
            ethernet.println("</body>");

            /* Disconnect from the client */
            ethernet.stop();
          }
        
          /* The last byte received from the client was the start of a 
             new line so flag as no data received for this line yet */
          bBlankLineFlag = true;
        
        /* If the last byte received wasn't a new line then it must be data... */  
        } else if (cCurrentByte != '\r')
        {  
          /* ...and so flag this as not a blank line. */
          bBlankLineFlag = false;
        }
      }
    }
  }
}



FAQ:

The main chip (Wiznet W5100) on my shield has solder bridges on some of the pins, is it faulty?

This is quite normal and is just where two or more adjacent pins (normally unused or ground pins) share the same pad area which effectively shorts these pins together. As a result the solder naturally flows between these pins making it appear that the short is not intentional. You can reference the image below of a working shield to confirm your board is ok.

Image
You do not have the required permissions to view the files attached to this post.

OptoLcd
Posts: 2
Joined: Tue Apr 23, 2013 7:04 am

Re: Arduino Ethernet W5100 Network Shield (HCARDU0034)

Post by OptoLcd » Tue Apr 23, 2013 9:25 am

Hello,

Can you verify that no modifications need to be made on the Mega 2560 when connected to the above shield.
With the Ethernet shield connected to my Macbook using the Arduino Files/ Examples/Ethernet DHCPAddressPrinter sketch I get "failed to configure Ethernet using DHCP". I see the leds flashing on the shield when connected.

Thanks in advance.

admin
Site Admin
Posts: 866
Joined: Sun Aug 05, 2012 4:02 pm

Re: Arduino Ethernet W5100 Network Shield (HCARDU0034)

Post by admin » Tue Apr 23, 2013 4:24 pm

Hi,

Yes, this shield will work with one of our Megas without requiring modification. Have you tried our above Analogue Input Example? This is a known working program and will help eliminate any software issues.

Andrew

filou59
Posts: 1
Joined: Wed Apr 24, 2013 2:15 pm

Re: Arduino Ethernet W5100 Network Shield (HCARDU0034)

Post by filou59 » Wed Apr 24, 2013 5:49 pm

Hello

This shield work on Arduino MEGA 2560 R3, but Analogue Exemple works only with Uno card.

The code don't work because SS Pin is on 53 on Mega , 10 on Uno. Other SPI are on ICSP-1,ICSP-3 and ICSP-4 for : Uno/Due/Mega/Leonardo
http://arduino.cc/en/Reference/SPI
http://arduino.cc/en/Reference/SPI wrote:SPI library supports only master mode, this pin should be set always as OUTPUT otherwise the SPI interface could be put automatically into slave mode by hardware, rendering the library inoperative.

It is, however, possible to use any pin as the Slave Select (SS) for the devices. For example, the Arduino Ethernet shield uses pin 4 to control the SPI connection to the on-board SD card, and pin 10 to control the connection to the Ethernet controller.
In the Analogue Example change the void setup and add :
pinMode(53, OUTPUT);

like this :

Code: Select all

void setup()
    {
      pinMode(53, OUTPUT);
      Ethernet.begin(mac, ip);
      server.begin();
    }
Voilà ^^

admin
Site Admin
Posts: 866
Joined: Sun Aug 05, 2012 4:02 pm

Re: Arduino Ethernet W5100 Network Shield (HCARDU0034)

Post by admin » Thu Apr 25, 2013 9:18 am

Thanks for this information although I have to say it has had me scratching my head this morning. Just to confirm, we have tested the above code on both our 2011 and R3 Mega’s on numerous occasions and we have not seen any case where the shield failed to work.

However I’ve had a look at the Atmel datasheet and it confirms that if this pin is configured as an input and somehow was to be pulled low (?), it would be interpreted as another master on the bus attempting to communicate. This would cause the hardware to switch theSPI mode form a master to a slave. When this pin is configured as an output it has no effect on the SPI system.

So in summary there is a condition where by not configuring this pin as an output on a Mega could cause the shield to suddenly stop working. But the confusing thing is that there is nothing directly connected to pin 53 that could potentially drive the pin low (other than external noise).
I’ve updated the code to include this line as I agree that it should be set to an output to stop any potential issues like this.
Is there anything special about your setup that could cause pin 53 to be driven low? Did you purchase your shield and Mega from us (i.e. are they the same make) ?

Andrew

OptoLcd
Posts: 2
Joined: Tue Apr 23, 2013 7:04 am

Re: Arduino Ethernet W5100 Network Shield (HCARDU0034)

Post by OptoLcd » Thu Apr 25, 2013 9:30 am

Hello Andrew.

Thanks for the reply.
I have got the shield working on the Uno and a Mega 2560 clone so I am very happy.
Used a different code example but my initial problem was incorrect IP.
I did not have to do any configuration with the exception of the IP address.
When I get a chance I will test your code.

Cheers,

Austin

neilk48
Posts: 4
Joined: Tue Jul 23, 2013 4:43 pm

Re: Arduino Ethernet W5100 Network Shield (HCARDU0034)

Post by neilk48 » Wed Jul 24, 2013 10:35 am

Arrived today and can't get it to work :( with both an R2 and an R3 Arduino Uno

I tried the first sketch provided here and several of the examples provided in the standard Arduino 1.05 ethernet library.

Where error checking is present - ie the library examples - I get "WiFi Shield not present" on the serial monitor.

Any advice please?

andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: Arduino Ethernet W5100 Network Shield (HCARDU0034)

Post by andrew » Wed Jul 24, 2013 12:01 pm

Could you possible confirm a few things for us...

That you have tried the Analogue Input Example?
By not working, do you mean you are not getting a webpage in a browser?
How are you powering the uno and shield?
Have you have changed the IP address within the sketch to match your networks subnet and that it is not in use by any other device on your network?
Do you see any LED's illuminate/Flash on the shield and could you describe them?

The error message is a bit weird but for the purpose of debugging the problem it is best to stick to out Analogue Input Example as this is a known working program.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

neilk48
Posts: 4
Joined: Tue Jul 23, 2013 4:43 pm

Re: Arduino Ethernet W5100 Network Shield (HCARDU0034)

Post by neilk48 » Wed Jul 24, 2013 1:03 pm

Many thanks for the quick response
andrew wrote:Could you possible confirm a few things for us...

That you have tried the Analogue Input Example? - Yes I have
By not working, do you mean you are not getting a webpage in a browser? that is correct; I can't even connect to the relevant IP address with either Chrome or IE. .
How are you powering the uno and shield? Via the USB socket
Have you have changed the IP address within the sketch to match your networks subnet and that it is not in use by any other device on your network? I can confirm that the IP address within the sketch matches my network and is not already in use.
Do you see any LED's illuminate/Flash on the shield and could you describe them? An amber LED, with a letter "L" printed under, flashes 3 times after reset and then is permanently lit when the sketch is running and a red LED labelled pwr is also permanently lit
I tried the example sketches because they checked for the shield presence or working

neilk48
Posts: 4
Joined: Tue Jul 23, 2013 4:43 pm

Re: Arduino Ethernet W5100 Network Shield (HCARDU0034)

Post by neilk48 » Wed Jul 24, 2013 1:41 pm

OOPS sorry for the confusion - I was trying the WiFi examples, not the simple ethernet examples. They don't work either

Post Reply

Return to “Arduino Shields”