Beginner Ethernet Shield V1.1

Hello
I have given a project of communicating with PC from Arduino and with Arduino from PC over LAN using Ethernet Shield V1.1 and i have no knowledge regarding communication systems and IP address or some other address etc, i'm just stuck, please help me in its programming, i have seen the examples in IDE but didn't got any idea that whats going on in it. please help me out.

Regards
Saad Khalil.

First of what operating system are you running? windows, mac, linux?

If windows open a command prompt (start --> run --> type: cmd )

In the command prompt window type ipconfig /all

This will give output similar to this:

Ethernet adapter Local Area Connection 3:

        Connection-specific DNS Suffix  . :
        Description . . . . . . . . . . . : D-Link DUB-E100 USB 2.0 Fast Etherne
t Adapter
        Physical Address. . . . . . . . . : 00-80-C8-38-F6-7C
        Dhcp Enabled. . . . . . . . . . . : Yes
        IP Address. . . . . . . . . . . . : 192.168.10.200
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . : 192.168.10.1

Most important is ip Adress in this case 192.168.10.200. We need an unique address for the arduino, so we add 1 to the last number: 192.168.10.201

We still need to know if this address is free so the next command we type is ping 192.168.10.201

C:\>ping 192.168.10.201

Pinging 192.168.10.201 with 32 bytes of data:

Request timed out.
Request timed out.
Request timed out.
Request timed out.

Ping statistics for 192.168.10.201:
    Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),

We get a timeout so the address is free.
Now open webserver example and search for the part shown below

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,1, 177 };

Change the ip adress to your newly created address.
In this example that would be:

byte ip[] = { 192,168,10, 201 };

Download the code to your arduino.
Now open your web browser and type in the following adress http://192.168.10.201 and see the magic.

Hope this helps to get started.

Hi

