I need array assistance.

Here's my code, but it doesn't seem to run.
My goal is to collect the data every one millisecond.
Hardware is Arduino Ethernet.
I will be adding 6 discrete inputs to the collection once i get this part working.
I'll also later add code to dump all the data to a PC that is running VB, over ethernet.

const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to


int MyArray1[700];
int MyArray2[700];
int MyIndex = 1;

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600); 
  delay(300);
  Serial.println("Here we go.");
}

void loop() {
  

  if (MyIndex < 600){
    MyArray1[MyIndex] = millis();
    MyArray2[MyIndex] = analogRead(analogInPin);
    //Serial.println(MyIndex);
  }

    
  if (MyIndex == 600){
    Serial.print(MyArray1[2]);
    Serial.print(", " );
    Serial.print(MyArray2[2]);
    Serial.println("");
  }
       

  MyIndex = MyIndex + 1;
  
}

jestal:
Here's my code, but it doesn't seem to run.
My goal is to collect the data every one millisecond.
Hardware is Arduino Ethernet.
I will be adding 6 discrete inputs to the collection once i get this part working.
I'll also later add code to dump all the data to a PC that is running VB, over ethernet.

const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to

int MyArray1[700];
int MyArray2[700];
int MyIndex = 1;

void setup() {
 // initialize serial communications at 9600 bps:
 Serial.begin(9600);
 delay(300);
 Serial.println("Here we go.");
}

void loop() {

if (MyIndex < 600){
   MyArray1[MyIndex] = millis();
   MyArray2[MyIndex] = analogRead(analogInPin);
   //Serial.println(MyIndex);
 }

if (MyIndex == 600){
   Serial.print(MyArray1[2]);
   Serial.print(", " );
   Serial.print(MyArray2[2]);
   Serial.println("");
 }

MyIndex = MyIndex + 1;
 
}

The problem is that your defining of int MyArray1[700]; and int MyArray2[700]; takes up 2800 bytes of SRAM, where as a 328p based arduino board only has 2,048 bytes avalible in total. So you see the fundamental problem here?

Lefty

If you're collecting data at regular intervals, why do you need a time stamp for every sample?
See here

At worst, eight bit deltas would be all that would be needed.

After downloading to the hardware the sketch program says:
Binary sketch size: 2,486 bytes (of a 32,256 byte maximum)

On the page for the Ethernet board:

Memory

The ATmega328 has 32 KB (with 0.5 KB used for the bootloader). It also has 2 KB of SRAM and 1 KB of EEPROM (which can be read and written with the EEPROM library).

so am i limited to 2k for data?

After downloading to the hardware the sketch program says: Binary sketch size: 2,486 bytes (of a 32,256 byte maximum)

You're confusing program memory with RAM.
Common mistake.

My goal is to collect the data every one millisecond.

Your code is not doing that though, it's sampling every loop.

MyArray1[MyIndex] = millis();

MyArray1 is an array of ints, you're sticking longs into it. (How does that compile? It does I tried it.)

so am i limited to 2k for data?

Yep, unless you get a Mega which has 8k or one of the 1284-based clones which have 16k.

As AWOL says though, if you are sampling at regular times you don't need timestamps in the first place, that will save a motsa of data space.

 MyIndex = MyIndex + 1;

MyIndex never gets reset to 0, so after the first 700 loop()s it's off into la la land.


Rob

How does that compile? It does I tried it.

It generates a warning that possible truncation could occur. It is up to you yo then determine if that really could happen. Since warnings are disabled, you never actually see the warning, but one IS generated.

Yes, I forgot that warnings are disabled in the IDE.


Rob