Tiny RTC messing with EthernetServer

I created a long sketch using an EthernetServer to put values inside a table.
The program takes an HTML/JavaScript code from an SD card and prints it using values stored in Arduino.
All was working fine, then I tried adding a line to obtain the current time from a Tiny RTC:

DateTime now = RTC.now();

Just this line doesn’t let me send the values stored in Arduino to the web page.
The sketch compiles anyway.
I was wondering if there is anything in the RTC library that conflicts with EthernetServer or SD?

This is just an example, I would send the complete code via private message if needed.

#include <Ethernet.h>
#include <SD.h>
#include <Wire.h>
#include <RTClib.h>

RTC_DS1307 RTC;
byte mac[] = { 0x**, 0x**, 0x**, 0x**, 0x**, 0x** };
IPAddress ip(192, 168, 1, 32);
EthernetServer server(80);

void setup() {
  Wire.begin();
  RTC.begin();
  if (! RTC.isrunning()) {
    Serial.begin(9600);
    Serial.println("RTC is NOT running!");
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
  Ethernet.begin(mac, ip);
  server.begin();
}

void loop() {
  //This line makes my code go bye-bye
  //DateTime now = RTC.now();

  EthernetClient client = server.available();
  if(client){
    char c;
    String message = "";
    while(client.connected()){
      if(client.available()){
        c = client.read();
        message += c;
        if(c == '\n'){
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println("Hello world");
          client.println("</html>");
        }
      }
    }
  }
}

What type of Arduino are you using? How did you wire it?

Does the problem show up with the above example sketch too or just with your long sketch?

I’m guessing a memory problem as you’re wasting memory by not using the F() macro and using the String class.

  if (! RTC.isrunning()) {
    Serial.begin(9600);
    Serial.println("RTC is NOT running!");
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
  Wire.begin();
  RTC.begin();

It’s not wise using the RTC object before calling it’s begin() method. You don’t have to call Wire.begin() as it’s being called in RTC.begin().

pylon:
What type of Arduino are you using? How did you wire it?

Does the problem show up with the above example sketch too or just with your long sketch?

I'm guessing a memory problem as you're wasting memory by not using the F() macro and using the String class.

It's not wise using the RTC object before calling it's begin() method. You don't have to call Wire.begin() as it's being called in RTC.begin().

Thanks for replying
Sorry, I just did wrong when I was transcribing the code. In my sketch begin() is before any use of RTC.
I'm using an Arduino Ethernet.
The RTC is connected to analogig pins 4(SDA) and 5(SCL), 5V and GND.
In this one the problem doesn't show up, I posted it just to know if somebody else also had troubles with this.
I don't think it's a memory problem (even though I get a memory alert) because I also tried to remove some lines using a big amount of memory, but the problem triggers only when that DateTime now = RTC.now() is used.
That was why I said I would send the complete code via private message if needed, because it's long and contains also html, css and JavaScript code.
It's weird because the sketch using only EthernetServer works fine, and same thing for the sketch using only RTC.

I don't think it's a memory problem (even though I get a memory alert) because I also tried to remove some lines using a big amount of memory, but the problem triggers only when that DateTime now = RTC.now() is used.

I'm quite sure now that it's a memory problem.

It's weird because the sketch using only EthernetServer works fine, and same thing for the sketch using only RTC.

Did you try the above sketch (the short one) with the RTC.now() line commented in? If that works it's most probably a memory problem.

Remember that using the SD card library (without any additional code) uses more than a quarter of the memory the Arduino Ethernet owns.

Maybe I'm misinterpreting your post. I do understand that if the line is compiled in that the program freezes. You're description of the symptoms are not very detailed so my interpretation might be wrong. If it doesn't freeze, describe in detail what happens. And post your complete sketch. We probably don't need the files on the SD card but post the code that you compile in the IDE and upload to the Arduino.

That was why I said I would send the complete code via private message if needed, because it's long and contains also html, css and JavaScript code.

It has been suggested that you try some smaller code. If you won't, then you'll need to deal with the problem yourself.

If you do use simpler/smaller code, and still have a problem, post the code. If you do use simpler/smaller code, and the RTC works, then you've learned that you don't have a hardware problem.

Too little SRAM isn't a hardware problem. It means that you selected the wrong hardware, which is a problem, but that's not the same as a hardware problem. 8)