SD card full

Hello, I am making a project which logs data to sd card. I want to stop logging data once the card is full. So is there any way to know the card is full or not. I know that the size of a file can be read using a function of sd card lib. But this involves the creation of new files during execution. So I am looking at a way to find how much space of the card has been occupied. Thanks

If you use the SDFat library directly, I believe you can read the card size. I don't know whether there's an easy way to find out how much of the capacity is used but I suspect you could get it from the card's CSD register.

Do you really need to worry about this? Filling a card isn't that easy.

OK, you might be doing something really serious and have already proven it with a test run, but I was a bit surprised to find that when I sent my data to a an ordinary 2Gb card at ten second intervals, it was going to take 590 days to fill it.

I guess it depends a bit on what you mean by "data".........

sreedevk: I want to stop logging data once the card is full.

The data is stored whenever a pulse sensor detects a pulse. It will be stored as a CSV file. The time of pulse, body temp & skin conductivity has to be stored. Such rapid rate of data collection can lead to the overflow of SD card.

OK. I guess all the questions like how many bodies, how long a period, what sort of sensors, how many sensors, at what resolution, why would you do it anyway, and what do you do with that data once you've got it, can be left for another topic......

No wait. This might be a time for feeding data by strings of a known length. You might find that the simplest way of doing this is to just count the number of data strings fed to the SD.

Nick_Pyner: OK. I guess all the questions like how many bodies, how long a period......

Nick, does that actually matter ? Indeed, one may not need such a routine with a 32GB-card, but maybe Sreedevk is using a 32MB-one. I was very happy to have a similar routine which warned me a week in advance when I used a 256MB-card, even when it recorded just 1.5MB a day.

Sreedevk, have a look at the sdinfo-example from the sdfat-library mentioned by PeterH. It uses 3 functions that can help you further, blocksPerCluster, clusterCount and freeClusters.

Keep in mind a block is always 512 bytes big, one can have a different number of blocks per cluster depending on the SD-card used and each card has a total cluster count. By multiplying all three you'll get the size of the card in bytes. By using the freeClusters - function (*512 * blocksPerCluster) you can see how much is used/still free.

Unfortunately it won't show every byte available since a cluster of blocks may or may not be completely filled, but I guess/hope it's accurate enough for you.

Thanks for the info