Go Down

Topic: Reading 250,000,000 values from sensor and storing it on SD card (Read 24012 times) previous topic - next topic

v_m_a

As I said .. I tried to write the code myself :p
This code reads 24000 values ..
1.stores them in an array on arduino DUE..
2.and writes them to the SD CARD..
3. clears the array
4. again reads values..stores them on SD CARD and repeats..

It gets compiled but shows an error at runtime     " couldn't open file"

I wrote this because as of now I am not concerned about the delay in reading values in my project..
Important factors for me are..
1. reading as many values as possible (increase array size more than 24000 but it shows an error if I do so..) and
2. writing it as fast as possible to the SD CARD..
3. In this code I am writing values to the array one by one in a loop.. is there any command from which I can write all values at a time..??

I ve attached my code along.. Please have a look and help me !!.. :p

Mr_arduino

Why do you need such a large array? That may be the cause of the problem. Also you declared the same array twice. Why did you do that? You only need to declare the array once.

v_m_a

I need to store as many samples from the sensor continuously in a short interval of time.. say 1,00,000 samples recorded per second continuously at a time would be perfect for me.. but in due I can only read 24000 samples at a time.. it shows compilation error if I try to increase it further..

what do you mean by declaring twice..
I have declared the array just once as
int z[24000];

Next time I ve made sure all values in the array are 0 before reading values into it.. and clearing the array again after writing values to SD card from it to again read values into it in the next iteration of ch..
int z[24000]={0};

But why is it showing error at runtime "Cannot open file"...




Mr_arduino

#33
Jul 06, 2014, 06:55 am Last Edit: Jul 06, 2014, 07:49 am by Mr_arduino Reason: 1
Global variables are already initialized to zero. Local variables are uninitialized. Regardless there is no reason to initialize the array to zero as you completely fill it with data from analogRead(). You know I am going to be honest with you. Right now I am having trouble writing a polite message. You are ignoring people advice people have tried to explain to you that you cannot have an array larger than there is ram and you appear to be putting minimal effort into improving your code. If this project is so important to you why do you not act like it is. The fact that you cannot create more ram out of thin air should be common sense. If things continue like this I am going to have to stop helping you.

PaulS

Quote
I have declared the array just once as
int z[24000];

Which Arduino has enough memory for you to store 24000 ints in SRAM?
The art of getting good answers lies in asking good questions.

steinie44

#35
Jul 06, 2014, 03:55 pm Last Edit: Jul 06, 2014, 06:09 pm by steinie44 Reason: 1
Quote

what do you mean by declaring twice..
I have declared the array just once as
int z[24000];

Next time I ve made sure all values in the array are 0 before reading values into it.. and clearing the array again after writing values to SD card from it to again read values into it in the next iteration of ch..
int z[24000]={0};

When you clear it, you're declaring it again.
Drop the 'int' on the 2nd one.

PaulS

Quote
Drop the 'int'

Doing just that will result in code that does not compile or do what OP expected..
The art of getting good answers lies in asking good questions.

Mr_arduino

The best solution would be to completely remove the:
Code: [Select]

int z[24000]={0};

That will solve the issue. I have tried to explain that global variables are already initialized to zero even when you don't set them to zero. Please read http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_varinit
Also he fills the entire array up with data from analogRead so the array does not need to be initialized. Also only use global variables when you have an actual need for them.

steinie44

Quote

Doing just that will result in code that does not compile or do what OP expected..


I just tried it and compiles fine. But your remark does not do what the OP expected.

PaulS


Quote

Doing just that will result in code that does not compile or do what OP expected..


I just tried it and compiles fine. But your remark does not do what the OP expected.


Bullshit;

Code: [Select]
int n[24000];

void setup()
{
}

void loop()
{
  n[24000] = {0};
}

Quote
sketch_jul06a:1: error: size of array 'n' is too large
sketch_jul06a.ino: In function 'void loop()':
sketch_jul06a:9: error: 'n' was not declared in this scope
sketch_jul06a:9: error: expected primary-expression before '{' token
sketch_jul06a:9: error: expected `;' before '{' token
The art of getting good answers lies in asking good questions.

v_m_a

My initial code gets compiled fine ..
with and without int z[24000]={0};
The error comes at runtime that "cannot open file"..
I ve tried changing the SD card too but in vain.same result , gets compiled..but at runtime after acquisition shows up "cannot open file"

As for which arduino.. I am using arduino DUE.. it has 96 kB of SRAM..So it does store 24000 integers..

My problem is ..It is not able to open file.. I ve attached the code with an array size of 1000 too.. but the same error at runtime..
"cannot open file"

And sir..I am very sorry.. I completely understand your patience is being tested with me.. I ll work harder.. and try to solve my problems myself..atleast the basic ones.. 

PaulS

Quote
As for which arduino.. I am using arduino DUE.. it has 96 kB of SRAM..So it does store 24000 integers..

Then you really should have posted in the DUE forum.
The art of getting good answers lies in asking good questions.

v_m_a

Ok..
but I  didn't do that in the first place because I don't think the error appears because of using DUE specifically !!

PaulS


Ok..
but I  didn't do that in the first place because I don't think the error appears because of using DUE specifically !!

If you can create a simple sketch that demonstrates the problem, that does not involved a 24000 element array or 250 millions samples, and the simple sketch works on a 328-based machine but not on the Due, then the problem IS Due-specific. If the simple sketch fails on both, then the problem isn't Due-specific.

But no one that does not have a Due can recreate your problem with the sketch you have.
The art of getting good answers lies in asking good questions.

v_m_a

uhm.. I tried running the same code with an array of 10.. on MEGA 2560 .. (CODE UPLOADED..) but it shows the same response..
gets compiled and at run time after acquisition of values for the first iteration is not able to open the file to write to SD Card..

although normal data writing code on SD CARD after reading values simultaneously  works .(code uploaded)

So .. I dn think its a problem with the DUE board..

Go Up