During the starting phase when i uploaded the code, the data log was working perfectly fine but after few addition to code, it got stuck up and always gave me the error that SD card was not found. Actually it does exist and the example code of arduino is working perfectly fine on the same circuit. Can you help me with the code? I actually want to create a log of gps data where data gets stored in sd card every few min(here it is 1 min (for testing) but it would be every 4-5 mins). The code in setup is working perfectly fine it's the writing in sd card giving me an issue.
Why are you using Strings? Quit pissing away resources uselessly.
Writing to an SD file or the serial port is already buffered. There is NOTHING to be gained by using one Serial.print() or File.print(), instead of multiple Serial.print()s or File.print()s, and there is definitely something to be lost.
input() is where the data would be written on sd card
Strings are going to be utilized in later part of the project while working with gsm as well. Yes, I agree they are utilizing resource uselessly. Would work on that.
Those print() were just done to test if it was as issue with gps data or something. OK removed those things
But still it is always going in the loop where it prints "the text file cannot be opened"
input() is where the data would be written on sd card
input() is where the data goes OUT of the Arduino, to some other device. Well, then, the name makes perfect sense.
while (myFile.available()) {
buffer[i++] = myFile.readStringUntil('\n');
delay(50);
}
Are you certain that there will never be more than 20 records in the file? How big are the records? That is, when trying to open a file for write in the input() function, how much memory is available?
Yes I am pretty sure that only 20 data would exist in the file Welcome.txt or even way less than that maybe 5-10 not more. Beside that sketch is using around 66% of total memory and 74% of available memory as global variables leaving the rest for local ones.
Can you help me with the code? Is there any issue with the code?
Sorry I am a newbie at this forum and so wasn't knowing that technique to attach the code. Thanks for that thing. Would always do that from now on. Beside that thank you so much PaulS, the issue is now solved. I just reduced the String buffer size and the thing again started working. Maybe memory issue.
If you could help me @PaulS with one more thing? Can you help me with optimization of this code?
And can you tell me how to work with gsm and gps together on UNO? Actually I want to embed GPS data in my message which I would send through GSM. The issue I am facing is that if I use both of them together I am not getting the data of GPS in message string. It is staying as 0 only. Both of them independently are working perfectly fine
PaulS:
There is no maybe about it.
You can either use an Arduino that has more memory that you can waste, or you can stop wasting memory. Instances of the String class waste memory.
Don't be so rude bro. This is actually my very first attempt on working with an Arduino. I would definitely make sure that it wont happen again. Again a very big thanks to you.
Kavish5:
Yes I am pretty sure that only 20 data would exist in the file Welcome.txt or even way less than that maybe 5-10 not more. Beside that sketch is using around 66% of total memory and 74% of available memory as global variables leaving the rest for local ones.
Can you help me with the code? Is there any issue with the code?
With Arduino uno?
You have to be sure you have left more than 512 bytes for SD lib. Still I see 522.
Free some more memory with string literals stored only in programming memory by:
Serial.print(F("The SD card cannot be found"));
AFAIK, Strings dynamically reserve memory and waste resources. Avoid it by any cost. Simply reserve some appropriate cycling buffer or better store data independently. Avoid concat stings by any cost!
Why you open and close file all the time?
Open it once in setup() and simply flush data after writing to avoid file corruption.
You have to be sure you have left more than 512 bytes for SD lib. Still I see 522.
Free some more memory with string literals stored only in programming memory by:
Serial.print(F("The SD card cannot be found"));
AFAIK, Strings dynamically reserve memory and waste resources. Avoid it by any cost. Simply reserve some appropriate cycling buffer or better store data independently. Avoid concat stings by any cost!
Why you open and close file all the time?
Open it once in setup() and simply flush data after writing to avoid file corruption.
Thanks for the advice. Had reduce the size of dynamic memory allocated to 65%. Thanks mate
It already started working correctly before your reply but with your reply and tips, it just got more efficient and this would be helpful when i interface it with GSM. So those tips were of great help....Thanks