Data from DHT22 and BMC085 gets cut in a long string

Hi!
I have a problem regarding my simple weather station. In my code, I have a loop that saves data from sensors into a string. Each line in the string is one run through the loop consisting of: date and time from RTC DS1307, humidity and temperature from DHT22 and temperature and pressure from BMP085. In the present version the loop runs 8 times, then the whole 8-line string is tranferred to the screen through the Serial port.
What troubles me is what I get in the results:

30.06.2014	19:31:51	56.0,	24.1,	23.52,	99386
30.06.2014	19:31:54	56.0,	24.1,	23.51,	99383
30.06.2014	19:31:56	56.0,	24.1,	23.51,	99386
30.06.2014	19:31:59	56.0,	24.1,	23.51,	99384
30.06.2014	19:32:01	56.0,	24.1,	23.51,	99389
30.06.2014	19:32:04	56.0,	24.1,	.,	
30.06.2014	19:32:06	.,	.,	.,	
30.06.2014	19:32:09	.,	.,	.,

As you see, after the 5th line, the data from the sensors get cut off (the dots and commas are "handwritten" in the code). At first, I thought that I exceeded some string length limit that I didn't know of, but quickly I realized that it's impossible, since the clock data and dots are there.

As I said - each of these lines is generated by another run of the same loop, so I don't really see what can differenciate one from another. The problem can't lie in the sampling period, either, as there's a delay of 2,5 s between each line - and I tried it with 10 s either, it makes no matter.
Sometimes the problem starts half a line earlier/later.

Does any of you know what's the matter?
Thanks in advance for your help!

Bonus question:
Sometimes the clock has some issues too, and it returns things like:

30.06.2014	19:33:39	55.9,	24.1,	23.73,	99387
165.165.2165	165:165:85	55.9,	24.1,	23.73,	99394
30.06.2014	19:33:45	55.9,	24.1,	23.73,	99389

...just for a line, then everything gets back to normal. If you know why, let me know. Thanks again!

Post your code.

Hm, that's strange. I wanted to extract the relevant code to post it without the part for saving to SD (with which I have some other issues) - I'd had commented it, but forgot to exclude the SD.h library. But when I cut the irrelevant code, the whole problem disappeared for 8 times through the loop.
I rechecked it with a bigger loop (I used the freeMemory library to make it stop when there's less than 300 bytes of RAM left) and the data get cut after the 13th run of the loop.
It seems that the problem is proportionate to the space that the program uses on my 32 kB Atmega328. The program without the SD.h library has 12 kB. With the SD.h, it weighs 17 kB and stops working properly after 6 full runs. I added another library (GSM.h), just to make the program heavier (22kB) - and again it stopped after those 6 runs.
The limit's not connected with some particular volume of RAM left (it's 500 bytes on heavier program, and 750 bytes on the 12 kB version).

My code:

#include <DHT.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include <RTClib.h>
#include <MemoryFree.h>
//#include <SD.h>

DHT dht;
Adafruit_BMP085 bmp;
RTC_DS1307 rtc;

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

  if (!bmp.begin()) {
	Serial.println("Could not find a valid BMP085 sensor, check wiring!");
	while (1) {}
  }

#ifdef AVR
  Wire.begin();
#else
  Wire1.begin(); // Shield I2C pins connect to alt I2C bus
                 // on Arduino Due
#endif
  rtc.begin();
  
  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time
    // this sketch was compiled
    rtc.adjust(DateTime(__DATE__, __TIME__));
  }

  dht.setup(7); // data pin for DHT sensor

}

void loop()
{
  // make a string for assembling the data to log:
String dataString = "";

  int czas;
  double zmienna;

while (freeMemory() > 300)  
{
  DateTime now = rtc.now();
  czas = now.day();
  if (czas < 10)
     dataString += "0";
  dataString += czas;
  dataString += ".";
  czas = now.month();
  if (czas < 10)
     dataString += "0";
  dataString += czas;
  dataString += ".";
  czas = now.year();
  dataString += czas;
  dataString += "\t";
  czas = now.hour();
  if (czas < 10)
     dataString += "0";
  dataString += czas;
  dataString += ":";
  czas = now.minute();
  if (czas < 10)
     dataString += "0";
  dataString += czas;
  dataString += ":";
  czas = now.second();
  if (czas < 10)
     dataString += "0";
  dataString += czas;
  dataString += "\t";
  zmienna = dht.getHumidity();
  dataString += String((int)zmienna);
  dataString += ".";
  dataString += String((int)(zmienna*10)%10);
  dataString += ",\t";
  zmienna = dht.getTemperature();
  dataString += String((int)zmienna);
  dataString += ".";
  dataString += String((int)(zmienna*10)%10);
  dataString += ",\t";
  zmienna = bmp.readTemperature();
  dataString += String((int)zmienna);
  dataString += ".";
  dataString += String((int)(zmienna*10)%10);
  dataString += String((int)(zmienna*100)%10);
  dataString += ",\t";
  dataString += String(bmp.readPressure());
  dataString += "\n";
  Serial.println(freeMemory());
  delay (2500);
}
  Serial.print(dataString);
}

I don't really see how the weight of the code should make this happen, as Atmega328 has separate RAM space, and anyway I'm not even close to running out of my 32 kB.

And again, a bonus question:
Since the RAM is separate, why does the free memory at the very beginning of the program differ with the size of my code (1300 bytes for lightversion, some 700 for the heavier ones)?

String dataString = "";

The String class uses dynamic memory and that is killing for the UNO in many sketches.

rewrite your sketch with a
char dataString[120]; // preallocated array
and use strcat to copy the data

Or better remove it altogether and use
Serial.print(...);
at all the places where you concatenate pieces to the String.

You should see much more free RAM memory in the latter version.

give it a try.

Thanks, robtillaart. The straight-to-Serial version is not an option, because I need the string for further saving the data to an SD card. But I'll try the preallocated array as soon as I get my computer to work.

Serial.println("Could not find a valid BMP085 sensor, check wiring!");

using the F() macro to save precious RAM is also worth doing. F() stores const strings to Flash iso RAM.

Serial.println(F("Could not find a valid BMP085 sensor, check wiring!"));

A quick update - the preallocated array solution works just fine, thank you!