Go Down

Topic: Keeping a File Open? (Read 1 time) previous topic - next topic

ahref

Oct 15, 2012, 04:00 am Last Edit: Oct 15, 2012, 04:02 am by ahref Reason: 1
Hello all,

Using a: https://www.sparkfun.com/products/9802
With: http://code.google.com/p/sdfatlib/

on an Uno Rev3.

I'm doing some data logging out to a file on the sd card fine but part of it is making me twitchy.
Code: [Select]

void loop()
{
 if (!sd.begin(chipSelect, SPI_FULL_SPEED)) sd.initErrorHalt();
 ofstream sdout("test.csv", ios::out | ios::app);
 //Do logging to sdout here
 //eg sdout << "test" << flush
 sdout.close();
}


Is there anyway to keep the file handle open between loops? This works fine I'm just concerned that this sort of behaviour seems inefficient/detrimental to the sd card.

I've tried declaring some of the stuff in setup()/ the main file body but this does not work, the examples with the library seem to agree that this is the only way to write to a file within loop()

Thanks :)


Osgeld

put the following in your void setup()

Code: [Select]

 if (!sd.begin(chipSelect, SPI_FULL_SPEED)) sd.initErrorHalt();
 ofstream sdout("test.csv", ios::out | ios::app);


your just opening the same file over and over again

and no its not the only way, there's a write() function, post your full code
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

PaulS

The SD::begin method should be called ONCE, not every pass through loop.

ahref


The SD::begin method should be called ONCE, not every pass through loop.


I was aware of this, my entire post details that i tried that.

Many thanks to the both of you!

Go Up