Arduino - nested timed loops and sd write error - please, help

Hello,
I'm getting lost in a "glass of water"... I lost 4 hours trying to debug it.
I made a litte sketch which I want to use as irrigation system for my home.

Im using an arduino uno compatible board with ethernet shield.

My goal and components:

  • acquire dht22 temp/hum sensor every 10 seconds
  • acquire soil resistance with analog input with a couple of metal rods and pullup res every 10 seconds.
  • a Ds1307 as clock input and verify when switch on/off the pump every 1 second
  • append all the data in a log file into the SD every 10 MINUTES
  • webserver (still to merge from another sketch I already made)

so I grabbed a bit of looping code from another project to keep the code simple to read
but I cannot write the LOG file into the SD card. I don't know why.

If I use the example sketch from arduino examples, it WORKS well, no problems at all.

In my sketch instead, it fails opening the file in the sd (error opening datalog.txt)
I tried a bit to insert some delay, but no success.

Any idea?
Here the entire code: http://www.thepiper.eu/files/irrighetto.txt

I'm getting crazy..

Are you certain you are not running out of SRAM? SD.open() will fail if not enough SRAM available. Here is a link to a post on another thread that has the code I use to check SRAM.

Thanks, didn't though about it.
I'm gonna verify.
I'll post news soon.

If you do establish that you have SRAM issues, use of the F macro on all your serial prints of constant strings would be helpful.

yes, I'll try also F() macro as soon as i'll be home later. thanks

Actually, I'm using a total of 571 chars in the serial.println functions along the program...

YEAAAAAA!!!! THANKS!!!!!!! program was running out of memory... I putted 571 chars in my serial.print calls under F(). I
Now I Have still more than 800 byte of free mem..
And the program runs!!!!!!!

Ok.. now the webserver .. Hope to have some free space with the ethernet library call.. :smiley:

Have a nice day at all!
Paolo