Pages: [1]   Go Down
Author Topic: multi dem arrays using data from EEPROM  (Read 911 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

im wanting to store some string data in the EEPROM.

what id like to know is if i can recall that data from the EEPROM and put it in a multi dem array.  I looked at the documentation in the reference and didnt see it mentioned.

each string is 10 bytes long and id like to be able to store it as following

ARRAY  keys[?] (
1 <= "1234567890"
2 <= "0987654321"
3 <= "1029384756" )

? will be determined by the ammount of data pulled form EEPROM.

Can i do something like that, and if i can what would i declare the main array as?
I want it to be numarically indexed but contain CHAR strings
« Last Edit: December 14, 2008, 08:12:34 am by dbunting » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i guess i should clarify that a little

the EEPROM would contain a string of chars

ARRAY [?] (
1 <= "asdfghjklz"
2 <= "zlkjhgfdsa"
3 <= "azsldkfjgh" )

ints i know can do defined as
int [3][10] (
{1,2,3,4,5,6,7,8,9,0}
{0,9,8,7,6,5,4,3,2,1}
{1,0,2,9,3,8,4,7,5,6} )

but i dont know if the same would work for chars.

better question, can i store chars in EEPROM?
Logged

Connecticut, US
Offline Offline
Edison Member
*
Karma: 2
Posts: 1036
Whatduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Once it is running, your program can stuff whatever it wants into EEPROM, but I don't think you can declare C data to go directly into EEPROM during the sketch-uploading process.  Instead, you use the EEPROM library of functions and your program writes things or reads things from it.

However, if your strings aren't changing, unless you're totally crammed for program space AND runtime memory, you probably want to put them into the program space ("progmem") instead.  There's an example on how to do this exact thing on the arduino site:  http://www.arduino.cc/en/Reference/PROGMEM

If you're really sure you want the strings in EEPROM, I guess you could make a temporary program that took your initial string values and put them into EEPROM, then replace the temporary program with your ultimate application.  I don't think the upload process modifies EEPROM at all.
« Last Edit: December 14, 2008, 05:45:08 pm by halley » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the eeprom will be storing 10byte RFID ids for use in a locking mechanism.
the sole reason for using the eeprom for storing these ids is so that they can be entered into the program without having to modify the sketch code using a computer, and to allow the values to be retained and recalled after a power cycle.

Im planning on posting all of the code once it is finished and im happy with it. im on revision 3 now

also i know i cant uset use the C syntax to insert and extract information from the eeprom, that will be done via the eeprom library and then parsed with c to create the array.  the recall and parsing would be done in setup() due to the fact that it will more then likely require some heavy lifting.  seeing as to how if i filled the eeprom space with data it could contain 51 sets of 10 byte IDs. they would be parsed into an array and subsiquently placed into progmem.  the only other time an eeprom read/write would take place is during a program ID routine

my main question is, how would i declare a numerically indexed multi-dimensional array of chars?  
« Last Edit: December 14, 2008, 10:26:33 pm by dbunting » Logged

Connecticut, US
Offline Offline
Edison Member
*
Karma: 2
Posts: 1036
Whatduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It depends on whether you have a need for variable-length character strings, or fixed-length character arrays.  If they're all RFID tags of the same length, you could just store them and calculate their addresses.  If not, you will have to have an index table to point to each string, or walk through the list of strings, to find a particular string.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

no they are all 10 byte
Logged

Connecticut, US
Offline Offline
Edison Member
*
Karma: 2
Posts: 1036
Whatduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

A useful definition to have, when working with arbitrary-length arrays:

Code:
#define countof(a)  ( sizeof(a) / sizeof(*(a)) )

A fixed width, arbitrary-length array of bytes:

Code:
byte rfids[][10] =
{
    { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A },
    { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A },
    { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A },
    { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A },
};

byte* p = rfids[3]; // pointer to rfid at index #3

A fixed width, fixed-length array of bytes is similar, just give the number of rows.  The compiler will complain if you don't match the number of rows expected and the actual rows given:

Code:
byte rfids[4][10] =
{
    { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A },
    { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A },
    { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A },
    { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A },
};

byte* p = rfids[3]; // pointer to rfid at index #3

If you really want them as char strings, terminated with zeros (easy for use with Serial.print() for example):

Code:
// takes 11 bytes per string due to '\0' terminators
// plus a separate index table of one pointer per string
char* rfids[] =
{
    "123456789A",
    "123456789A",
    "123456789A",
    "123456789A",
};

char* p = rfids[3]; // pointer to rfid at index #3

To put them into the EEPROM attic, I would make small custom functions that read or wrote an RFID array or string.  Then I could refer to EEPROM RFID #3 and retrieve it into a RAM string for use.
« Last Edit: December 15, 2008, 10:43:38 am by halley » Logged

Pages: [1]   Go Up
Jump to: