I also have this issue. I have an Arduino Mega2560 with ethernet shield on top, headers on top of that, sainsmart 1602 lcd w/keypad on top of that. When I try to use both shields, it immediately fails on grabbing DHCP. Here is my code:
#include <DNS.h>
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SD.h>
#include <Time.h>
#include <Timezone.h>
#include <LiquidCrystal.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
unsigned int localPort = 8888;
IPAddress timeServer(172, 16, 0, 4);
const int NTP_PACKET_SIZE = 48;
byte packetBuffer[NTP_PACKET_SIZE];
EthernetUDP Udp;
int timeZoneHour = -5;
long timeZoneOffset = (timeZoneHour * -1) * 60 * 60;
int NTP_UPDATE_INTERVAL = 10;
int counter = 0;
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
void resetSauce() {
void (*softReset) (void) = 0; //declare reset function @ address 0
softReset();
}
unsigned long sendNtpPacket(IPAddress& address) {
memset(packetBuffer, 0, NTP_PACKET_SIZE);
packetBuffer[0] = 0b11100011;
packetBuffer[1] = 0;
packetBuffer[2] = 6;
packetBuffer[3] = 0xEC;
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;
Udp.beginPacket(address, 123);
Udp.write(packetBuffer,NTP_PACKET_SIZE);
Udp.endPacket();
}
unsigned long grabNtpTime() {
Serial.print("GRABBING NTP FROM ");
Serial.println(timeServer);
counter = 0;
sendNtpPacket(timeServer);
delay(1);
if (!Udp.parsePacket()) {
Serial.println("No NTP packet found");
return 0;
}
Serial.println("SUCCESS");
Udp.read(packetBuffer, NTP_PACKET_SIZE);
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
unsigned long secsSince1900 = highWord << 16 | lowWord;
const unsigned long seventyYears = 2208988800UL + timeZoneOffset;
unsigned long epoch = secsSince1900 - seventyYears;
return epoch;
}
void printDigits(int digits) {
if (digits < 10) {
lcd.print('0');
}
lcd.print(digits);
}
void printDayOfWeek(int digits) {
if (digits == 1) { lcd.print(" SUN"); }
else if (digits == 2) { lcd.print(" MON"); }
else if (digits == 3) { lcd.print(" TUE"); }
else if (digits == 4) { lcd.print(" WED"); }
else if (digits == 5) { lcd.print(" THU"); }
else if (digits == 6) { lcd.print(" FRI"); }
else if (digits == 7) { lcd.print(" SAT"); }
}
void printDateTime() {
time_t eastern, utc;
TimeChangeRule *tcr;
TimeChangeRule usEDT = {"EDT", Second, Sun, Mar, 2, -240};
TimeChangeRule usEST = {"EST", First, Sun, Nov, 2, -300};
Timezone usEastern(usEDT, usEST);
utc = now() + 2;
eastern = usEastern.toLocal(utc, &tcr);
printDayOfWeek(weekday(utc));
lcd.print(" ");
printDigits(hourFormat12(utc));
lcd.print(":");
printDigits(minute(utc));
lcd.print(":");
printDigits(second(utc));
if (isAM()) {
lcd.println(" AM");
} else {
lcd.println(" PM");
}
//Serial.println(tcr->abbrev);
}
void setupTime() {
setSyncProvider(grabNtpTime);
}
void setup() {
Serial.begin(9600);
if (!Ethernet.begin(mac)) {
lcd.println("DHCP FAILED");
for(;;);
}
Udp.begin(localPort);
lcd.print("IP Address [DHCP]: ");
lcd.println(Ethernet.localIP());
setupTime();
}
void loop() {
printDateTime();
delay(1000);
}