copy an array to another array

dear all,

as I know the buffer size of arduino is 512 byte. So, the question is this max size is for one array or for sum of all arrays inside my code?

Am I possible to write my data into a 512 byte array and the copy it into another array to save my data? if yes, how?

Thank you

as I know the buffer size of arduino is 512 byte.

News to me. What buffer? Where did you hear that?

Am I possible to write my data into a 512 byte array and the copy it into another array to save my data? if yes, how?

Use the memcpy() function to copy one array to another. If you have enough SRAM to hold both arrays.

groundFungus:
News to me. What buffer? Where did you hear that?

I just read somewhere about it. Maybe I misunderstood.

groundFungus:
Use the memcpy() function to copy one array to another. If you have enough SRAM to hold both arrays.

Thank you for your suggestion. Is is possible for arduino uno to have both of them at sam time?

As in the case of many posts here a questions is posed without explaining the underlying reason for it.

Why do you want to save the data from one array in a second one ?
Over what period of time will the saved data be retained ?
Would it be helpful to save the data in a way that it was still available after a power cycle or reboot ?

As to the question of a Uno being able to have 2 arrays, each of 512 bytes, at the same time. That depends on what else you are doing in the program.

Please post a complete program showing what you want to achieve.

UKHeliBob:
Why do you want to save the data from one array in a second one ?
Over what period of time will the saved data be retained ?
Would it be helpful to save the data in a way that it was still available after a power cycle or reboot ?

Well, I want to save float data coming from mpu 6050 every 50 ms on the sd card together with 2 proximity sensors and millis lable. for this reason I need an array to save 9 float values each 50 ms.

Proxmitiy sensors are working through interrupt pins 2 and 3 of arduino uno. To have an accurate intervals for mpu data I want to use Timer1 interrupt to collect its data every 50 ms.

Because I need this data in 20Hz for a period of 10 days, it is not useful to write them directly on sd card...it causes many missing datas due to a porblem with sd card( I don't know why).
If I use a large array to collect data and write it to sd card every 1 sec, this problem will vanish, but still there is a problem, somewhere I have over lapping datas in array, let say once for a period of one hour. So I need to copy the first one into another array to avoid this over lapping data.

UKHeliBob:
Please post a complete program showing what you want to achieve.

the part of code you will need...

// MPU-6050...
float Accel_X, Accel_Y, Accel_Z, Gyro_X, Gyro_Y, Gyro_Z;
float Acc_X, Acc_Y, Acc_Z, Gyr_X, Gyr_Y, Gyr_Z;
int Temp, Tmp;
const int MPU_ADD = 0b1101001;
float mpuAll[118];

// SD Card...
int chipSelect = 4;
SdFile myFile ;
SdFat Sd;
int SD_Old_Time = 0;
char FileName[12];
char Time_to_FileName[7];
String Date = "";
int flag = 0;
int i=0;
int j=0;
int p=0;
int k=0;

// Real Time Clock(RTC)...
char Now_Time[9];
char Now_Date[11];
RTC_DS3231 RTC;
DateTime now;
unsigned long Millis;

void setup() {
Wire.begin();
Wire.setClock(400000);
Serial.begin(115200);
pinMode (10, OUTPUT);
RTC.begin();
// RTC.adjust(DateTime(DATE,TIME));
setupMPU();
Sd.begin(chipSelect);
while (!Sd.begin(chipSelect)) {
Serial.println("SD Card Error!");
}

pinMode(proximity2, INPUT);
pinMode(proximity1, INPUT);
attachInterrupt(digitalPinToInterrupt(proximity1), postion, FALLING);

attachInterrupt(digitalPinToInterrupt(proximity2), counter, FALLING);
Timer1.initialize(50000);
Timer1.attachInterrupt(MPU);
}

void MPU() {
Millis = millis();
mpuAll[i++]= Millis;
mpuAll[i++]= Accel_X;
mpuAll[i++]= Accel_Y;
mpuAll[i++]= Accel_Z;
mpuAll[i++]= Gyro_X;
mpuAll[i++]= Gyro_Y;
mpuAll[i++]= Gyro_Z;
mpuAll[i++]= postion;
mpuAll[i++]= rpm;
p++;

if(p==13){
flag = 1;
p=0;
i=0;
}
}

void saveData() {

now = RTC.now();
sprintf(Now_Time, "%02d:%02d:%02d", now.hour(), now.minute(), now.second());
sprintf(Now_Date, "%02d/%02d/%02d", now.day(), now.month(), now.year());

if(SD_Old_Time!=now.hour()){
myFile.close();
sprintf(Time_to_FileName, "%02d%02d%02d", now.month(), now.day(), now.hour());
Date = String(Time_to_FileName) + ".txt";
Date.toCharArray(FileName, 12);
myFile.open(FileName, FILE_WRITE); // Open new text file
myFile.print(""); // Writing header file on to the SD Card
myFile.print(F("Column num"));
myFile.println(F(" Info"));
myFile.println("");
myFile.print(F(" 1 "));
myFile.println(F(" Milliseconds"));
myFile.print(F(" 2 "));
myFile.println(F(" Accel_X"));
myFile.print(F(" 3 "));
myFile.println(F(" Accel_y"));
myFile.print(F(" 4 "));
myFile.println(F(" Accel_Z"));
myFile.print(F(" 5 "));
myFile.println(F(" Gyro_X"));
myFile.print(F(" 6 "));
myFile.println(F(" Gyro_Y"));
myFile.print(F(" 7 "));
myFile.println(F(" Gyro_Z"));
myFile.print(F(" 8 "));
myFile.println(F(" Position"));
myFile.print(F(" 9 "));
myFile.println(F(" RPM"));
myFile.println("");
myFile.println(F("Starting time of writing this file:"));
myFile.println("");
myFile.print(F("Date: "));
myFile.print(Now_Date);
myFile.print(F(" Time: "));
myFile.print(Now_Time);
myFile.print(F(" Temperature: "));
myFile.print(Temp);
myFile.println(F("°C"));
myFile.println("");
SD_Old_Time = now.hour();
}
for(k=0 ; k<=12 ; k++){
mpuData();
myFile.print(uint32_t(mpuAll[j++])); myFile.print(" ");
myFile.print(mpuAll[j++],3); myFile.print(" ");
myFile.print(mpuAll[j++],3); myFile.print(" ");
myFile.print(mpuAll[j++],3); myFile.print(" ");
myFile.print(mpuAll[j++],3); myFile.print(" ");
myFile.print(mpuAll[j++],3); myFile.print(" ");
myFile.print(mpuAll[j++],3); myFile.print(" ");
myFile.print(int(mpuAll[j++])); myFile.print(" ");
myFile.print(int(mpuAll[j++])); myFile.println("");
}

k = 0;
j=0;
myFile.flush();
}

I want to save float data

Do you hear that noise ?
It is the sound of goalposts moving

How many floats can you fit in a 512 byte array ?

Why copy?
Why not ping-pong two buffers?

UKHeliBob:
Do you hear that noise ?
It is the sound of goalposts moving

How many floats can you fit in a 512 byte array ?

As float numbers have size of 4 bytes,that means 128 float numbers. Am I right?

AWOL:
Why copy?
Why not ping-pong two buffers?

It could be also the solution, but the question is am I possible to use two 512 bytes arrays at the same time or not?

ebarash:
It could be also the solution, but the question is am I possible to use two 512 bytes arrays at the same time or not?

That depends upon if you have enough RAM

ebarash:
As float numbers have size of 4 bytes,that means 128 float numbers. Am I right?

That's right and I am glad there is no confusion