Storing data in an array instead of a file

Hi,

In the code below, I create a file on a SD card and then write incoming data on the uart to the file. It is image data.

Can I store this data in an array instead of in a file on an SD card? I don’t know how much data I’m will receive though.

Thanks

void setup()
{
    Serial.begin(38400);
    while (!Serial)
    {
        ; // wait for serial port to connect. Needed for Leonardo only
    }
 
    Serial.print("Initializing SD card...");
    // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
    // Note that even if it's not used as the CS pin, the hardware SS pin
    // (10 on most Arduino boards, 53 on the Mega) must be left as an output
    // or the SD library functions will not work.
    pinMode(10, OUTPUT);
    if (!SD.begin(4))
    {
        Serial.println("initialization failed!");
        return;
    }
    Serial.println("initialization done.");
    Serial.println("please waiting ....");
 
    Serial2.begin(115200);
    //Serial2.begin(38400);
    delay(100);
    SendResetCmd();
    delay(2000);
    SetBaudRateCmd(0x2A);
    delay(500);
    Serial2.begin(38400);
    delay(100);
}
 
void loop()
{
    byte a[32];
    int ii;
 
    SendResetCmd();
    delay(2000);                            //Wait 2-3 second to send take picture command
    SendTakePhotoCmd();
    delay(1000);
    while(Serial2.available()>0)
    {
        incomingbyte=Serial2.read();
    }
 
    myFile = SD.open("pic.jpg", FILE_WRITE); //The file name should not be too long
 
    while(!EndFlag)
    {
        j=0;
        k=0;
        count=0;
        //Serial2.flush();
        SendReadDataCmd();
        delay(20);
        while(Serial2.available()>0)
        {
            incomingbyte=Serial2.read();
            k++;
            delay(1); //250 for regular
            if((k>5)&&(j<32)&&(!EndFlag))
            {
                a[j]=incomingbyte;
                if((a[j-1]==0xFF)&&(a[j]==0xD9))     //tell if the picture is finished
                {
                    EndFlag=1;
                }
                j++;
                count++;
            }
        }
 
        for(j=0;j<count;j++)
        {
            if(a[j]<0x10)  Serial.print("0");
            Serial.print(a[j],HEX);           // observe the image through serial port
            Serial.print(" ");
        }
 
        for(ii=0; ii<count; ii++)
        myFile.write(a[ii]);
        Serial.println();
    }
 
    myFile.close();
    Serial.print("Finished writing data to file");
    while(1);
}

How much data, and how much physical memory do you have?

Hi, I'm using an arduino 101, it has 24kB of SRAM, 196kB of flash, which one would it be stored in? The image data uses about 10 kB.

Thanks

SRAM

I don't know how much data I'm will receive though.

Then how will you size the array to store the data in?

If I know that I'm getting 10kb of data, how do I know how big to make the array?

transcendglue:
If I know that I’m getting 10kb of data, how do I know how big to make the array?

10kb = 10,240 bytes.

byte array[10240];

byte array[10240];Naughty !

UKHeliBob: byte array[10240];Naughty !

aarg did not say which Arduinos that would work on. OP asked a stupid question. He/she deserves a literal answer.

I bet you would have said something different if the OP had used that line of code.