Bonjour, dans le cadre d'un projet d'une petite station météo je souhaite écrire les informations récoltées sur une carte SD.
Lorsque je veux nommer mon fichier en .txt, je passe par des String, mais j'ai l'impression que le file.open ne prend pas en compte les string ? Si quelqu'un verrait le problème...
#include <SPI.h>
#include <SD.h>
int comptFichier = 1;
File myFile;
void setup() {
Serial.begin(9600);
while (!Serial) {
;
}
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
}
void loop() {
ecrireSD();
delay(5000);
}
void ecrireSD(){
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
String NomFichier = getRTCdate();
Serial.println(NomFichier);
myFile = SD.open(NomFichier, FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening");
}
}
String getRTCdate(){
String NomFichier1;
NomFichier1 ="captures";
NomFichier1+=String(comptFichier);
NomFichier1+=".txt";
comptFichier++;
return NomFichier1;
}
Alors j'ai fait la modif mais pas d'amélioration de ce côté, j'ai peut être mal fait les choses ?
void ecrireSD(){
String NomFichier = getRTCdate();
Serial.println(NomFichier);
myFile = SD.open(NomFichier.c_str(), FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening");
}
}