I'm working on a project that gets a data stream (sequence of bytes which I want to place in an array) and then does something with it. I would like to receive the stream and save it to the program memory because I would like to store 4096bytes and flash is not enough on my 328P.
The following section of my program is quite simple and works saving the elements to an array in flash memory:
...
unsigned char HelloMP3[1024] = { };
...
//******************SAVING ARRAY TO FLASH:
//DATA IS COMING IN FROM THE NETWORK
while (client2.connected()){
p = &HelloMP3[0];
while (p <= &HelloMP3[sizeof(HelloMP3)-1]) {
*p = client2.read();
p++;
}
}
//******************READING ARRAY
p = &HelloMP3[0]; // Point "p" to the beginning of array
while (p <= &HelloMP3[sizeof(HelloMP3)-1]) {
variable = p*;
p++;
}
now I would like to implement the exact same code but saving each element in progmem as they are made available or alternatively I can store the data on a 1024 array (I have this amount available in flash) and then transfer it to progmem and repeat this until I get to 4096bytes.
It looked like you could set up variables and define them to go into program memory as opposed to ram. Are you saying that if I map an array or some long strings at compile time, I can only read these and not modify them? It seems I should be able to do that.
You have a big constant array (perhaps larger than system RAM) which will never be altered during program execution. Such an array can be put into the flash ROM memory at compile time and accessed during run-time with the PROGMEM feature of the gnu compiler: http://www.nongnu.org/avr-libc/user-manual/pgmspace.html
Note: Constant arrays are always placed in flash ROM area:
Without PROGMEM: Array is copied to RAM
With PROGMEM: Array is NOT copied to RAM
You want to store a lot of data, but there is not enough RAM or EEPROM. You might consider a run-time self programming of the flash ROM memory:
Not sure if anybody has implemented procedures for the Arduino.
I'm glad this thread was started, I was under the mistaken impression that the PROGMEM lib could be used to place program varibales into the flash program space, and used like normal varibales. Thanks for clarifying that.
For the OP, you could add a bit of flash to your Arduino pretty easily and cheaply. I did, check this out:
I added a big 4 MByte chip, but if you don't need that much you can buy much smaller chips for less money. When you're shopping, remember that chips like this are rated in mega BITS, so divide by 8 to get Mega BYTES. Six wires, (two of which are power and ground) and you're in business.