Pages: [1]   Go Down
Author Topic: Issue including EEPROM.h function calls within class  (Read 1815 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys, I've been searching a lot and can't seem to get a solid answer on this. I'm trying to use EEPROM.read() and write() in a class. Can someone tell me where I'm going so terribly wrong? Thanks.

Code:
#ifndef _PHONEMEMORY_H_
#define _PHONEMEMORY_H_

#include <Arduino.h>
#include <string.h>
#include <EEPROM.h>


class PhoneMemory
{
  public:
   PhoneMemory();
   int addPhone(char *number);
};

#endif

Code:
#include "PhoneMemory.h"

int PhoneMemory::addPhone(char *number)
{
 EEPROM.read(1);
}

Error:
Code:
PhoneMemory.cpp: In member function 'int PhoneMemory::addPhone(char*)':
PhoneMemory.cpp:12: error: 'EEPROM' was not declared in this scope

I appreciate any help.

Thanks.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What does your sketch look like? You can't hide the fact that you need EEPROM.h from the sketch.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The main .ino includes looks a like this:

Code:
#include <SoftwareSerial.h>       //Include the NewSoftSerial library to send serial commands to the cellular module.
#include <string.h>               //Used for string manipulations
#include "CircularBuffer.h"
#include "PhoneMemory.h"
#include <EEPROM.h>

I've tried it with both EEPROM.h being included and not included in the .ino. I find it weird that Serial will work just fine in the class but EEPROM won't.

Thanks for your help.

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Has anyone resolved this?  I'm having exactly the same problem.
Logged

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 64
Posts: 2101
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This code works under IDE 1.0.4

make sure you have "#include <EEPROM.h>" in the sketch ( not just library ).
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Has anyone resolved this?  I'm having exactly the same problem.


I have no idea if what Pyro said is true, if it was fixed in a new IDE version. In case it isn't though, here is the work around I used:

Code:
uint8_t eepromRead(int address)
{
  return eeprom_read_byte((unsigned char *) address);
}

void eepromWrite(int address, uint8_t value)
{
  eeprom_write_byte((unsigned char *) address, value);
}

You just use those functions to read/write to the EEPROM if it won't work right any other way.

Hope that helps!
Logged

Pages: [1]   Go Up
Jump to: