I started messing around with EEPROM today but have come up against a problem. If you look up the reference page for EEPROM.read there's a little example which I tried and it worked fine. However, if you re-organise it so it uses 2 files, like this :
#include <EEPROM.h>
int a = 0;
int value;
void Dotest( void )
{
value = EEPROM.read(a);
Serial.print(a);
Serial.print("\t");
Serial.print(value);
Serial.println();
a = a + 1;
if (a == 512)
a = 0;
delay(500);
}
then it won't work. You get the compiler error "Test.cpp:1:20: error: EEPROM.h: No such file or directory".
Why is this? Can you only include EEPROM.h in an ino file? Is this a known problem?
The files from the sketch directory are copied to a temporary folder for the compile/link process to operate in. All files in the sketch directory AND all files included in the sketch are copied. In your case, EEPROM.h is not included in the sketch, so it is not copied, so it is not available to include in the cpp file.
Can you only include EEPROM.h in an ino file?
No, but you must ALSO include it in the sketch.
Is this a known problem?
It's a known condition. Whether it is a problem or not depends on your perspective/background/etc.
On further experimentation I found you need to select "Import library - EEPROM" from the IDE. Not quite sure why the unmodified example works but my code does not though.
I did notice that I misnamed the method "Dotest" instead of "DoTest" in Test.cpp but that wasn't the problem.
PaulS : Are you saying I need #include<EEPROM.h> in EEPROMTest.ino as well as in Test.cpp even though EEPROMTest.ino doesn't appear to use it?