i am also new to Ethernet Shield. I am doing Home Automation Project where i will be controlling LED's using web server. Even tho i have got the code for controlling LED's i can't understand how the code works. Here is the code.
#include <SPI.h>
#include <Client.h>
#include <Ethernet.h>
#include <Server.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1,2 }; // ip in lan
byte gateway[] = { 192, 168, 0, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
Server server(80); //server port
byte sampledata=50; //some sample data - outputs 2 (ascii = 50 DEC)
int ledPin = 13; // LED pin
char link[]="http://www.scienceprog.com/"; //link data
String readString = String(30); //string for fetching data from address
boolean LEDON = false; //LED status flag
void setup(){
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
//Set pin 4 to output
pinMode(ledPin, OUTPUT);
//enable serial datada print
Serial.begin(9600);
}
void loop(){
// Create a client connection
Client client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100)
{
//store characters to string
readString += c; //replaces readString.append(c);
}
//output chars to serial port
Serial.print(c);
//if HTTP request has ended
if (c == '\n') {
//dirty skip of "GET /favicon.ico HTTP/1.1"
if (readString.indexOf("?") <0)
{
//skip everything
}
else
//lets check if LED should be lighted
if(readString.indexOf("L=1") >0)//replaces if(readString.contains("L=1"))
{
//led has to be turned ON
digitalWrite(ledPin, HIGH); // set the LED on
LEDON = true;
}else{
//led has to be turned OFF
digitalWrite(ledPin, LOW); // set the LED OFF
LEDON = false;
}
// now output HTML data starting with standart header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
//set background to yellow
client.print("");
//send first heading
client.println("

HTTP test routines

");
client.println("
");
client.println("
");
//output some sample data to browser
client.println("Sample data: ");
client.print(sampledata);//lets output some data
client.println("
");//some space between lines
client.println("
");
//drawing simple table
client.println("Simple table: ");
client.println("
");
client.println("");
client.println("
row 1, cell 1 row 1, cell 2
row 2, cell 1 row 2, cell 2
");
client.println("
");
client.println("
");
//printing some link
client.println("Link: ");
client.print("Visit Scienceprog!");
client.println("
");
client.println("
");
//controlling led via checkbox
client.println("

LED control

");
//address will look like http://192.168.1.110/?L=1 when submited
if (LEDON)
client.println("LED
");
else
client.println("LED
");
client.println("
");
//printing LED status
client.print("LED status: ");
if (LEDON)
client.println("ON");
else
client.println("OFF");
client.println("
");
client.println("
");
client.println("");
//clearing string for next read
readString="";
//stopping client
client.stop();
}
}
}
}
}

Could you please explain me how the code works. Or could you teach me step by step process of how to work with Ethernet Shield? I understand how to setup the ip address. Just teach me about client and server and how to communicate.

Thanks in advance !!!!!!!!

I have given a project of communicating with PC from Arduino and with Arduino from PC

If the PC and the Arduino are the only devices involved, a cable is a lot cheaper and easier to use. Why is the Ethernet shield involved at all?

If you know nothing about network programming, this job is too big for you.

Some simple server code that will will make arduino pin 4 high and low from a simple web page.

//zoomkat 12-18-10
//routerbot code
//for use with IDE 0021
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html 
//address will look like http://192.168.1.102:84/ when submited
//for use with W5100 based ethernet shields

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
Server server(84); //server port

String readString; 
 
 //////////////////////

void setup(){

pinMode(4, OUTPUT); //pin selected to control
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();

//enable serial data print 
Serial.begin(9600); 
Serial.println("servertest1"); // so I can keep track of what is loaded
}

void loop(){
// Create a client connection
Client client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();

//read char by char HTTP request
if (readString.length() < 100) {

//store characters to string 
readString += c; 
//Serial.print(c);
} 

//if HTTP request has ended
if (c == '\n') {

///////////////
Serial.println(readString);

  //now output HTML data header

  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println();

client.println("<HTML>");
   client.println("<HEAD>");
     client.println("<TITLE>Arduino GET test page</TITLE>");
   client.println("</HEAD>");
   client.println("<BODY>");
    
    client.println("<H1>HTML form GET example</H1>");

    client.println("<FORM ACTION=\"http://192.168.1.102:84\" method=get >");

    client.println("Pin 4 \"on\" or \"off\": <INPUT TYPE=TEXT NAME=\"LED\" VALUE=\"\" SIZE=\"25\" MAXLENGTH=\"50\">
");

        client.println("<INPUT TYPE=SUBMIT NAME=\"submit\" VALUE=\"Change Pin 4!\">");

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

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

  delay(1);
  //stopping client
client.stop();

/////////////////////
if(readString.indexOf("on") >0)//checks for on
           {
             digitalWrite(4, HIGH);    // set pin 4 high
             Serial.println("Led On");
             }
if(readString.indexOf("off") >0)//checks for off
           {
             digitalWrite(4, LOW);    // set pin 4 low
             Serial.println("Led Off");
             }
//clearing string for next read
readString="";
  
}}}}}

wortelsoft:
First of what operating system are you running? windows, mac, linux?

If windows open a command prompt (start --> run --> type: cmd )

In the command prompt window type ipconfig /all

This will give output similar to this:

Ethernet adapter Local Area Connection 3:

We still need to know if this address is free so the next command we type is ping 192.168.10.201

[code]C:>ping 192.168.10.201

Pinging 192.168.10.201 with 32 bytes of data:

Request timed out.
Request timed out.
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),




// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,1, 177 };[/code]

Change the ip adress to your newly created address.
In this example that would be:


byte ip[] = { 192,168,10, 201 };



Download the code to your arduino.
Now open your web browser and type in the following adress http://192.168.10.201 and see the magic.

Yes i'm having Windows, Thanks Wortelsoft.. i hope it will help me alot..

PaulS:
If the PC and the Arduino are the only devices involved, a cable is a lot cheaper and easier to use. Why is the Ethernet shield involved at all?
If you know nothing about network programming, this job is too big for you.

Thanks for Reply..
Let me clear my question again, actually i want to send some sensor data continuously to 'PC' far away with my friend via internet, with the help of my Ethernet, my PC and Arduino. Am i doing right? if yes please help me out, and yes i don't know about "Network programming" :~

...send some sensor data continuously to 'PC' far away with my friend via internet, with the help of my Ethernet, my PC and Arduino...

The good news: I tcan be done! And you've identified the way to do it.

The bad news?....

I don't know about "Network programming"...

You'll need to learn.

===
Half the problem is that you'll have to learn a whole bunch of things all at once... building and running a server (that topic alone has multiple sub-topics), HTML coding (you won't need more than a smattering)

The other half of the problem is at the receiving end. More details needed of the receiver's exact needs.

===
More good news... it CAN be done!! See http://ArduServer.com for some encouragement, some further information.

===

Does your friend need continuous access to what, say, the temperature is where you are just when he's curious? I.e. is it enough to set up a webpage which can be accessed anytime, and the webpage shows the temperature now? That's fairly easy.

Does your friend need a graph of what the temperatures (or whatever) have been for the past few days? Might be a job to do with a PC at your end, rather than just an Arduino. See Overview of FarWatch products- surveillance via internet

Another answer, which would need just Arduino and a lot of work (and an always-on internet connection) is Pachube... If your friend needs a graph of up to 30 days' data (longer if you pay... 30 day service is free). More on that at Pachube for Sensing and Control- SC1wy

tkbyd:

The good news: It can be done! And you've identified the way to do it.

WoW! Thanks for encouragement tkbyd..

More good news... it CAN be done!! See http://ArduServer.com for some encouragement, some further information.

i can see some helpful material for myself in it and hope that it 'll help me alot... and i 'll need youa help in future buddy.. So please stay tune to me.. Thanksss again