Go Down

Topic: First attempts at Arduino OOP (Read 1 time) previous topic - next topic


Jul 03, 2012, 12:42 am Last Edit: Jul 03, 2012, 12:53 am by markCaz Reason: 1
Hey guys,

I'm pretty new to Arduino, but have been doing okay so far. I am having a quite a bit of trouble writing a library function that reads and writes to the EEPROM. The project is an RFID door opener, I want the ability to add cards to the non-volatile memory if one's detected while the button is pressed, or check the card against the memory to allow entrance if the button is not depressed. The DataBase lib I'm writing should roughly do this, but I keep getting an error saying "'EEPROM' was not declared in this scope" even though it's in the header.

Everythings work in progress but I can't get past this bug! thanks for taking the time to read though it and any help you can give.. I'm also confused that despite updating to 1.01 I still need to include 'Arduino.h' for it to work. in the library tutorial it said it should run off 'WProgram.h' instead. only mention as maybe I fluffed the update.

My code structure is as follows: folder 'database' contains:

'database.ino' (with nothing in it)

Code: [Select]

#ifndef DataBase_h
#define DataBase_h

#include <Arduino.h>

class DataBase {
           boolean existsAt(int i);        // checks EEPROM to see if position is taken.
           int existsValue(int value[5]);  // checks EEPROM
           int getAt(int i);               // returns array
           void setAt(int i, int value[5]);// set in EEPROM
           void clearAt(int i);            // deletes in EEPROM

Code: [Select]

#include "DataBase.h"
boolean DataBase::existsAt(int i){
 boolean t = false;
 for (int j=i; j<i+8; j++){
   if(EEPROM.read(j)!=255){  // BUG HERE :(
 return t;

int DataBase::existsValue(int value[5]){
 for ( int i=0; i<1024/8; i+=1){
     return i;
 return -1;
int* DataBase::getAt(int i){
 int ans[5];
 for (int j=i; j<i+8; j+=2){
   int[(j-i)/2] = int(EEPROM.read(j)) + int(EEPROM.read(j+1));
 return ans;

void DataBase::setAt(int i, int value[5]){
 for (int j=i; j<i+8; j+=2){
   byte a = 0;
   byte b = 0;        
     a = 255;
     b = value-255;
  EEPROM.write(j  , a );
  EEPROM.write(j+1, b );
void DataBase::clearAt(int i){
 for (int j=i; j<i+8; j+=2){
   EEPROM.write(j  , a );
   EEPROM.write(j+1, b );


Jul 03, 2012, 12:52 am Last Edit: Jul 03, 2012, 12:56 am by AndyCC Reason: 1
Is EEPROM.h being included, or is it not being found? I've always found it useful in cases like this to put #error at the top of the header file you're including (temporarily, of course):

Code: [Select]
#error "Yes I just included EEPROM.h"

If you don't get the error, something is wrong with your include path or location of the header file. You could put it right before the line that defines EEPROM if you want to narrow things down.

Nick Gammon

Put this line:

Code: [Select]
#include <EEPROM.h>

at the start of the .ino file.

The IDE copies all your files to a temporary folder, based on the includes in the .ino file.
Please post technical questions on the forum, not by personal message. Thanks!

More info:


Jul 03, 2012, 01:05 am Last Edit: Jul 03, 2012, 01:09 am by markCaz Reason: 1
Hey Andy and Nick,

Cheers for the quick reply.. It appears not to be being included.

tried adding it at the top of the .cpp too, but no joy!

No idea why thought because it's one of the stock libraries.. I should note this project isn't in the library folder yet, but I wouldn't have expected that to stop it working.

Thanks for helping to bail me out..!


oh! in the .ino? but I dont have control of the .ino from the library.. it doesn't make it v portable if I do have to. bit of a shame.

Tom Carpenter

Once it is in the libraries folder it should work without it included in the .ino file. But until then, the compiler needs to know where to look.


Awesome that worked! Thanks..! good to know I wont need it in the end :) now to iron out all the other bugs.. heheheh..

Tom Carpenter

On second thoughts, you will...

Unless you copy the EEPROM.cpp and EEPROM.h files into your library folder.



I knew there was a way I had gotten around that problem. Its only an extra 2kB to include in your library folder, and the "#ifndef EEPROM_h" statements in the EEPROM.h will prevent the compiler accidentally including it twice.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131