How to dump data from EEPROM more clearly

In my project i am using a struct that is read at the start of the program.
This struct contains a mix int, bytes, longs and characters.
For saving and loading of the struct is use the example found here:
http://playground.arduino.cc/Code/EEPROMLoadAndSaveSettings

But now i want to have a nice formated output to the terminal.
If i do a simple

  for(unsigned int t = 0; t < sizeof(confValue); t++)
  {
    Serial << t << "\t" << _DEC(EEPROM.read(t)) << endl;
  }

i get a list with all the EEPROM members, but they dont show the actual value.
Using EEPROMex makes is possible to read a single int, byte, long and char, but i cant figure out how to get this in a list.
I dont think i should do something like this:

uint8_t read(int address);
bool readBit(int address, byte bit)
uint8_t readByte(int address);
uint16_t readInt(int address);
uint32_t readLong(int address);
float readFloat(int address);
double readDouble(int address);

where i have to calculate the address value.
Is there a possibilytie to get this working or a workaround?

In my project i am using a struct that is read at the start of the program. This struct contains a mix int, bytes, longs and characters.

EEPROM_readAnything() and EEPROM_writeAnything() will read and write the whole struct full of data in one call.

Then, print the elements in the struct, not the raw bytes.

PaulS:

In my project i am using a struct that is read at the start of the program.
This struct contains a mix int, bytes, longs and characters.

EEPROM_readAnything() and EEPROM_writeAnything() will read and write the whole struct full of data in one call.

Then, print the elements in the struct, not the raw bytes.

Yes i know, but i dont want to reload the struct, but output the EEPROM content to the Serial port.
This is how i do it now:

void dumpConfig()
{
  // Send the EEPROM content to the termina
  Serial << "Show EEPROM" << endl;
  for(unsigned int t = 0; t < sizeof(confValue); t++)
  {
    Serial << t << "\t" << _DEC(EEPROM.read(t)) << endl;
  }
}

Yes i know, but i dont want to reload the struct

int a, b; See, you can have two variables of the same type. That includes structs...

Maybe i am not clear enough. My output now looks like:

  • Show EEPROM 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 32 9 13 10 0 11 0 12 32 13 13 14 0 15 0 16 25

.......... 35 48 36 46 37 49 38 0

I rather would like to have something like this: Show EEPROM: 1 0 2 0 3 3360 4 3360 5 25 enz.

Maybe i am not clear enough.

What you want to do is clear enough. Why you are dumping raw bytes when that is not what you want is not.

If you have a struct:

struct stuff
{
   int a;
   long b;
   float c;
   char d[10];
};

struct stuff myStuff;

myStuff.a = 3;
myStuff.b = 8;
myStuff.c = 3.14159;
strcpy(myStuff.d, "Hey, there");

Then, you can use EEPROM_writeAnything() to write the structure to EEPROM.

Then, you can do this:

struct stuff storedCrap;

Then, use EEPROM_readAnything() to read data from the EEPROM and store it in the storedCrap instance. Finally, you can do this:

Serial.print(storedCrap.a);
Serial.print(storedCrap.b);
Serial.print(storedCrap.b);
Serial.print(storedCrap.d);

to see 3 8 3.14159 Hey, there

But, hey, it's your choice.

OK, final question, can one delete the struct afterwards to clear RAM?

An easy way to do this automatically would be to declare the struct as a local variable in a function that reads it from EEPROM and prints its content to serial.

Oeps thats a lot of information for me as a newbie C++ programmer. Could you give a example. Thnx

Could you give a example.

void dumpEEPROM()
{
   struct stuff storedCrap;
   // Read eeprom
   // dump storedCrap stuff
}

When the function ends, the memory used by storedCrap is available for other uses.

Sometimes i feel stupid becourse i cant figure out what is wrong here:

void dumpConfig()  {
struct  EEPROMStruct{
  long _azAdZeroOffset;        // azAdZeroOffset value
  long _elAdZeroOffset;        // elAdZeroOffset value
  long _azScaleFactor;         // azimuth encoder scale factor
  long _elScaleFactor;         // elevation encoder scale factor
  int  _closeEnough;           // value for catcing position
  long _azimuthPark;           // Position where the antenna is parked after a timeout
  long _elevationPark;         // 
  byte _rotationSpeed;         // Actual rotation speed
  byte _rotationSpeed4;        // Rotator speed High
  byte _rotationSpeed3;        //
  byte _rotationSpeed2;        //
  byte _rotationSpeed1;        // Rotator speed Low
  unsigned long    _rotorParkInterval; // Duration after wich the rotors are parked
  char softwareVersion[4];     // contains version number
}  
EEPROM_Value;

EEPROM_readAnything(0, EEPROM_value);
}

I get a 'EEPROM_value' was not declared in this scope error. Maybe its to late and i should go to sleep.

EEPROM_Value;

EEPROM_readAnything(0, EEPROM_value);

Case matters. Value != value.

Its hopeles with me, now got a different error: EEPROM:127: error: no matching function for call to 'EEPROM_readAnything(int, dumpConfig()::EEPROM_Struct&)'

Its hopeles with me

Apparently so. You make code changes and expect us to guess what you changed.

The only thing i dit was chancing EEPROM_value in EEPROM_Value and nothing else.
I now do it the old fasioned way

void dumpConfig()  {
struct	EEPROM_Struct{
  long	_azAdZeroOffset;		// azAdZeroOffset value
  long	_elAdZeroOffset;		// elAdZeroOffset value
  long	_azScaleFactor;			// azimuth encoder scale factor
  long	_elScaleFactor;			// elevation encoder scale factor
  int	_closeEnough;			// value for catcing position
  long	_azimuthPark;			// Position where the antenna is parked after a timeout
  long	_elevationPark;			// 
  byte	_rotationSpeed;			// Actual rotation speed
  byte	_rotationSpeed4;		// Rotator speed High
  byte	_rotationSpeed3;		//
  byte	_rotationSpeed2;		//
  byte	_rotationSpeed1;		// Rotator speed Low
  unsigned long	_rotorParkInterval;	// Duration after wich the rotors are parked
  char	softwareVersion[4];		// contains version number
}  
EEPROM_Value;

  Serial << "Show EEPROM" << endl;
    for (unsigned int t=0; t<sizeof(EEPROM_Value); t++) {
      *((char*)&EEPROM_Value + t) = EEPROM.read(t);
    }
  
  Serial << EEPROM_Value._azAdZeroOffset << endl;		// azAdZeroOffset value
  Serial << EEPROM_Value._elAdZeroOffset << endl;		// elAdZeroOffset value
  Serial << EEPROM_Value._azScaleFactor << endl;			// azimuth encoder scale factor
  Serial << EEPROM_Value._elScaleFactor << endl;			// elevation encoder scale factor
  Serial << EEPROM_Value._closeEnough << endl;			// value for catcing position
  Serial << EEPROM_Value._azimuthPark << endl;			// Position where the antenna is parked after a timeout
  Serial << EEPROM_Value._elevationPark << endl;			// 
  Serial << EEPROM_Value._rotationSpeed << endl;			// Actual rotation speed
  Serial << EEPROM_Value._rotationSpeed4 << endl;		// Rotator speed High
  Serial << EEPROM_Value._rotationSpeed3 << endl;		//
  Serial << EEPROM_Value._rotationSpeed2 << endl;		//
  Serial << EEPROM_Value._rotationSpeed1 << endl;		// Rotator speed Low
  Serial << EEPROM_Value._rotorParkInterval << endl;	// Duration after wich the rotors are parked
  Serial << EEPROM_Value.softwareVersion << endl;		// contains version number
}

Moving the structure definition out of the function gets rid of that error message.

PaulS: Moving the structure definition out of the function gets rid of that error message.

According to this http://arduino.cc/forum/index.php/topic,153823.msg1154610.html#msg1154610 schould is be possible.

According to this http://arduino.cc/forum/index.php/topic,153823.msg1154610.html#msg1154610 schould is be possible.

I think what that is saying is you can declare a variable of the appropriate struct type, but you wouldn't define the struct there.

gharryh: The only thing i dit was chancing EEPROM_value in EEPROM_Value and nothing else. I now do it the old fasioned way

I can't imagine why you wrote a function that reads the config and prints it, in a way that does not provide you any means to access the values that you read. Why on earth would you do it like that? All you need to do is declare a struct that holds the config values, write a function to read it from EEPROM (or use the simple pre-existing function that does the job for you) and write a function to print the content.

I can't imagine why you wrote a function that reads the config and prints it, in a way that does not provide you any means to access the values that you read. Why on earth would you do it like that?

It was a test. This is a follow-on from another thread.