UdpNtpClient example and arduino ethernet

I'm trying out the UdpNtpClient example, but it does not work. I have connected the Arduino Ethernet to the USB/Serial Light Adapter, and I made no modifications to the example.

Sometimes is says on serial: Seconds since Jan 1 1900 = 0 Unix time = 2085978496 The UTC time is 6:28:16

Most times: Failed to configure Ethernet using DHCP

When I connect my 12VDC supply as well, it always says: Seconds since Jan 1 1900 = 0 Unix time = 2085978496 The UTC time is 6:28:16

I can't figure out where this comes from, I tested with my laptop, syncing the time against the same ntp server, works fine. DHCP is working fine, 100% sure.

I tested pinging the time.nist.gov server using the cable from the arduino, 100% ok. (with my laptop, wifi off)

The ethernet chip is getting hot, I guess 40/50 C, but that is normal as far i can find with google.

Can anybody point out a new idea?

Is there a microSD card in the slot?

Yes, is there, but unused by UdpNtpClient example.

SjoerdNLD: Yes, is there, but unused by UdpNtpClient example.

That doesn't matter. If the microSD card is in the slot, it is active. You must disable the SD SPI, or it will trash up your w5100 traffic.

If you doubt me, power down the Arduino, remove the SD card, power it up, then try it again. There will be no problem then.

Thanks SurferTim, will try this evening.

Tried - works instantly. XD

Uh, is there a work around for this ? I'm attempting to build a home energy monitor and would like to query the NTP servers a couple times a day but also write files to the SD card. Other option just to buy an RTC ? or use the Time library ?

You can use both together. This is how I start them so they will work together in the UdpNtpClient sketch.

#include <SPI.h>         
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SD.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[] = {  
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

unsigned int localPort = 8888;      // local port to listen for UDP packets

IPAddress timeServer(192, 43, 244, 18); // time.nist.gov NTP server

const int NTP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the message

byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets 

// A UDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() 
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);

  // disable w5100 while starting SD  
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);

  Serial.print(F("Starting SD..."));
  if(!SD.begin(4)) Serial.println(F("failed"));
  else Serial.println(F("ok"));

  // start Ethernet and UDP
  Serial.print(F("Starting w5100..."));
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }
  Serial.println(Ethernet.localIP());
  Udp.begin(localPort);
}

// rest of the code

Thanks Tim :)