Converting from int to string then back again?

I am trying to save data to eeprom and read from with this code

byte out;

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

}

void loop() {

  if (digitalRead(3) == 1) {
    //v(30); delay(1000);           // "temperature"
    //v(38); delay(1000);           // "threshold"
    //v(20); delay(800);            // "low"
    int b = analogRead(A3);
    Serial.println(b);
    int a = map(b, 0, 1023, -10, 30); // map analog value to from -10 to 30
    Serial.println(a);
    String TTL;
    TTL = String(a);
    Serial.print(TTL); Serial.println(a);


    if (TTL.startsWith("-")) {
      //v(12); delay (1500);
      char fd = TTL.charAt(1);
      Serial.println(fd);
      //v(fd); delay(800);
      char sd = TTL.charAt(2);
      Serial.println(sd);
      //v(sd); delay(800);
    }
    else {
      char fd = TTL.charAt(0);
      //v(fd); delay(800);
      char sd = TTL.charAt(1);
      //v(sd); delay(800);
    }
    //v(33); delay(1000);       //degrees
    //v(21); delay(1000);       //press
    //v(9);  delay(800);        //nine
    //v(2);  delay(800);        //to
    //v(22); delay(2000);       //confirm
    if (digitalRead(9) == 1) {
      while (!eeprom_is_ready()) {
        cli();
        eeprom_write_byte((uint8_t*)0, TTL);
        sei();
        //v(39); delay(1000);
        Serial.print("written to eeprom:"); Serial.print(TTL);
        while (!eeprom_is_ready()) {
          cli();
          out = eeprom_Read_byte((uint8_t*)0);
          sei();
          Serial.print("read from eeprom:"); Serial.print(out);
        }
      } delay(3000);
    }

firstly i am converting the byte to a string, this is so i can access it easily using charAt to isolate the individual characters in the byte - each individual characters (well digits) are then used to play a voice file representing that digit.

however when it comes to save to eeprom i get this stauts

cannot convert 'String' to 'uint8_t {aka unsigned char}' for argument '2' to 'void eeprom_write_byte(uint8_t*, uint8_t)'

Now i could just convert back the string or make a separate variables for both. But is it possible to just save the string in eeprom, not to sure how eeprom like strings and don't really want to be having double variables for what will be a very minor part of the program

thanks for looking

Where is eeprom_write_byte defined? Some EEPROM library you didn't show the include statement for? The usual way to store different types is the put() method of the EEPROM library listed on this site. The question of, "can I store a String class variable in EEPROM using put(), I don't know the answer. It's worth a look, though...

cannot convert ‘String’ to ‘uint8_t {aka unsigned char}’ for argument ‘2’ to ‘void eeprom_write_byte(uint8_t*, uint8_t)’

this is saying that it expects the 2nd argument to be an uint8_t but it’s finding a String variable (i.e. TTL).

the 2nd argument should be some integer value

seems you are trying to use the avr-libc eeprom functions

the doc says that the function void eeprom_write_byte( uint8_t* __p, uint8_t __value) will write ONE single byte __value to EEPROM address __p, so that won't work to save a String or any complex object that does not fit on one byte...

any reason not to use the standard EEPROM library ? much easier...

Also, thinking architecturally, do you really need to store the string itself in EEPROM? If it is just a voice sample selection, you could translate the string into some kind of integer song index value that would be easier to store. If you limit yourself to 256 songs, you can use a byte with the eeprom_write_byte() method.

thanks for the replies guys,

J-M-L: seems you are trying to use the avr-libc eeprom functions

the doc says that the function void eeprom_write_byte( uint8_t* __p, uint8_t __value) will write ONE single byte __value to EEPROM address __p, so that won't work to save a String or any complex object that does not fit on one byte...

any reason not to use the standard EEPROM library ? much easier...

Yes Ive been confusing things really, firstly a byte is unsigned, so its no good in any case so i decided to go with word. that was after realizing that im trying to save a string. The INT was always there so made a mountain out of a molehill.

aarg: Also, thinking architecturally, do you really need to store the string itself in EEPROM? If it is just a voice sample selection, you could translate the string into some kind of integer song index value that would be easier to store. If you limit yourself to 256 songs, you can use a byte with the eeprom_write_byte() method.

Thats not quite what im looking for, I was totally wrong about the string as i have said in reply to J-M-L. Really was just getting ahead of my self, If interested I have started a post (which i have just realized is probably wrong to do as its really a continuation of what is asked here.) sorry for annoyances. MODS - cane me please.

its about some kind of glitch...

link to post https://forum.arduino.cc/index.php?topic=667691.0

Don’t confuse String with string.

A String (on an AVR) uses six bytes of RAM - you don’t want to be saving those in EEPROM.