Ethernet.begin(mac) hangs indefinitely

So i tried to use the DhcpAddressPrinter demo from the Ethernet library however the Serial seems to hang indefinitely after it executes Ethernet.begin(mac) and would not continue to the next line even after 4 hours. Im using an EtherMega 2560 and there is currently no SD or MicroSD card attached to the Mega and the DHCP server is currently up and running for my ethernet connection. So any help would be greatly appreciated.

/*
DHCP-based IP printer

This sketch uses the DHCP extensions to the Ethernet library
to get an IP address via DHCP and print the address obtained.
using an Arduino Wiznet Ethernet shield.

Circuit:

  • Ethernet shield attached to pins 10, 11, 12, 13

created 12 April 2011
modified 9 Apr 2012
by Tom Igoe

*/

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

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
};

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println(“Failed to configure Ethernet using DHCP”);
// no point in carrying on, so do nothing forevermore:
for (;:wink:
;
}
// print your local IP address:
Serial.print(“My IP address: “);
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(”.”);
}
Serial.println();
}

void loop() {

}

Hello Ocsyscleen,

what do you mean by "Serial seems to hang indefinitely" ?

Do you see the message printed in loop ?
Or is your program blocked in the "Ethernet.begin()" function call ?
or do you get the DHCP error message ?

If it blocks in the function, it means that you probably have a communication problem between the shield and the Arduino (shield badly inserted, shield damaged, Arduino damaged... generally an hardware problem)

You may have a DHCP server not working, or it can be a network issue, etc... I need to know what you get on the console to have an idea of what could be wrong

Benoit

Naveen_prasath:
hai ,

i m using ENC28j60 module and i want this to work in my own Local network without using the internet

i have directly connected the one end of the LAN cable to module and other end directly to the computer's LAN port.

i want this to work like when i visit the IP address of this module in my browser, this should display the output.

please help..

Naveen,

as far as I can see, your problem is not related to Ocsycleen at all. You should create a new question for that, you will have no chance to get an answer if you post your own question as a reply to a problem of somebody else.

Anyway, about your problem, you simply ask to create a webserver... So, first, you need to learn how to include the 28J60 in your code (libray import, then create a startup program)
Then you will need to use the IP stack to create a TCP socket
And then you will need to write a HTTP server handler.

This is a big work, you need to do it step by step, you will not find somebody here who will provide you directly a source code for that

Benoit

Naveen: As BenKissBox wrote, you have to open a new case with your problem.
There are a lot of examples on the net, so it's not so scary as BenKissBox writes.
In the mean time you can Google for libraries and examples for the ENC28J60.
Some of the libraries : etherShield.h, ETHER_28J60.h, EtherCard.h
Good luck.

BenKissBox:
Hello Ocsyscleen,

what do you mean by "Serial seems to hang indefinitely" ?

Do you see the message printed in loop ?
Or is your program blocked in the "Ethernet.begin()" function call ?
or do you get the DHCP error message ?

If it blocks in the function, it means that you probably have a communication problem between the shield and the Arduino (shield badly inserted, shield damaged, Arduino damaged... generally an hardware problem)

You may have a DHCP server not working, or it can be a network issue, etc... I need to know what you get on the console to have an idea of what could be wrong

Benoit

Thank you for your response. So what happened was that the program gets stuck in Ethernet.begin() function call so that nothing after the line with Ethernet.begin() would be executed (not even the DHCP error message). I am connecting my etherMega to my rented verizon Fios router, is there a possibility for the Fios router to have some hidden encryption that prevents the connection?

Ocsycleen:
Thank you for your response. So what happened was that the program gets stuck in Ethernet.begin() function call so that nothing after the line with Ethernet.begin() would be executed (not even the DHCP error message). I am connecting my etherMega to my rented verizon Fios router, is there a possibility for the Fios router to have some hidden encryption that prevents the connection?

I do not think that your router is encrypting anything. If you stay blocked in the Ethernet.begin(), it means that the Arduino is unable to detect that the W51000 has been reset properly or that it can not get an IP address.

Can you make a test using the static IP address mode? Check if the Ethernet.begin() exits in this case. If it exits, it means that you have a DHCP server issue (the DHCP server does not want to allocate an IP address to the Arduino)
If the function does not exit when you are in static IP mode, then you have probably a broken Ethernet shield and/or an hardware problem with the Arduino itself (SPI not communicating properly)

And check also that you do not have multiple devices in your network using the same MAC address (the address you use seems not very "common" LOL). If you use the same MAC address on different test devices, then the network will fail because it will not be able to send the messages to the correct devices

Benoit

I think i found out the problem. As soon as i removed my Nextion TFT LCD display, it works perfectly. But is there a way i can use the ethernet library and the LCD display at the same time?