Saving arrays in EEPROM using ARDUINOMEGA

SRY AAAAAAA,I didn't upload it (getting late shit)!!
Ok so 323 :smiley:
One more question before you kill me please.
So 323 is stored in address 0?

tnx again

So 323 is stored in address 0?

Don't be afraid, I won't kill you!

No, 323 cannot be stored in address zero because 323 is too big to be stored in a single byte, so it is stored in address 0 and address 1.

No, 323 cannot be stored in address zero because 323 is too big to be stored in a single byte, so it is stored in address 0 and address 1.

Which is why EEPROM_readAnything returned 2. That is the next available address to write to/read from.

It is stored in address 0 1 and 2 i think.

#include <EEPROM.h>
template <class T> int EEPROM_writeAnything(int ee, const T& value)
{
    const byte* p = (const byte*)(const void*)&value;
    int i;
    for ( i = 0; i < sizeof(value); i++)
	  EEPROM.write(ee++, *p++);
    return i;
}

template <class T> int EEPROM_readAnything(int ee, T& value)
{
    byte* p = (byte*)(void*)&value;
    int i;
    for (i = 0; i < sizeof(value); i++)
	  *p++ = EEPROM.read(ee++);
    return i;
}
void setup()
{
  Serial.begin(9600);
  int reference = 323;
  int serial;
 
  EEPROM_writeAnything(0, reference);
  //EEPROM_readAnything(0,serial);
  serial = EEPROM.read(0) + EEPROM.read(1) + EEPROM.read(2);
       
  Serial.print(serial);
}
void loop()
{}

serial = EEPROM.read(0) + EEPROM.read(1) + EEPROM.read(2);
Removing read(2) will not give 323

It is stored in address 0 1 and 2 i think

Think again.

serial = EEPROM.read(0) + EEPROM.read(1) + EEPROM.read(2);
This 'prints' 323

serial = EEPROM.read(0) + EEPROM.read(1)
This 'prints' 68

why then??
(And hehe i am on a laptop so shaking my keyboard wont make it that better :p)

tnnx

The value is not stored digit by digit in consecutive addressed. I think you need to go back and look at reply #11 (not to sound like a broken record or anything).

"You provide the first EEPROM address to be written, and the functions return how many bytes were transferred."
So if in this code it returns 2, meaning 2 bytes were transferred right?

But still I cannot understand the fact that using the code; EEPROM.read(0) + EEPROM.read(1) it 'prints' 68.

I'm sorry if im being such a bi*** but I really need to understand this

tnx again

The function returns the high byte and the low byte on the two calls. The integer is constructed by shifting the high byte 8 places to the left and adding the low byte, as was shown in reply #11. It is NOT constructed by simply adding the two bytes.

The values that you are getting are 1 and 67. Shifting the 1 8 places is equivalent to multiplying by 256. So, 256 + 67 = ? That's right. 323.

aaaaaaaaaaaaaa tnx!!!!!!

now for tomorrow to continue looking in this....

TNX ALL!!!

serial = EEPROM.read(0) + EEPROM.read(1) + EEPROM.read(2);
Removing read(2) will not give 323

In case you were wondering:
323 decimal = 0x0143

0x01 + 0x43 + 0xFF (the contents of address 2, because you haven't written anything to it) = 0x143 = 323.

Another question pls...

If for example I need integer 1511. I thought that it would need 3 bytes but 2 are needed(serialmonitered it).

Reading addreses 0 and address 1 i get these values
address 0 - 231
address 1 - 5

So my question is, (looking at reply11), 5 is the HIGH byte right?
How is it worked out?
Moving 5 - 101B to shift 8 places - 10100000000 - 1280??
Adding 231 = 1511

Is this right?
tnx

What is 101B, where did it came from?

But if your high byte is 5, then 5 * 256 =1280. That is correct.
1280 + 231 =1511, so that is true as well.

Kari

What is 101B, where did it came from?

5 in binary.

OP: Start thinking in hex.
1511 is 0x05E7, so two bytes only, 0x05 and 0xe7.

AWOL:

What is 101B, where did it came from?

5 in binary.

OP: Start thinking in hex.
1511 is 0x05E7, so two bytes only, 0x05 and 0xe7.

I'm dummy. That "B" confused me, I though IT WAS hex 101B. I don't know how they should be expressed in these posts, I like to say "bin" or "hex" just to be sure, not combining binary and decimals in the same sentence.
:wink:

Cheers,
Kari

EDIT. By the way, what does the "OP:" stand for? OT= off topic, but OP?

Original Poster

AWOL:
Original Poster

Ok, I though it was for me.

This has been very enlighten conversation for me, only thing that bothers me is the short lifeline of the internal eeprom.

If I decide to use external eeprom IC, is there anything that makes life easier or more complicated, comparing to internal eeprom? Is it faster or exactly opposite? Programming issues are more likely the biggest consern, not the speed.

Cheers,
Kari

only thing that bothers me is the short lifeline of the internal eeprom.

I thought the retention time was of the order of a century - do you plan on leaving your Arduino to your grandchildren?

AWOL:

only thing that bothers me is the short lifeline of the internal eeprom.

I thought the retention time was of the order of a century - do you plan on leaving your Arduino to your grandchildren?

Heh, no. But isn't there a limited rewrites with the eeprom? I would like to use to store online information for measurements and stats for later reading. Eeprom is quite small, but certai information need to sotred somewhere if communication with outworld is not available all the time. If device (autonomus idioticus) restarts, it need to have location and few extra data available, until it is linked to main system again.

How many times I can actually rewrite that little memory bank? I was in that belief that is limited, depending of the MCU, from hunderthousand to million times?

Cheers,
Kari

How many times I can actually rewrite that little memory bank?

How many licks does it take to get to the center of a Tootsie Pop? No one knows.

Atmel guarantees 100,000 erase-writes. In order to make that guarantee, the average part has to be able to reach a far higher number before a failure occurs.