Getting input from Serial and placing in a 2d array

Hello, I am working on getting input from the Serial port, but am experiencing some issues. Right now, It is “getting input”, converting that input based on letters to a number 1-27 (1 for space, 2 for a, 3 for b ect), and then it prints out the matrix. I know the printing does not have any issues, and the assignment of the numbers doesn’t have anything wrong with it, so I have narrowed it down to the actual input. The code for the input is bellow:

void getData(){  
  int newInputs = Serial.available();
  if(newInputs > 0){
    for(int j = newInputs; j >= 0; j--){
      if(j > 0){
        node[newInputs-j][0] = Serial.read();
      }else{
        newData = true;
      }
    }
  }
}

I think the issue may be at the statement int newInputs = Serial.available(); but I do not know what would be causing it. For the rest of my code, here is what is in the loop:

void loop(){
  getData();
  if(newData == true){
    //setRandWeight(-100,100, dataNumIn);
    nodeReader(); 
    //weightReader();
    newData = false;
  }
}

And here is my node reader:

void nodeReader(){
  if(debug == true){
    unsigned short temp;
    for(int f = 0; f < 30; f++){
      Serial.println(" ");
      for(int s = 0; s < 7; s++){
        temp = node[f][s];
        Serial.print("[");
        Serial.print(temp);
        Serial.print("] ");
      } 
    }
  }
}

and just for you to see what is actually coming out from the serial port when I input the word “hello”:

[104] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[101] [0] [0] [0] [0] [0] [0]  
[108] [0] [0] [0] [0] [0] [0]  
[108] [0] [0] [0] [0] [0] [0]  
[111] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]  
[0] [0] [0] [0] [0] [0] [0]

The array that is being printed out is only a 30 tall x 7 wide, so I am not sure why there are so many rows either…

Serial.available() only knows about the data that's already arrived and stored in the serial receive buffer. This may be a lot less than all the data that will eventually arrive.

The arduino main loop, and your program, as far as I can see, would easily run fast enough that you would be picking up the input one byte at a time -- ie: getData() runs and there is just one byte "h". Later getData() runs again with the "e". Meanwhile the loop runs many, many times with no input at all.

Have a look at Serial Input Basics. They are simple reliable examples that get all the data and then you can store it wherever needed. There is also a parse example.

As your code is written, you are trying to read many characters when there may only be one in the input buffer. The Arduino does things very much faster than serial data arrives.

...R

Why don't you add a special character as a terminator to your string, say an "#"? Then you can stay in the SerialRead() loop, collecting your characters into an array until one of them is a "#". Then leave that loop, and process all of your received data before going back to look for more data.

jrdoner: collecting your characters into an array until one of them is a "#".

That is how Serial Input Basics works.

...R

The array that is being printed out is only a 30 tall x 7 wide, so I am not sure why there are so many rows either…

I’m going to guess that you are not printing it correctly. Of course, you left out a lot of code, and a LOT of explanations…