Go Down

Topic: load a file in eeprom (Read 607 times) previous topic - next topic

dr_no

:smiley-zipper: 'lo there...

i try to load a [font=Verdana]txt file[/font] 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

Cybernetician

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
From Idea To Invention

dr_no

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

Cybernetician

#3
Nov 27, 2012, 02:00 pm Last Edit: Nov 27, 2012, 02:02 pm by Cybernetician Reason: 1
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: [Select]

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

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


last step push data from fileData to EEPROM it's on you 8)

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

From Idea To Invention

PaulS

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: [Select]
count++;
Read a character, write to EEPROM, increment the address. Repeat until the end of the file is reached.

dr_no

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

PeterH


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.
I only provide help via the forum - please do not contact me for private consultancy.

Go Up