Creating 3d table in external EEPROM (24LC256)

Hi everyone,

I am using an Arduino Uno and I recently connected it with an external EEPROM (24LC256 to be exact).

I used this library --> Arduino Playground - I2CEEPROM24C1024
and everything works smoothly.
So, after achieving writing and reading by byte, I want to be able to create a 3d table on the EEPROM and be able to write and read to/from this table.

I checked out here --> Arduino Playground - ExtendedDatabaseLibrary
but the example describes the creation of a 2d table on the internal EEPROM.
So, if anyone could help me/give me any kind of hints on that, I would appreciate it.

Thanks in advance.

the trick is to create an address formula,

suppose you have
byte cube[10][8][12];

then an address can be calculated

uint16_t getCubeAddr(byte x, byte y, byte z)
{
return x812 + y*12 + z;
}

for cube's that have larger datatypes you need to multiply the address with the size of one element.

Splendid idea! Thanks a lot.

you can do this for any number of dimensions and sizes (in theory)

The compiler can help you with that.

byte cube[10][8][12] EEMEM;

uint16_t getCubeAddr(byte x, byte y, byte z)
{
   return (uint16_t) &cube[x][y][z];
}

uint16_t ptr = getCubeAddr(2,1,0);

An alternative avoiding using the EEMEM address space is a template function.

template<class M> 
uint16_t getAddr(uint8_t x, uint8_t y, uint8_t z, M m = NULL)
{
  return (uint16_t) &m[x][y][z];
}
typedef byte CUBE[10][8][2];
uint16_t ptr = getAddr<CUBE>(2,1,0);

Cheers!