# How does the EEPROM store int and char ?

**URL:** <https://forum.arduino.cc/t/how-does-the-eeprom-store-int-and-char/1424211>\
**Category:** General Guidance\
**Created:** [January 8, 2026, 3:29pm UTC](https://forum.arduino.cc/t/how-does-the-eeprom-store-int-and-char/1424211 "2026-01-08T15:29:01Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ardubit](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ardubit/32/264049_2.png) [@Ardubit](https://forum.arduino.cc/u/Ardubit)\
**Post date:** [January 8, 2026, 3:29pm UTC](https://forum.arduino.cc/t/how-does-the-eeprom-store-int-and-char/1424211/1 "2026-01-08T15:29:01Z")

</div>

I have a PC based App send in some data to my MEGA 2560 via Serial 1.

All good there and I am getting this into the MCU and then storing to EEPROM. The sample data is as below :

\<C,1000,PU,4375,200,9375,HL,4375,400,0,PD,2500,200,9375,HL,2500,400,0,NU,625,200,9375,HL,625,400,0,ND,2500,200,9375,HL,2500,400,0,E\>

Now I have defined the EEPROM storage space as all “int “ variables. So when I read back I am reading all numeric perfectly, but the Characters like C, PU etc are just reading zero. How to get the characters right.

For information I have given the code that stores the received characters on to the EEPROM below. I am not sure if this code needs to be corrected ?

```cpp
while ((parsedMsg = strtok(NULL, ",")) != NULL) {
      editParam[paramCount] = atoi(parsedMsg);
      paramData = editParam[paramCount]; // paramData has now the next data in the array
      EEPROM.put(eeAddress, paramData); // Save it to EEPROM
      eeAddress += sizeof(int); // Incrememnt for the next data
      paramCount = paramCount + 1;
    }

```

>

---

<div class="post-metadata">

**Author:** ![sonofcy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sonofcy/32/1283617_2.png) [@sonofcy](https://forum.arduino.cc/u/sonofcy)\
**Post date:** [January 8, 2026, 3:31pm UTC](https://forum.arduino.cc/t/how-does-the-eeprom-store-int-and-char/1424211/2 "2026-01-08T15:31:15Z")

</div>

If you want to store and retrieve char data then you probably need to define that part of the eeprom as holding char data. It's been a while but it's just a structure I think.

---

<div class="post-metadata">

**Author:** ![david\_2018](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/david_2018/32/1013044_2.png) [@david\_2018](https://forum.arduino.cc/u/david_2018)\
**Post date:** [January 8, 2026, 3:35pm UTC](https://forum.arduino.cc/t/how-does-the-eeprom-store-int-and-char/1424211/3 "2026-01-08T15:35:59Z")

</div>

Easiest method is to have a struct that holds all the character and numeric variables, then use put() to store the entire struct to EEPROM.

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [January 8, 2026, 3:51pm UTC](https://forum.arduino.cc/t/how-does-the-eeprom-store-int-and-char/1424211/4 "2026-01-08T15:51:28Z")

</div>

> [@Ardubit](#):
>
> ```arduino
> while ((parsedMsg = strtok(NULL, ",")) != NULL) {
> editParam[paramCount] = atoi(parsedMsg);
> 
> ```

The **PU** token is a string. How can you apply `atoi()` on it? You can't. For example:

```arduino
char str[] = "C, 1000";
char delim[] = ",";
char *token;

token = strtok(str, delim);
Serial.println(atoi(token)); //shows: 0 because C is not a decimal digit
Serial.println(token); //shows: C
//---------------------------
token = strtok(NULL, delim); 
Serial.println(atoi(token)); //shows: 1000

```

You need to seperate the integer type tokens from that of the string type tokens using `if-else` structure.

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [January 8, 2026, 6:46pm UTC](https://forum.arduino.cc/t/how-does-the-eeprom-store-int-and-char/1424211/5 "2026-01-08T18:46:22Z")

</div>

> [@Ardubit](#):
>
> I have defined the EEPROM storage space as all “int “ variables.

That will make sense, and your question will be easiest to answer if you post the code.

EEPROM is addressed as bytes at the low level. Any other interpretation of stored bytes is up to you.

There are some functions for integers, I think.

Using _struct_ (structured variable) has been mentioned. I mention it again.

a7

---

<div class="post-metadata">

**Author:** ![cattledog](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cattledog/32/217816_2.png) [@cattledog](https://forum.arduino.cc/u/cattledog)\
**Post date:** [January 8, 2026, 6:48pm UTC](https://forum.arduino.cc/t/how-does-the-eeprom-store-int-and-char/1424211/6 "2026-01-08T18:48:10Z")

</div>

> [@Ardubit](#):
>
> I have a PC based App send in some data to my MEGA 2560 via Serial 1.

As @david_2018 suggests the optimum way of handling complex eeprom storage is to put all the data into a struct and store that. You may be able to send a struct from the pc, but the issues of cross platform compatibility may be troublesome.

Your issue is indeed the parsing of the input character string into the variables of the struct for storage. Your approach using strtok on the comma and then using either atoi or strcpy on the pieces should work.

```arduino
<C,1000,PU,4375,200,9375,HL,4375,400,0,PD,2500,200,9375,HL,2500,400,0,NU,625,200,9375,HL,625,400,0,ND,2500,200,9375,HL,2500,400,0,E>

```

Can you explain to what variables you would assign the numbers and letters of the input string? What do you do with the data when you retrieve it from the EEPROM?

---

<div class="post-metadata">

**Author:** ![camsysca](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/camsysca/32/1015228_2.png) [@camsysca](https://forum.arduino.cc/u/camsysca)\
**Post date:** [January 8, 2026, 9:44pm UTC](https://forum.arduino.cc/t/how-does-the-eeprom-store-int-and-char/1424211/7 "2026-01-08T21:44:17Z")

</div>

Additional question - can the line be presented with the tokens, and their values, in any order? Or can you be guaranteed the line will be as shown, in the order shown? Because it changes parsing a lot, if you have to read the token to decide which variable to write.

---

<div class="post-metadata">

**Author:** ![kenb4](https://avatars.discourse-cdn.com/v4/letter/k/bb73d2/32.png) [@kenb4](https://forum.arduino.cc/u/kenb4)\
**Post date:** [January 9, 2026, 12:42am UTC](https://forum.arduino.cc/t/how-does-the-eeprom-store-int-and-char/1424211/8 "2026-01-09T00:42:55Z")

</div>

In programming, `char` is a single character. I see `C` at the beginning and `E` at the end. But all the ones in the middle have two characters: `PU`, `HL`, etc.

If they're all that short, the text can be encoded as a number. On AVR boards like Mega, an `int` is two bytes, so up to `32767` for a signed integer. If the numeric values are non-negative, that means you can use the sign bit to indicate the encoding of two 7-bit ASCII values in the same two bytes. So you use EEPROM to store/retrieve all as `int`, and then encode/decode appropriately.

ETA: 26 letters fit into five bits, so if it's just (case-insensitive) letters, you can squeeze three plus the sign bit into two bytes.

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [January 9, 2026, 5:41am UTC](https://forum.arduino.cc/t/how-does-the-eeprom-store-int-and-char/1424211/9 "2026-01-09T05:41:24Z")

</div>

@Ardubit

Please, post your whole sketch so that it is possible to know the usage of your tokens and how you are saving them into EEPROM and retrieve.

---

<div class="post-metadata">

**Author:** ![Ardubit](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ardubit/32/264049_2.png) [@Ardubit](https://forum.arduino.cc/u/Ardubit)\
**Post date:** [January 9, 2026, 5:56am UTC](https://forum.arduino.cc/t/how-does-the-eeprom-store-int-and-char/1424211/10 "2026-01-09T05:56:16Z")

</div>

I have gone through all the responses and thank each one of you for taking time to help !! I will now try and address all your queries in this reply to the extent possible :

The string that you see defines one complete pressure profile for one cycle and has these parts :

> [@cattledog](#):
>
> `<C,1000,PU,4375,200,9375,HL,4375,400,0,PD,2500,200,9375,HL,2500,400,0,NU,625,200,9375,HL,625,400,0,ND,2500,200,9375,HL,2500,400,0,E>`

1. C : Cycles . Other option is H for hours to execute
2. 1000 : Number of Cycles to execute
3. PU : Positive Up Ramp
4. 4375 : End voltage of 4.375 at the end of Ramp
5. 200 : Number of 5ms loops to execute
6. 9375 : 0.009375 V to increment for each scan. ( Being BiPolar 2.5V is the Zero base )
7. HL : Hold at the end of Ramp
8. PD : Positive Down Ramp
9. NU: Negative Up Ramp
10. ND : Negative down ramp
11. E : End of the cycle.

You should now get an idea of teh string … the cycle pattern is very random and the user will anyway break it down to up and down ramps and enter the values in the PC application which will then transfer the above string to the MCU.

The MCU then executes the pattern using a switch case for PU/PD/HL/NU/ND and using the number of scans and volt/scan input to generate the pattern.

I thought about the Structure but then the number of sequences per cycle is open ended and can be simple as above and get very complex. So I thought its better to have a uniform storage pattern for the EEPROM but in this process missed out the Char aspect.

If I were to avoid mixing up data types can I use the INT as the only type and cast the characters like C/PU/HL/PD/NU/ND/E to unique integers as 1/2/3/4/5/6/7 . These single digits can never be part of any sequence as all single precision voltage values are multiplied by 100 to convert to int and transmitted. I think that will be the easy way out ??

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [January 9, 2026, 6:08am UTC](https://forum.arduino.cc/t/how-does-the-eeprom-store-int-and-char/1424211/11 "2026-01-09T06:08:14Z")

</div>

> [@Ardubit](#):
>
> These single digits can never be part of any sequence as all single precision voltage values are multiplied by 100 to convert to int and transmitted. I think that will be the easy way out ??

If you sepertae the numeric tokens (1000, 4375, …) from that of the alphabetic/string type tokens (C, PU, …), will it work? Save the tokens in their respective arrays, store them in EEPROM, retrieve them from EEPROM, and then use them.

```arduino
String tokens:
C
PU
HL
PD
HL
NU
HL
ND
HL
E

Integer tokens:
1000
4375
200
9375
4375
400
0
2500
200
9375
2500
400
0
625
200
9375
625
400
0
2500
200
9375
2500
400
0

```

---

<div class="post-metadata">

**Author:** ![kenb4](https://avatars.discourse-cdn.com/v4/letter/k/bb73d2/32.png) [@kenb4](https://forum.arduino.cc/u/kenb4)\
**Post date:** [January 9, 2026, 6:31am UTC](https://forum.arduino.cc/t/how-does-the-eeprom-store-int-and-char/1424211/12 "2026-01-09T06:31:41Z")

</div>

> [@Ardubit](#):
>
> can I use the INT as the only type and cast the characters like C/PU/HL/PD/NU/ND/E to unique integers as 1/2/3/4/5/6/7 . These single digits can never be part of any sequence

Sure, although "cast" has a specific meaning in C/C++, so maybe "translate" or "convert" instead. I do see zero as a numeric value.

You could use negative integers to have better separation. And there are plenty of them, so maybe -1 to -3 for E, C, H. -10 and so on for the two-letter ones, or start at -20 or -100, however you want to divide up the functionality.

---

<div class="post-metadata">

**Author:** ![Ardubit](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ardubit/32/264049_2.png) [@Ardubit](https://forum.arduino.cc/u/Ardubit)\
**Post date:** [January 9, 2026, 7:28am UTC](https://forum.arduino.cc/t/how-does-the-eeprom-store-int-and-char/1424211/13 "2026-01-09T07:28:01Z")

</div>

Sorry about the word “cast” used casually here !!

Yes I will try and use negative single digit numbers to make them unique ! And go back to my original plan of saving all the parts of the sequence as only INT variables.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 8, 2026, 7:28am UTC](https://forum.arduino.cc/t/how-does-the-eeprom-store-int-and-char/1424211/14 "2026-07-08T07:28:10Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
