I'm trying to build a random string, save it to EEPROM as int, then read it back and output it.
If I give it a predefined string then it works fine. But Something is wrong with the random string generator.
String output;
char letter;
String mystr=""; //"ABCabc123..";
String characters = "ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz";
String numbers = "0123456789";
String other = "<>!.,()?|=&%¤#";
// add random characters to empty string
for(int i=0 ; i < 12 ; i++){
mystr += characters[random(0, characters.length())];
}
// add two numbers, one other and two more characters
mystr += numbers[random(0, numbers.length())];
mystr += numbers[random(0, numbers.length())];
mystr += other[random(0, other.length())];
mystr += characters[random(0, characters.length())];
mystr += characters[random(0, characters.length())];
// loop the string and place one character in each EEPROM address
for(int i=0 ; i < mystr.length() ; i++)
{
EEPROM.writeInt( i,mystr[i] );
}
// read the string back from EEPROM
for(int i=0 ; i < 17 ; i++){
letter = EEPROM.readInt(i);
output += letter;
}
If I run the code output will be "H". Every time.
If I use the predefined string "ABCabc123.." then it works correct.
What am I doing wrong with building the mystr?
EEPROM.writeInt()
andEEPROM.readInt()
don't look like standard Arduino functions. Where did you get them? Also note that “¤” is not an ASCII character. It takes two bytes if you write it in UTF-8.