EEPROManything.h

I`m writing 230 to eeprom but getting back 50.

#include "EEPROManything.h"

const byte eeprom_key = 180;

void setup() {

  Serial.begin(9600);
  // put your setup code here, to run once:

  char _key[] = "50";

  char _new_key[] = "230";

  byte old_key = (byte)atoi(_key);

  byte key_to_compare = 0;

  EEPROM_readAnything(eeprom_key, key_to_compare);

  Serial.println(key_to_compare);

  if (key_to_compare != 255 && key_to_compare != 0) if (old_key != key_to_compare)Serial.println("something happened");

  byte new_key = (byte)atoi(_new_key);

  Serial.print("new key=");

  Serial.println(new_key);

  EEPROM_writeAnything(eeprom_key, _new_key);

  Serial.println("eeprom written");

  byte from_eeprom = 0;

  EEPROM_readAnything(eeprom_key, from_eeprom);

  Serial.print("read from eeprom");

  Serial.println(from_eeprom);


}

void loop() {
  // put your main code here, to run repeatedly:

}

OUTPUT

50
new key=230
eeprom written
read from eeprom50

You might be interested to know that the official Arduino EEPROM library has the same functionality via EEPROM.put() and EEPROM.get():

These "EEPROManything" type of libraries were useful years ago when the official library didn't have that functionality but these days using them is pointless.

i was always using this one without any problems so far. But for this portion of code i cant figure out where that 50 is comming from?

@Pert thank you for this one after reading reference its better than eepromanything and no need to check if value is same in eeprom not to overwrite.

problem is _new_key instead of new_key in EEPROM_writeAnything(eeprom_key, _new_key);

Thanks Juraj!

After switching all eeprom requests from eepromanything to eeprom.h I got this error

Arduino: 1.8.6 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\plutus\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\EEPROM\src/EEPROM.h: In function 'long& EEPROMClass::get<long>(int, long&) [clone .isra.6] [clone .constprop]':

C:\Users\plutus\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\libraries\EEPROM\src/EEPROM.h:135:5: internal compiler error: Segmentation fault

     }

     ^

Please submit a full bug report,

with preprocessed source if appropriate.

See <http://gcc.gnu.org/bugs.html> for instructions.

lto-wrapper.exe: fatal error: D:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-gcc returned 1 exit status

compilation terminated.

d:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

problem is here in my code I defined address with byte not int because its within byte (0-255).
const byte eeprom_key = 180;

after changing to int compiled ok.

same if writing char array to eeprom if in for loop counter is declared as byte and I`m going to write 20chars compiler doesnt like that and want me to change counter variable from byte to int.

is this a bug?

havent problem like this with EEPROManything.h

same code with EEPROManything.h

Sketch uses 21590 bytes (66%) of program storage space. Maximum is 32256 bytes.
Global variables use 827 bytes (40%) of dynamic memory, leaving 1221 bytes for local variables. Maximum is 2048 bytes.

same code with EEPROM.h

Sketch uses 21670 bytes (67%) of program storage space. Maximum is 32256 bytes.
Global variables use 827 bytes (40%) of dynamic memory, leaving 1221 bytes for local variables. Maximum is 2048 bytes.

80byte less if using EEPROManything.h!

EEPROM library put and get are template functions. To match a template function, the parameters must match. The compiler should not crash on this. You can use byte variable, only add a cast before the use in put or get function for the compiler to match the template. EEPROM.put((int) eeprom_key, value)

The segmentation fault error is specific to the new avr-gcc 5.4.0 version used in Arduino IDE 1.8.6/Arduino AVR Boards 1.6.22:

Unfortunately there doesn't seem to be much progress on this issue so I suspect Arduino IDE 1.8.7/Arduino AVR Boards 1.6.23 will have the same problem. At least Arduino IDE 1.8.7 will allow us to roll back to the last good version of Arduino AVR Boards (1.6.21).

Yes i have tested now and 1.6.23 have same trouble.. Segmentation fault..i hope an update4 soon..