Go Down

Topic: arduino wiznet w5100 ethernet shield problem (Read 5 times) previous topic - next topic

julianiii

Oct 08, 2011, 05:17 pm Last Edit: Oct 08, 2011, 05:28 pm by julianiii Reason: 1
Hi guys i'm new in this. I have a ardiuno duemilanove and an ethernet shield w5100.
I can't get it work with my ardiuno . I can't ping the device i try to many times .
Help me.


This is the code i'm using.
/*
 Web  Server

A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.



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

// 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 };

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
Server server(80);

void setup()
{
 // start the Ethernet connection and the server:
 Ethernet.begin(mac, ip);
 server.begin();
}

void loop()
{
 // listen for incoming clients
 Client client = server.available();
 if (client) {
   // an http request ends with a blank line
   boolean currentLineIsBlank = true;
   while (client.connected()) {
     if (client.available()) {
       char c = client.read();
       // if you've gotten to the end of the line (received a newline
       // character) and the line is blank, the http request has ended,
       // so you can send a reply
       if (c == '\n' && currentLineIsBlank) {
         // send a standard http response header
         client.println("HTTP/1.1 200 OK");
         client.println("Content-Type: text/html");
         client.println();

         // output the value of each analog input pin
         for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
           client.print("analog input ");
           client.print(analogChannel);
           client.print(" is ");
           client.print(analogRead(analogChannel));
           client.println("<br />");
         }
         break;
       }
       if (c == '\n') {
         // you're starting a new line
         currentLineIsBlank = true;
       }
       else if (c != '\r') {
         // you've gotten a character on the current line
         currentLineIsBlank = false;
       }
     }
   }
   // give the web browser time to receive the data
   delay(1);
   // close the connection:
   client.stop();
 }
}

SurferTim

What is the ip and subnet of the computer that you are using for the ping attempt?

julianiii

#2
Oct 08, 2011, 06:03 pm Last Edit: Oct 08, 2011, 06:09 pm by julianiii Reason: 1
IP:192.168.1.184
Subnet mask: 255.255.255.0

I have both my pc and ardiuno in the same range

i also have enc28j60 ethernet shield and works perfect. Maybe is library problem with w5100. I use ardiuno 0022 software

zoomkat

Simple server code. If the arduino is connected to a router, then it may need to be specified as the gateway.

Code: [Select]

//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\"><BR>");

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

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

          client.println("<BR>");

          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="";

        }
      }
    }
  }
}

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

julianiii

#4
Oct 08, 2011, 06:16 pm Last Edit: Oct 08, 2011, 06:34 pm by julianiii Reason: 1
I try it but without success. I cant get it ping.
??

zoomkat

You probably need to detail your lan setup. If you try code that is not changed to match your lan, it probably won't work.
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)


SurferTim

#7
Oct 08, 2011, 07:03 pm Last Edit: Oct 08, 2011, 07:08 pm by SurferTim Reason: 1
You can try this. Compile and upload. Open the serial window and wait for "Tick Tick Tick".
Wait a few seconds, then try to ping 192.168.1.2
Code: [Select]
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x59, 0x66 };  
byte ip[] = { 192, 168, 1, 2 };    
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };

void setup()
{
 Serial.begin(9600);
 Ethernet.begin(mac, ip, gateway, subnet);
 delay(1000);
}

void loop()
{
 Serial.println("Tick");
 delay(1000);
}


Then try to ping 192.168.1.1, just as a test. Does it respond?

julianiii

Same problem.??

SurferTim

#9
Oct 08, 2011, 07:12 pm Last Edit: Oct 08, 2011, 07:16 pm by SurferTim Reason: 1
OK, tick is working, so it is not locking up. That is a good thing.

What is the router ip address for your localnet? Can you ping the router from the computer?
Is your router IP 192.168.1.157?

julianiii

#10
Oct 08, 2011, 07:17 pm Last Edit: Oct 08, 2011, 07:18 pm by julianiii Reason: 1
im in a domain network
yes i can ping router
router ip : 192.168.1.157 / 192.168.1.134


SurferTim

Your subnet is 255.255.255.0 on that network?
Have you tried a cable change?
Are both the computer and Arduino connected to the same port on the router? Like a switch? Or different ports?

julianiii

#12
Oct 08, 2011, 07:28 pm Last Edit: Oct 08, 2011, 07:29 pm by julianiii Reason: 1
yes my subnet is 255.255.255.0
yes i changed the cable and the pc, i even connected to the same switch. but is the same problem

i use the same configuration for enc28j60  ethernet shield and works fine

SurferTim

Let's see if the Arduino is actually talking to the shield. Compile and upload the following code. Open the serial window.
The first line of the serial responses should be the ip address you assigned to the shield.
Code: [Select]
#include <SPI.h>
#include <Ethernet.h>
#include <utility/w5100.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x59, 0x66 }; 
byte ip[] = { 192, 168, 1, 7 };   
byte gateway[] = { 192, 168, 1, 157 };
byte subnet[] = { 255, 255, 255, 0 };

byte ipBuf[4];
char outBuf[18];

void setup()
{
  Serial.begin(9600);
  Ethernet.begin(mac, ip, gateway, subnet);
  delay(1000);
  W5100.getIPAddress(ipBuf);
  sprintf(outBuf,"%u.%u.%u.%u\r\n",ipBuf[0],ipBuf[1],ipBuf[2],ipBuf[3]);
  Serial.write(outBuf);
}

void loop()
{
  Serial.println("Tick");
  delay(1000);
}

julianiii

No i dont get the ip from theserial responses

Go Up