My problem is a strange one and I am unable to figure it out. I am using (attempting to use) the tinyFat library. When I make a brand new sketch and use the library, it works flawlessly. When I load their examples and compile them, it works flawlessly.
However when I go to include it in my project something goofy is happening and I cannot understand why. It will act like it cannot see the library. It gives me " 'file' was not declared in this scope" for the command res = file.initFAT(). Why would it be able to detect the library in one set of circumstances and not in another?
I would post my code but it is over 30 files in size and I am simply not doing that. As I've said, it works fine if not in this project. I have moved the project to the Arduino folder in my documents and that did nothing. Before using this library everything was working fine.
Example that works: #include <tinyFAT.h> #include <avr/pgmspace.h>
void setup(){
byte res = file.initFAT();
}
void loop(){
}
Move that code to the appropriate locations in my project and it explodes.
This is their example and it compiles fine on my machine. There is no declaration of file in their program either.
// Demo_readLn (C)2011 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// This program is a demo of the readLn()-function.
//
// This demo will open a textfile named 'TEXTFILE.TXT'
// and display its contents in the Serial Monitor.
//
// SD card must be connected to the SPI port of your Arduino.
//
// Remember to select 115200 baud in the Serial Monitor.
//
#include <tinyFAT.h>
#include <avr/pgmspace.h>
byte res;
word result;
char textBuffer[81];
char *verboseError(byte err)
{
switch (err)
{
case ERROR_MBR_READ_ERROR:
return "Error reading MBR";
break;
case ERROR_MBR_SIGNATURE:
return "MBR Signature error";
break;
case ERROR_MBR_INVALID_FS:
return "Unsupported filesystem";
break;
case ERROR_BOOTSEC_READ_ERROR:
return "Error reading Boot Sector";
break;
case ERROR_BOOTSEC_SIGNATURE:
return "Boot Sector Signature error";
break;
default:
return "Unknown error";
break;
}
}
void setup() {
// Initialize serial communication at 115200 baud
Serial.begin(115200);
Serial.println();
// Initialize tinyFAT
// You might need to select a lower speed than the default SPISPEED_HIGH
res=file.initFAT();
if (res!=NO_ERROR)
{
Serial.print("***** ERROR: ");
Serial.println(verboseError(res));
while (true) {};
}
Serial.println("This demo will display a textfile called 'TEXTFILE.TXT'");
Serial.println();
Serial.println("***** Send any character to start *****");
while (!Serial.available()) {};
Serial.flush();
Serial.println();
Serial.println();
if (file.exists("TEXTFILE.TXT"))
{
res=file.openFile("TEXTFILE.TXT", FILEMODE_TEXT_READ);
if (res==NO_ERROR)
{
result=0;
while ((result!=EOF) and (result!=FILE_IS_EMPTY))
{
result=file.readLn(textBuffer, 80);
if (result!=FILE_IS_EMPTY)
{
if (result==BUFFER_OVERFLOW)
Serial.print(textBuffer);
else
Serial.println(textBuffer);
}
else
Serial.println("** ERROR: File is empty...");
}
Serial.println();
file.closeFile();
}
else
{
switch(res)
{
case ERROR_ANOTHER_FILE_OPEN:
Serial.println("** ERROR: Another file is already open...");
break;
default:
Serial.print("** ERROR: ");
Serial.println(res, HEX);
break;
}
}
}
else
Serial.println("** ERROR: 'TEXTFILE.TXT' does not exist...");
Serial.println();
Serial.println();
Serial.println("***** All done... *****");
}
void loop()
{
}
Oh sorry I thought you posted code that didn't work, which is necessary. Either post your 30 file project (a link to github is great) or find a smaller example that doesn't work also. It's unlikely anyone will be able to guess at what your code is and then immediately come up with a solution.