I am recording some data on the SD card and I want the file name where it is saved to be assigned by a function ...
For example:
String (file) = (("/mnt/sd/")+datactual+".csv");
File dataFile = FileSystem.open (file, FILE_APPEND);
But that doesn’t work.
Always a very useful description of the problem. Does it not compile? Or doesn't it create a file? Or something else?
Which SD library do you use? We probably wouldn't have to ask if you had provided a complete code that demonstrates the problem and if we knew which board you're using.
Note that filenames on SD cards usually have to adhere to the 8.3 notation; so if datactual contains "Hello World", you're out of luck.
Not so surprising. It is incomprehensible. For all that, using a variable as a filename is common practice, the most obvious example being the use of the date:
20211101.csv.
Just stick with DOS-type 8.3 names, as mentioned above.
It doesn't copy the whole program because it's quite extensive, but it works, only now I want to make a modification, so far the information is always saved in the same file and I want it to be saved in a different file every month. Test-fitxer-SD.ino (1.7 KB)
the error message when compiling is as follows:
In file included from /home/pere/Documents/Projectes/Programes per arduino/Test-fitxer-SD/Test-fitxer-SD.ino:4:0:
/snap/arduino/61/libraries/Bridge/src/FileIO.h:83:10: note: candidate: BridgeLib::File BridgeLib::FileSystemClass::open(const char*, uint8_t)
File open(const char filename, uint8_t mode = FILE_READ);
^~~~
/snap/arduino/61/libraries/Bridge/src/FileIO.h:83:10: note: no known conversion for argument 1 from 'String' to 'const char'
exit status 1
The compiler is objecting to the use of a String object in that function call - it was expecting a C string instead. Take a look at the String docs in the reference - you can use c_str() to solve your problem I think.