Pages: [1]   Go Down
Author Topic: Put long string in flash memory  (Read 693 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 67
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
    i need to store (read,write) 5 string like this "05000005329000" in the flash memory so when the arduino is power off it will keep the data in. I checked the eeprom fonction but it only one byte, i'm a little lost with that. and it is possible to create a list and able to modified it so if a sting is equal with a string in the list then do it?

Thanks in advance
Like i say i checked on the net but i'm lost whit that
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 613
Posts: 49248
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i need to store (read,write) 5 string like this "05000005329000" in the flash memory so when the arduino is power off it will keep the data in.
You can't write to flash memory at run time.

Quote
I checked the eeprom fonction but it only one byte
One byte per call. So, call it more than once.

Logged

Worst state in America
Offline Offline
God Member
*****
Karma: 32
Posts: 799
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
    i need to store (read,write) 5 string like this "05000005329000" in the flash memory so when the arduino is power off it will keep the data in. I checked the eeprom fonction but it only one byte, i'm a little lost with that. and it is possible to create a list and able to modified it so if a sting is equal with a string in the list then do it?

Thanks in advance
Like i say i checked on the net but i'm lost whit that

You can use PROGMEM to "compile in" your string into flash (program memory) and then read it out later.

If you need to write and re-write string data, then you need EEPROM. Why not do it this way:

Code:
    const char *string1 = "05000005329000";
    const char *string2 = "I am a string of a different length";
    int x;
    int address = 0; // base address to write or read the string
    for (x = 0; x < strlen(string1); x++) {
        EEPROM.write(address + x, string1[x]); // write string #1 to EEPROM
    }
    address += strlen(string1); // point to next free EEPROM area
    for (x = 0; x < strlen(string2); x++) {
        EEPROM.write(address + x, string2[x]); // write string #2 to EEPROM
    }

Only thing you have to do is somehow keep track of where each string is stored and how long it is!

Hope this helps.
Logged

Gentlemen may prefer Blondes, but Real Men prefer Redheads!

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

Thanks,
           yes it will help. could you tell me how to read it after that.
Logged

Worst state in America
Offline Offline
God Member
*****
Karma: 32
Posts: 799
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks,
           yes it will help. could you tell me how to read it after that.


Code:
    char buffer[32]; // must be at least as large as the stored string!
    int x;
    int address = 0; // base address where you stored the string
    for (x = 0; x < 32; x++) { // assume the string was 32 bytes long
        buffer[x] = EEPROM.read(address + x); // read EEPROM into buffer, 1 byte at a time
    }
    // "buffer" now contains the string that was stored in EEPROM

Hope this helps.....
Logged

Gentlemen may prefer Blondes, but Real Men prefer Redheads!

Pages: [1]   Go Up
Jump to: