• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

ESP32 Data Logging: 'writeFile' was not declared in this scope

Q&A Forum › Category: ESP32 › ESP32 Data Logging: 'writeFile' was not declared in this scope
0 Vote Up Vote Down
Christopher Stillwell asked 5 years ago

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();
}

 

2 Answers
0 Vote Up Vote Down
Steve Mercer answered 5 years ago

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.

0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

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

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.