user17212: I am trying to read a text file and send the info to 2D array, but after loading the array, it reads all zeroes. What can I do to stop the Arduino from doing this and get the array with my required data?
/* This program was created by ScottC on 8/5/2012 to receive serial signals from a computer to turn on/off 1-9 LEDs */

int** ptr;

void setup() {
  // initialize the digital pins as an output.
  pinMode(13, OUTPUT);
  // Turn the Serial Protocol ON
  Serial.begin(9600);
}

void loop() {
  byte byteRead;

  if (Serial.available()) {

    /* read the most recent byte */
    byteRead = Serial.read();
    //You have to subtract '0' from the read Byte to convert from text to a number.
    byteRead = byteRead - '0';
    ptr = new int* [byteRead];

    int i,j;
    for ( i = 0; i < byteRead; i++) {
      ptr[i] = new int[3];
      for ( j = 0; j < 3; j++) {
        if (Serial.available()) {

            /* read the most recent byte */
            byteRead = Serial.read();
            //You have to subtract '0' from the read Byte to convert from text to a number.
            byteRead = byteRead - '0';
            ptr[i][j] = byteRead; 
            Serial.print(ptr[i][j]);
        }
      } 
    } 
  }
}


user13432: There are several issues with your code but instead of correcting I recommend that you start by checking that your assumptions about the format is correct. Send your data to this "reduced" variant of your sketch. Does it work? Did you receive what you expected?
void setup() {
  // initialize the digital pins as an output.
  pinMode(13, OUTPUT);
  // Turn the Serial Protocol ON
  Serial.begin(9600);
}

void loop() {
  byte byteRead;

  if (Serial.available()) {

    /* read the most recent byte */
    byteRead = Serial.read();
    //You have to subtract '0' from the read Byte to convert from text to a number.
    byteRead = byteRead - '0';
    Serial.print(F("byteRead = "));
    Serial.println(byteRead);

    int i,j;
    for ( i = 0; i < byteRead; i++) {
      for ( j = 0; j < 3; j++) {
        if (Serial.available()) {

            /* read the most recent byte */
            byteRead = Serial.read();
            //You have to subtract '0' from the read Byte to convert from text to a number.
            byteRead = byteRead - '0';
            Serial.print(i);
            Serial.print(':');
            Serial.print(j);
            Serial.print(F(":byteRead = "));
            Serial.println(byteRead);
        }
      } 
    } 
  }
}

Did you see the issue with:
    for ( i = 0; i < byteRead; i++) {
    ...
    }

Cheers!

17212: <p>I am trying to read a text file and send the info to 2D array, but after loading the array, it reads all zeroes. What can I do to stop the Arduino from doing this and get the array with my required data?</p>

<pre class="lang-c prettyprint-override"><code>/* This program was created by ScottC on 8/5/2012 to receive serial signals from a computer to turn on/off 1-9 LEDs */

int** ptr;

void setup() {
  // initialize the digital pins as an output.
  pinMode(13, OUTPUT);
  // Turn the Serial Protocol ON
  Serial.begin(9600);
}

void loop() {
  byte byteRead;

  if (Serial.available()) {

    /* read the most recent byte */
    byteRead = Serial.read();
    //You have to subtract '0' from the read Byte to convert from text to a number.
    byteRead = byteRead - '0';
    ptr = new int* [byteRead];

    int i,j;
    for ( i = 0; i &lt; byteRead; i++) {
      ptr[i] = new int[3];
      for ( j = 0; j &lt; 3; j++) {
        if (Serial.available()) {

            /* read the most recent byte */
            byteRead = Serial.read();
            //You have to subtract '0' from the read Byte to convert from text to a number.
            byteRead = byteRead - '0';
            ptr[i][j] = byteRead; 
            Serial.print(ptr[i][j]);
        }
      } 
    } 
  }
}
</code></pre>
 13432: <p>There are several issues with your code but instead of correcting I recommend that you start by checking that your assumptions about the format is correct. Send your data to this "reduced" variant of your sketch. Does it work? Did you receive what you expected?</p>

<pre><code>void setup() {
  // initialize the digital pins as an output.
  pinMode(13, OUTPUT);
  // Turn the Serial Protocol ON
  Serial.begin(9600);
}

void loop() {
  byte byteRead;

  if (Serial.available()) {

    /* read the most recent byte */
    byteRead = Serial.read();
    //You have to subtract '0' from the read Byte to convert from text to a number.
    byteRead = byteRead - '0';
    Serial.print(F("byteRead = "));
    Serial.println(byteRead);

    int i,j;
    for ( i = 0; i &lt; byteRead; i++) {
      for ( j = 0; j &lt; 3; j++) {
        if (Serial.available()) {

            /* read the most recent byte */
            byteRead = Serial.read();
            //You have to subtract '0' from the read Byte to convert from text to a number.
            byteRead = byteRead - '0';
            Serial.print(i);
            Serial.print(':');
            Serial.print(j);
            Serial.print(F(":byteRead = "));
            Serial.println(byteRead);
        }
      } 
    } 
  }
}
</code></pre>

<p>Did you see the issue with:</p>

<pre><code>    for ( i = 0; i &lt; byteRead; i++) {
    ...
    }
</code></pre>

<p>Cheers!</p>
