I’m using the “LoRa Long Range Sensor Monitoring and Data Logging” Project as a reference. When I tried to create the microSD initialization and have the arduino IDE verify the code, I’m getting an error that ‘writeFile’ was not declared in the scope. I’m just a bit confused because I thought FS.h or SD.h would have the function included. I’m using the ESP32 Huzzah if that is any help.
#include <SPI.h>
#include "FS.h"
#include "SD.h"
#define SD_CS 16
void setup(){
Serial.begin(115200);
SD.begin(SD_CS);
if(!SD.begin(SD_CS)){
Serial.println("Card Mount Failed");
return;
}
uint8_t cardType = SD.cardType();
if(cardType == CARD_NONE){
Serial.println("No SD card attached");
return;
}
Serial.println("Initializing SD card...");
if(!SD.begin(SD_CS)){
Serial.println("ERROR - SD card initialization failed!");
return;
}
File file = SD.open("/data.txt");
if(!file){
Serial.println("File does not exisit");
Serial.println("Creating file...");
writeFile(SD,"/data.txt","Sensor_ID,User_ID,Session,Time,gx,gy,gz,ax,ay,az,mx,my,mz\n");
}
else{
Serial.println("File already exists");
}
file.close();
}
I don’t know the libraries (You did add those libraries with the library manager, right?) you are using but I would have based my project on ESP32-CAM Take Photo and Save to MicroSD Card. Perhaps try that and see how you get on.
Hi.
You need to include the actual writeFile() function in your code. Add the following lines before the setup.
void writeFile(fs::FS &fs, const char * path, const char * message) {
Serial.printf("Writing file: %s\n", path); File file = fs.open(path, FILE_WRITE);
if(!file) {
Serial.println("Failed to open file for writing");
return;
}
if(file.print(message)) {
Serial.println("File written");
} else {
Serial.println("Write failed");
}
file.close();
}
Let me know if this solves your issue.
Regards,
Sara