read and write on at24c16 with wire.h

hi . i wanna store a long number in at24c16 with wire.h library or another library .
pls help me i cant write long in at24c16 with wire.h . with eeprom just can write byte value ...
thans a lot ...

A long variable is simply four bytes.

AWOL:
A long variable is simply four bytes.

can u write a code for this? its so hard :///////

saiona:
can u write a code for this? its so hard :///////

Yes I can, no, it isn't.

saiona:
can u write a code for this? its so hard :///////

Let us try --

The following instructions will help you to write 1-byte data into one memory location of the 24C16 EEPROM. If you can follow what these code are doing, you will be able to write multiple data bytes into multiple locations.

#include<Wire.h>
byte busStatus;

void setup()
{
   
   Serial.begin(9600);
   Wire.begin();
   //check the presence of the chip by executing the following instructions
   
   do
   {
       Wire.beginTransmission(slaveAddress);
       busStatus = Wire.endTransmission();
    }
    while (busStatus != 0x00):

   Serial.print("EEPROM is Present...!)

   //point to the EEPROM location (say, 0x0100) where we want to store data byte 0x23;
    Wire.beginTransmission(slaveAddress);
    Wire.write(0x00); //higher byte of address
    Wire.write(0x10); //lower byte of address
    Wire.write(0x23);  //data for the EEPROM location
    Wire.endTransmission();

    delay(5);      //5 ms is required to get 1-byte data written into an EEPROM location

    //now write codes to read back the data from EEPROM location 0x0010 and show it on Serial Monitor.

    /* Hints:
        Point the EEPROM location address (0x0010)
        Execute the following code:
        Wire.requestFrom(slaveAddress, 1);     //request for 1-byte data
        byte x = Wire.read(); // read 1-byte data
        Show the data on Serial Monitor 
   */
}

void loop()
{

}

i wanna give one long like "2837384738" and store to 24c16 then read that and plus plus that and again save that ...
pls write thid code plsssss

saiona:
i wanna give one long like "2837384738" and store to 24c16 then read that and plus plus that and again save that ...
pls write thid code plsssss

Please you "want to".
"Wanna" sounds like a toddler asking for a biscuit.

You want to write the four bytes representing the value 0xA91F0E22 to EEPROM.
What have you tried?
(It's not like there aren't examples for this)

I cant write the code of four bytes. just write a code that get a long and thrn read four byte and change to long . Just this

saiona:
i wanna give one long like "2837384738" and store to 24c16 then read that and plus plus that and again save that ...
pls write thid code plsssss

You want to save this long ("2837384738") array of characters into EEPROM? Saving a character array (like this "2837384738") is different from saving a numerical value (like this 2837384738).

GolamMostafa:
You want to save this long ("2837384738") array of characters into EEPROM? Saving a character array (like this "2837384738") is different from saving a numerical value (like this 2837384738).

no i want to save a long . pls write that code

Yo have this number : 2837384738 (decimal). You can check using calculator that the equivalent binary number for it is (written in hex form for convenience): A91F0E22. In programming, the hex (binary value) value is automatically created when you declare/define like this:

long int x = 2837384738; //A9 1F 0E 22

There are 4-byte data in the corresponding hex number. You need to store them into 4 locations of the I2C Buffer by executing the following instructions (before they are transferred to destination by the I2C Bus commands : Wire.beginTransmission()/Wire.endTransmission()) :

for(int i = 0; i<4; i++)
{
   Wire.write(myData[i]);     //mydata[0] = A9, myData[1] = 1F and so on.
}

Now you feel that that you have to find out a way of split the value of x into 4-byte and store them in the array named byte myData[4];.

Try to do it? One programming inside another programming?

GolamMostafa:
Yo have this number : 2837384738 (decimal). You can check using calculator that the equivalent binary number for it is (written in hex form for convenience): A91F0E22. In programming, the hex (binary value) value is automatically created when you declare/define like this:

long int x = 2837384738; //A9 1F 0E 22

There are 4-byte data in the corresponding hex number. You need to store them into 4 locations of the I2C Buffer by executing the following instructions (before they are transferred to destination by the I2C Bus commands : Wire.beginTransmission()/Wire.endTransmission()) :

for(int i = 0; i<4; i++)

{
  Wire.write(myData[i]);    //mydata[0] = A9, myData[1] = 1F and so on.
}




Now you feel that that you have to find out a way of split the value of x into 4-byte and store them in the array named **byte myData[4];**. 

Try to do it? One programming inside another programming?

dear i have a headache till i write my code . pls write complete code . plsssss

If we write complete program for you, can you test it? Do you have UNO? Do you use paper/pencil to write down notes and whatever you have learnt something new?

GolamMostafa:
If we write complete program for you, can you test it? Do you have UNO? Do you use paper/pencil to write down notes and whatever you have learnt something new?

i write more than 15 code but all of them i think fault . and now i really stew :///////
can u write it for me?

Do you know what is Arduino UNO? Do you know what is IDE?

Please, post the 15 lines codes that you have written.

GolamMostafa:
Do you know what is Arduino UNO? Do you know what is IDE?

Please, post the 15 lines codes that you have written.

i think u cant help me ... thanks for attention :slight_smile:
if another person can help me pls write that code. i write my code here now that i write but dont work . :slight_smile:

You are second person whom I have got in this Forum as a Game Player?

GolamMostafa:
You are second person whom I have got in this Forum as a Game Player?

Im game player and you Edison !!!! Thanks for Help ...

We wanted to help you; but, you are playing game. The chance is still there to get help if you say that you have an Arduino UNO/NANO/MEGA/DUE Kit.

GolamMostafa:
We wanted to help you; but, you are playing game. The chance is still there to get help if you say that you have an Arduino UNO/NANO/MEGA/DUE Kit.

i have uno and i write code for internal eeprom to write in uno but in external eeprom i cant write code because wire.write just give 1 argument but eeprom.write give 2 argument. and now if u can help me do it pls.