Hi Claudecate,
probably there are spaces added to the end of string to grow all byte array length
Try something similar to
int writeStringToEEPROM(int addrOffset, const String &strToWrite)
{
byte len = strToWrite.length();
EEPROM.write(addrOffset, len);
for (int i = 0; i < len; i++)
{
EEPROM.write(addrOffset + 1 + i, strToWrite[i]);
}
return addrOffset + 1 + len;
}
int readStringFromEEPROM(int addrOffset, String *strToRead)
{
int newStrLen = EEPROM.read(addrOffset);
char data[newStrLen + 1];
for (int i = 0; i < newStrLen; i++)
{
data[i] = EEPROM.read(addrOffset + 1 + i);
}
data[newStrLen] = '\0';
*strToRead = String(data);
return addrOffset + 1 + newStrLen;
}
where the addrOffset is the start of eeprom and you can use String variable
String user = "ciccio";
String password = "passwd";
writeStringToEEPROM(0, user);
writeStringToEEPROM(32, password);
and to read
String user;
String password;
readStringFromEEPROM(0, &user);
readStringFromEEPROM(32, &password);
Bye Renzo