Pages: [1]   Go Down
Author Topic: load a file in eeprom  (Read 564 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 smiley-zipper 'lo there...

i try to load a txt file in my wonderful 24c01 used in i2c way..
what do you suggest me to use for load it into it ? string sequence ? stream ?
i'd look on the library, but i did not see exemple of file's handles.

ever test it ?  smiley-eek-blue many thanks
Logged

Offline Offline
Full Member
***
Karma: 4
Posts: 187
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i try to load a txt file in my wonderful 24c01 used in i2c way..
what do you suggest me to use for load it into it ? string sequence ? stream ?
i'd look on the library, but i did not see exemple of file's handles.

If your .txt file located in SdCard read the file in chunks(size of chunk must equal to size of EEPROM memory block)
http://fritzing.org/projects/readwrite-serial-eeprom-via-i2c/ for 24c01 interfacing
Logged

From Idea To Invention

Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 smiley-zipper yes i 'd ever test this fritzing beta and it works very nice.. smiley-mr-green

but instead of counting basicly, i want to push a little file.txt into it..(size=300 bytes) smiley-small
Logged

Offline Offline
Full Member
***
Karma: 4
Posts: 187
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but instead of counting basicly, i want to push a little file.txt into it..(size=300 bytes)

First Step
Reading a file from Sd Card
Code:
void readFile(char* file ,char *fileData)
{
  int16_t  readed;
  File myFile = SD.open(file,FILE_READ);

  if(myFile!=NULL){
    char* buf = (char*) malloc(myFile.size()+1);
    readed = myFile.read(buf,myFile.size());
    buf[readed]='\0';

    myFile.close();
    strcpy(fileData,buf);
    free(buf);
  }
  else
      strcpy(fileData,"Fail to open file");
}

Second step
call this funtion when you want to readfile for e.g file name test.txt

Code:
char fileData[300];
readFile("test.txt",fileData)

last step push data from fileData to EEPROM it's on you smiley-cool

One important point intialize the SD (Sd.begin(4)) in setup

« Last Edit: November 27, 2012, 08:02:19 am by Cybernetician » Logged

From Idea To Invention

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 617
Posts: 49463
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but instead of counting basicly, i want to push a little file.txt into it..(size=300 bytes)
What's wrong with counting? It's incredibly simple:
Code:
count++;
Read a character, write to EEPROM, increment the address. Repeat until the end of the file is reached.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 smiley-eek ok i going to see that...sd card libraries gives many idea about this...
thanks very much everyone....
 smiley-wink
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Read a character, write to EEPROM, increment the address. Repeat until the end of the file is reached.

Assuming you want to read the content back from EEPROM at some point, you'd need to provide some way to know how long the 'file' was. You might be willing to remember the number of bytes that were written and hard-code that value in the code to read it - it would work, although it isn't an elegant solution.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Pages: [1]   Go Up
Jump to: