How big are the matrices?
If they are 512 bytes, or less, use the onboard EEPROM.
You can load and store at any time in the program, just do it when it's needed.
The code is pretty simple.
It's a holiday, so though this looks a bit homeworkey ...
Here's a pseudo-example of loading and storing a 16x16 'maze' (it compiles, but I HAVE NOT TESTED IT, so be careful).
Reading back should be comparably straightforward.
/* EEPROM Write Matrix
* Stores values from a matrix into EEPROM for later retrieval.
*/
#include <EEPROM.h>
int done = false; // flag to avoid repeatedly writing
#define WIDTH (16)
#define HEIGHT (16)
unsigned char maze[WIDTH][HEIGHT];
void setup() {}
void loop()
{
if (done) return; // finished, so just get out of here
write_matrix();
done = true;
}
void write_matrix()
{
for (int addr=0; addr < sizeof(maze); ++addr) {
EEPROM.write(addr, maze[addr/WIDTH][addr%HEIGHT]);
}
}
A slightly less obvious, but actually simpler, and more general purpose approach is:
void write_matrix01()
{
for (int addr=0; addr < sizeof(maze); ++addr) {
EEPROM.write(addr, *((unsigned char*)maze+addr));
}
}
This has the small benefit that it cares less what the data looks like. It could be an array of struct's and it would still work. If this is homework, you might want to avoid this approach unless you can explain it to the instructor, as it is a bit tricky.
loop() contains a flag to avoid repeatedly writing the matrix to EEPROM for this demo. The on-board EEPROM can be used over 100,000 times, but I still try to avoid writing unnecessarily. It takes about 3-4 milli seconds to write a byte, so the whole 256 bytes will take about a second. This is the significant downside.
If you need to save a few matrices, then make sure they don't overlap in EEPROM! You can do this using a bit of arithmetic and sizeof() which will give the memory size in bytes (char) of each matrix.
If all the data fits, and speed isn't a problem, then this is oodles easier and infinitely lower cost (you already have the Arduino :-)) than using an external memory.
To test it, put some easy to recognise data into the matrix before writing it to EEPROM, write it, then create a second sketch/program to read it back and print the values to the serial monitor.
HTH
GB-)