Help Storing Data to Memory before writing to SD

Hello all,

I am attempting to log data using my Arduino and I am unsure about the feasibility of my approach. My goal is to scan a linear sensor with 512 pixels six times, that is 5126 data values. The values are coming from a 16 bit ADC so some of then have a magnitude of >10000. It was suggested that I use a char array of a large enough size to store all those numbers, that is 512pixels6scans*5characters per value max. That takes up way to much of my dynamic memory (i.e. 787% of it). Obviously that won't work. I considered using PROGMEM to save the char array to, but this requires that the array is constant which it is not.

Since I eventually need to write this data to an SD card I could try to just write each value to a single file on the card, but I am worried this will severely slow my data collection as it only took about 10 seconds originally to just Serial.print all the data before. I read something like upwards to 380 ms just to write a 30 bit character to the SD card.

So, does anyone have any suggestions on how I should approach this? If writing to the SD one value at a time is the only other way, then so be it, but is there a better way?

Thank you

512pixels6scans5characters

A sixteen bit value will fit in sixteen bits, i.e. two bytes.

I read something like upwards to 380 ms just to write a 30 bit character to the SD card.

A 30 bit character? What the heck is that?

It was suggested that I use a char array of a large enough size

By what dumb ass? Expanding a 2 byte value to 5 bytes doesn't make sense. Still 512 * 6 * 2 is 6144 bytes.

Which Arduino do you have that 512 * 6 * 5 uses 78% of the memory?

16 bits per value.
Read values from ADC -> Place in to array of ints. Each int is 16bits = 2 bytes.

Memory available is aprox 2kB = 2kB/2 = 1,000 ints.

512 pixels should easy fit in that space. Takes about half of available SRAM.

You are getting mixed up with types.

An INT is 2 bytes. A CHARACTER is one byte. During writing to the SD card, the library will convert the 2 byte INTs in to CHARACTERS in the txt file. You only need to store the ints in mem...not some pre-converted characters.

Which Arduino do you have that 512 * 6 * 2 uses 78% of the memory?

Arduino Uno, but not 78%, 787%....

Still 512 * 6 * 2 is 6144 bytes

Yes exactly, I apologize for that, I was confused by the bits/bytes. Something like the ATMEGA1280 chip would be a better choice than the 328P....hmmm

Well as always thank you guys for your help

Or as '1284P, 16K SRAM, vs just 8K in the 1280/2560. I offer boards in several form factors, including Uno style, with onboard or offboard USB/Serial interface optons, and varying other features:
http://www.crossroadsfencing.com/BobuinoRev17/