Go Down

Topic: read and write on at24c16 with wire.h (Read 1 time) previous topic - next topic

saiona

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 ...

AWOL

A long variable is simply four bytes.

saiona

A long variable is simply four bytes.
can u write a code for this? its so hard :///////

AWOL

can u write a code for this? its so hard :///////
Yes I can, no, it isn't.

GolamMostafa

#4
Jul 23, 2018, 09:12 pm Last Edit: Jul 24, 2018, 04:45 am by GolamMostafa
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.

Code: [Select]
#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()
{

}



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

AWOL

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)

saiona

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

GolamMostafa

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).

saiona

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

GolamMostafa

#10
Jul 24, 2018, 09:47 am Last Edit: Jul 24, 2018, 10:12 am by 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:

Code: [Select]
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()) :
Code: [Select]
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?

saiona

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:

Code: [Select]
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()) :
Code: [Select]
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

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?

saiona

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?

GolamMostafa

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

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

Go Up