Problem with DS1307 and DS18B20

Hello,

I doing a small project with digital temperature sensor and a clock. I'm monitoring various temp sensors and saving the results on a SD card.

My problems start when I install a DS1307 clock. By doing trial and error, I'm pretty sure there is a problem when all those libraries are used at the same time. It works fine when I used edither the temperature sensor libraries or the clock libraries.

Temp libraries: OneWire DallasTemperature

Clock libraries Wire RTClib

When all those lib are used, the micro controller start giving funny results or become all mixed up (unexpected info is store on the SD, garbage is generated when reading the temperature or application crash).

Have anybody already had this kind of issue.

I'm planning to start reading the C++ code, but I have not done this in a very very long time...

Thanks for your help

Unless your OneWire device is using the same pins as your RTC, I don't see how there would be a conflict.

Post the code that doesn't work. Maybe it isn't the libraries themselves causing the problem.

The symptoms you describe suggest that you are exceeding the available SRAM.The SD library uses a fair bit of SRAM on its own. If you have a lot of strings or, worse yet, you are using the String library, you'll easily exceed SRAM.

Pete

I’ve attached my sketch and libs.
Please keep in mind, this is my first project… ever!!!

Quick resume of what I’m trying to do:

I’ve build a solar heater using soda cans (something like this: Brian's Pop Can Solar Heater).

My sensors are:
-1 thermometer inside the panel
-1 thermometer outside the house
-1 thermometer inside the house
-1 photometer

I’ve also included LCD screen, 1 clock, 2 12v computer fans and 1 SD card reader.

My objectives are:

  • Start the fans when the temperature in the panel > the one inside the house.
  • Log everything on the SD card to create stats.

When compiling my sketch, it shows a size of 27,180 bytes (of a 32,256 maximum) so I think I’m still within the limit.

Thanks for your help and please let me know if you see way to improve my code :blush:… I’m here to learn! :smiley:

lib.zip (80.4 KB)

RadiateurSolaire4.ino (5.13 KB)

it shows a size of 27,180 bytes

That's the amount of flash ram that's used. The IDE does not show you how much SRAM you are using. You are using the String library and, as I mentioned, the SD library requires quite a bit of SRAM so you will almost certainly be running into problems caused by exceeding the SRAM limit which on a 328-based Arduino is only 2kB. You should get rid of the String library and handle the character strings yourself.

Pete

I'd strongly advise you to lose all reference to the String library, its almost always creates a memory leak, especially if you use the + operator on Strings.

ok, so what's next? :fearful:

Will removing all my string from my sketch will solve the issue?

Do you have a small example so I can find out how to use a string without using the String.

Thanks

One more question: any idea why that sram allocation is so small? For me the String functionnality is pretty basic request and should not be a limitation.

(Just for my info...)

Thanks again

azzabcd: One more question: any idea why that sram allocation is so small? That's how the chip was designed.

For me the String functionnality is pretty basic request and should not be a limitation. I think there are errors in String functions and they also fragment your RAM so after some time the processor will probably crash

azzabcd: Do you have a small example so I can find out how to use a string without using the String.

Your already using some in the sketch you supplied.

    char tempChar [10];
    dtostrf(temp[j],1,2,tempChar);

Lookup commands like strlcpy, strlcat, itoa & dtostrf on http://www.cplusplus.com/

azzabcd: One more question: any idea why that sram allocation is so small? For me the String functionnality is pretty basic request and should not be a limitation.

(Just for my info...)

Thanks again

The String library needs a reference-counted or garbage-collected system to work reliably. The String library was not designed for a microcontroller with a few kB of RAM. With a few kB of RAM you are always programming round limitations! Microcontrollers are not microprocessors, they are literally 10,000's of times less complex - thats why it runs on a few mA rather than 100 amps (like an intel i7)

The String library was not designed for a microcontroller with a few kB of RAM.

Actually, it was. It's just that the design that Paul Stoffgren came up with and the implementation that made it into the IDE package are not the same thing, AND the free() function in the standard library has a fatal error.

Given an understanding of the limits of the (properly implemented) String class on a microcontroller with limited memory (and a properly functioning free() function), the String class itself is not inherently evil. It is often abused, and the poor implementation doesn't help its cause.

If the allocation that the String class does was not one character more at a time, and if the free() function worked correctly, and if users understood that storing 5000 characters in a String instance wasn't possible, the String class would not be bad.

Unfortunately, none of those if tests currently evaluate to true.

I'd like to thanks everyone who help me go thru this problem. I've convert everything to use char and it's now working fine.

Thanks again for your help and time.