I am farily new to arduino and programming in general, so please bare with me.
I have been developing a code to read a CO2 sensor and an Ultrasonic range finder. That code is working great.
I am using surferTim's FTP upload/download code from the arduino playground. When I load that code into the arduino board it works fine.
THe problem comes when I try to combine the two codes. Everything runs like it should until it is time to upload the files to the FTP. The program gets stuck opening the file on the sd card, so the FTP upload does not begin. After the FTP try, the CO2 sensor is producing a number that indicates it is not reading.
The Scaboo.txt file is one that I put on my sd card. I'm writing cdata001 and rdata001.
I couldn't get either file that the program wires to open so I put a file on the sd card to see if it would open any file at all.
I'm getting the sd open fail message then the ftp fail message.
I have a simple ftp set on my computer using filzilla just to test. So I set my own ftp server address.
I am using an UNO. If I take out the ability to download from the ftp will that free up enough space? And I forsee more code being written anyways. I want to eventually pull time from the internet and put date stamps on my files. I also will need to change file names after each upload. That seems to be 4 to 5 kB right there. I had to leave my office so the device is not with me to test.
The FTP code only includes one function or the other in the compile. It compiles either the SD-to-FTP code, or the FTP-to-SD code, depending on the FTPWRITE define. That is so it will fit easier into an Uno.
And there is a difference between program memory and SRAM. You have 32K of program memory, but only 2K SRAM.
Here is a short sketch that has a SRAM checking function. It doesn't show zero when out of SRAM, but a very large or negative number. You can add it to your sketch and call it just before the SD open fail to see how much SRAM you have before the SD file open.
int freeRam() {
extern int __heap_start,*__brkval;
int v;
return (int)&v - (__brkval == 0 ? (int)&__heap_start : (int) __brkval);
}
void setup() {
Serial.begin(9600);
// all your setup stuff, then
Serial.print(F("SRAM = "));
Serial.println(freeRam());
}
void loop() {
}
If i understand SRAM, it is the storage of data while powered but erases when not powered. If that is correct, is there a way to clear the SRAM before the FTP upload?
It isn't really a matter of clearing it, but freeing it. That is why the F() function is prevalent in that code. It keeps those static strings in program memory instead of copying them to SRAM to use them.
Try the freeRam() function. Call it at the end of your setup() function to check how much you have remaining there, then again just before the SD file open. It is possible this is not the problem, but until you check...
edit: Some of the SRAM is used by the "operating system", and the Ethernet and SD libraries take their toll on it too. Then when it runs that FTP function, you have a file and two sockets open, all at the same time.
edit: The Serial.write() function call, and probably all the other .write() functions, have a problem with the F() function. They will throw a "I don't know anything about this FlashStringHelper thing" error.