Go Down

Topic: ethernetshield wont connect with the internet. (Read 221 times) previous topic - next topic

bask185

I bought an original arduino ethernet shield v2. http://www.sgbotic.com/images/detailed/10/01844-01.jpg

Not knowing that the sticker on the back contained something called a MAC address, I tossed it away.....:smiley-confuse:

At the moment I'm trying to this code
Code: [Select]
#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.
// gateway and subnet are optional:
byte mac[] = { 0xA1, 0xA2, 0xD3, 0xC3, 0xF1, 0x2A };
IPAddress ip(192, 168, 1, 118);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);

// telnet defaults to port 23
EthernetServer server(23);
boolean gotAMessage = false; // whether or not you got a message from the client yet

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
 
  // start the Ethernet connection:
  Serial.println("Trying to get an IP address using DHCP");
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // initialize the ethernet device not using DHCP:
    Ethernet.begin(mac, ip, gateway, subnet);
  }
  // print your local IP address:
  Serial.print("My IP address: ");
  ip = Ethernet.localIP();
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(ip[thisByte], DEC);
    Serial.print(".");
  }
  Serial.println();
  // start listening for clients
  server.begin();

}

void loop()
{
  // wait for a new client:
  EthernetClient client = server.available();

  // when the client sends the first byte, say hello:
  if (client) {
    if (!gotAMessage) {
      Serial.println("We have a new client");
      client.println("Hello, client!");
      gotAMessage = true;
    }

    // read the bytes incoming from the client:
    char thisChar = client.read();
    // echo the bytes back to the client:
    server.write(thisChar);
    // echo the bytes to the server as well:
    Serial.print(thisChar);
  }
}


I have tried several MAC adresses, from example sketches, from whatever I could find. The current one in the code is a random one.

The arduino never gets past the setup code, I have enclosed a screenshot of the output
(COM output.png).

My first question: Do I have to use the MAC address of the lost sticker persé or can I assign and use other random MAC-adresses as well? I read that this address was hardwired into the shield.

I can propably figure out a for-loop where I test every possible MAC-address.. but 16^12 = 2.8^14 and millis() can get as high 4.29^9 < and this takes 50 days worth of milli seconds. It takes about 300 ms to test a mac address  :smiley-sad-blue:

I also have another question concerning IP-addresses.

I have enclosed another screenshot of the IPconfig out in cmd.exe. I know that my subnet mask is 255.255.255.0 and the gateway is indeed 192.168.1.1. But I do not know of what the IPv4-address is. It is 192.168.1.117. When I looked up the Ip adress of my PC on the internet I got an entire other IP-address

question 2: in IPAddress ip() which IP-adresses can I use? do the first 2 numbers have to be 192.168.xxx.xxx or does it not matter?


SurferTim

Quote
The arduino never gets past the setup code, I have enclosed a screenshot of the output
That screenshot is of your ipconfig on your PC.

Does your ethernet shield have a w5200 IC on it? If so, you must use a library for the w5200.
https://github.com/Seeed-Studio/Ethernet_Shield_W5200

bask185

That screenshot is of your ipconfig on your PC.
I though I added 2 screenshots, 1 of the ipconfig and one of the serial monitor.

The chip I have is a W5500.

SurferTim

Then you should try a library for the w5500 IC. The standard library included with the IDE will not work with the w5500. I have heard that the w5200 library from Seeed Studios will work with the w5200 and the w5500.

bask185

I installed the other library but I cant get anything to work

bask185

Code: [Select]
Ethernet.begin(mac);

this line of code makes the entire program stop.

If I put a print function behind it, I dont see anything printed

SurferTim

It will take about 2 minutes for a return value from that function if the dhcp service fails.

It will also fail if there is a SD card in the shield's slot and you have not disabled its SPI.

bl0w

I had this problem too some time ago.

To work with that shield you can download the IDE from arduino.org and it comes with the library to work with wiznet5500.

bask185

Guys I need an answer on my question about the mac adress. I read that newer board such as mine has a hard wired mac adress. Is there a way to set a new one or read it out somehow?

Now I have lost this adress. Can I still use the ethernet shield or can I get a hammer and smash my board which costed me €35,- to $h!T??

PaulS

Quote
Guys I need an answer on my question about the mac adress. I read that newer board such as mine has a hard wired mac adress. Is there a way to set a new one or read it out somehow?
The MAC address is defined in the code. It is NOT hardcoded in the Ethernet Shield.

Quote
Can I still use the ethernet shield or can I get a hammer and smash my board which costed me €35,- to $h!T??
Yes, you can. Whichever will make you feel better. The MAC address simply needs to be unique ON YOUR NETWORK. So, check the address of some other computer to get the format (6 bytes) and make up different values for a couple of the fields.

bask185

I now use this library https://github.com/Wiznet/WIZ_Ethernet_Library, I followed the instruction to install it correctly

Quote
Download all files and replace the "\libraries\Ethernet\src" folder in your Arduino IDE. This will update the "utility" folder also under "\libraries\Ethernet\src".
removed the original src file and placed the new one from the wiz library there

Quote
In the W5100.h file(\libraries\Ethernet\utility\w5100.h), uncomment the device(shield) you want to use.
done that

Quote
By default, "WIZ550io_WITH_MACADDRESS" is commented and if you uncommnet it, you can use the MAC address stored in the WIZ550io.
also done this.

the examples have all this line of code, by doing the previous step ^  ^  this should use the default MAC address 
Code: [Select]
#if defined(WIZ550io_WITH_MACADDRESS) // Use assigned MAC address of WIZ550io
;
#else
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
#endif


I am still no where, I do every tutorial I can find and I cant get no connection. I am also unable to find the ethernet shield in the network devices on my PC. Both PC and shields are plugged in the same router. If I try the dhcp address printer example, I get:
Quote
Failed to configure Ethernet using DHCP
if I try the Web server example I get
Quote
server is at 0.0.0.0

PaulS

Quote
I am also unable to find the ethernet shield in the network devices on my PC.
I'll bet you can't find mine, either. Why would you expect to?

Quote
Failed to configure Ethernet using DHCP
It's far simpler to configure your router to assign a static IP address (the same one every time) to the Arduino. Why not try that before trying to get dynamic addressing working?

bask185

#12
Jul 28, 2015, 05:33 pm Last Edit: Jul 28, 2015, 06:08 pm by bask185
I do get a reply when I ping the shield using the cmd,

But when I try the webserver example I still cant find the page, tried both google chrome and internet explorer. I get ERR_CONNECTION_REFUSED instead of a timeout, so atleast I'm doing something right -_-

bask185

Yo I fixed it, 1 week of my life is gone, but i fixed it. The SS of the sd card wasn't written high in the demo sketch -_- , when I pulled my SD card out, I got almost a heart attack when 5 sensor readings popped up on my screen, and the serial monitor was filled with text,

Tnx alot for the help PaulS  ;)  

...I go kill myself now  :smiley-cry: .....

SurferTim

#14
Jul 28, 2015, 07:08 pm Last Edit: Jul 28, 2015, 07:09 pm by SurferTim
You should have read reply #6 better. ;)

Go Up