external eeprom storage

hello , this is a counter program and counter value stored in eeprom, but i have a problem with storage it store only 255 count and rest to 0, i want to store 999999 cunt what to do.

[code]
#include "Wire.h"
#include <LiquidCrystal.h>
#define EEPROM_I2C_ADDRESS 0x50
LiquidCrystal lcd(12,11,5,4,3,2);
int enter =7;
int shift =8;
int inc =9;
int menu=10; 
int no=1;
int Key;
int key=1;
int x=0; 
byte val = 11;
int address = 0;
 byte readVal ;
void setup() 
{
  lcd.begin(20,4);
  Wire.begin();
  analogWrite(6,x);  //Display intensity
pinMode(enter,INPUT_PULLUP);
pinMode(shift,INPUT_PULLUP);
pinMode(inc,INPUT_PULLUP);
pinMode(menu,INPUT_PULLUP);
 
  byte readVal = readAddress(address);
  lcd.setCursor(0,0);
  lcd.println("Last count:");
  lcd.setCursor(11,1);
  lcd.println(readVal);


  
  


}
void Key_Scane()
{
  bool key_input ;
  Key=0;
  key_input = digitalRead(enter);
  if (key_input==0)  {delay(100); if (key_input==0) {Key='E'; return ;}}
  key_input = digitalRead(shift);
  if (key_input==0)   {delay(100); if (key_input==0) {Key='S'; return ;}}
  key_input = digitalRead(inc);
  if (key_input==0)   {delay(100); if (key_input==0) {Key='I'; return ;}}
  key_input = digitalRead(menu);
  if (key_input==0)  {delay(100); if (key_input==0) {Key ='M' ; return ;}}                                                                                                                
}

void writeAddress(int address, byte val)
{
  Wire.beginTransmission(EEPROM_I2C_ADDRESS);
  //Wire.write((int)(address >> 8));   // MSB
  Wire.write((int)(address &  0xFF)); //LSB 
  
  Wire.write(val);
  Wire.endTransmission();

  delay(5);
}

byte readAddress(int address)
{
  byte rData = 0xFF;
  
  Wire.beginTransmission(EEPROM_I2C_ADDRESS);
  
//  Wire.write((int)(address >> 8));   // MSB
  Wire.write((int)(address &  0xFF)); //LSB 
  Wire.endTransmission();  


  Wire.requestFrom(EEPROM_I2C_ADDRESS, 1);  

  rData =  Wire.read();

  return rData;
}
void loop() 
{
  while(1)
  {Key_Scane();
    readVal = readAddress(address);
   val=readVal;
    if(Key=='I'){ val++;
      
    
  writeAddress(address, val); 
   readVal = readAddress(address);
  lcd.clear ();
  lcd.print("Total Count: ");
  lcd.println(readVal);
  delay(500);  
    }}

}

[/code]

The code only seems to read and write 1 byte. 99999 = 0x01869f which needs 3 bytes to store.

FYI

https://www.arduino.cc/en/Reference/EEPROMPut

The question is a bit vague. Have you looked on any of the many fine EEPROM tutorials online? Have you tried any of the examples included in your IDE. Have you tried any of the examples; try them they are good.

CrossRoads: The code only seems to read and write 1 byte. 99999 = 0x01869f which needs 3 bytes to store.

thank u sir, but i don,t know how to break any large number into more than 2,3,8 byte and ho to club byte into a large nuber

larryd: FYI

https://www.arduino.cc/en/Reference/EEPROMPut

thank u sir, but i want to know how to break 20 number into byte to store it. club the bytes to got broken number.

@mohitnama400 - why did you submit a Report to moderator ?

thank you sir, sir but i don,t know how break a integer value into 3 or more than 3 byte, and i want know what is the process to break large number into byte vice versa.

“ sir but i don,t know how break a integer value into 3 or more than 3 byte, and i want know what is the process to break large number into byte vice versa.”

unsigned long bigNumber = 4294967295;

byte array[4];

array[0] = bigNumber & 0xFF; array[1] = (bigNumber >> 8 ) & 0xFF array[2] = (bigNumber >> 16) & 0xFF array[3] = (bigNumber >> 24) & 0xFF


OP, do you understand what is meant by ‘data types’:

byte, int, long ?

larryd: “ sir but i don,t know how break a integer value into 3 or more than 3 byte, and i want know what is the process to break large number into byte vice versa.”

unsigned long bigNumber = 4294967295;

byte array[4];

array[0] = bigNumber & 0xFF; array[1] = (bigNumber >> 8 ) & 0xFF array[2] = (bigNumber >> 16) & 0xFF array[3] = (bigNumber >> 24) & 0xFF


thank for this precious advice , but this is half solution of my problem, please suggest how to combine these 4 byte into bigNumber

You should read and understand shift left << and shift right >>.

Left
https://www.arduino.cc/reference/tr/language/structure/bitwise-operators/bitshiftleft/

Right
https://www.arduino.cc/reference/en/language/structure/bitwise-operators/bitshiftright/

Do you know the memory is arranged as bytes and you can only read or write one byte at a time. It does not know nor care what the bytes are or what they indicate, that is your softwares job. To save a three byte number you will need to write them in three different locations, typically sequentially but not required.

A different way:

// https://forum.arduino.cc/t/external-eeprom-storage/703499/2

unsigned long bigVar = 0xFF5500AA;
unsigned long bigVar2 = 0;
byte storeBig[4];

void setup() {
  Serial.begin(115200);
  Serial.println("-- start --");
  Serial.print("original number\t");
  Serial.println(bigVar, 16);

  memcpy(&storeBig[0], &bigVar, 4);

  Serial.print("broken apart\t");
  for (char i = 3; i >= 0; i--) {
    Serial.print(storeBig[i], 16);
    Serial.print(' ');
  }
  Serial.println();

// put it back together
  memcpy(&bigVar2, &storeBig[0], 4);
  
  Serial.print("reconstructed\t");
  Serial.println(bigVar2, 16);
}

void loop() {
}