Max. 11 chars via Serial?

Hi,

I wrote a program, for getting Serial Inputs. This is the function for saving the incoming data in a array.

int in(){
  Serial.println("In in()");
  int i=0;
  while(1){
    indata[i] = (char)Serial.read();
    if(indata[i]=='

indata[] is a global char array. I want to send strings linke that:

PS180F90B196$
NN52.94682873E10.47327$

The last char is ever a "$". But when I try it, it's only possible to send 11 chars at the time. I send:

PS180F180B180$

and this is the output PS180F180B1ÿÿÿÿÿÿÿÿ8ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ0ÿÿÿÿÿÿÿÿÿÿÿÿÿ$ I tried it with a lot of different strings, and it's ever the same.

What can I do?

Greetings Philipp){      Serial.println("Return 1");      Serial.println(indata);      return 1;    }    i++;  } } ```

indata[] is a global char array. I want to send strings linke that:

§_DISCOURSE_HOISTED_CODE_1_§

The last char is ever a "$". But when I try it, it's only possible to send 11 chars at the time. I send:

§_DISCOURSE_HOISTED_CODE_2_§

and this is the output §_DISCOURSE_HOISTED_CODE_3_§ I tried it with a lot of different strings, and it's ever the same.

What can I do?

Greetings Philipp

You are receiving garbage because you read an empty buffer.
The Arduino is running way faster than the serial line can send data.
Before a SerialRead() you should use Serial.avalaible() so the software will wait for a new char in the buffer.
The Serial.avalaible() can be put in a if embracing all the code that processes the data or in a while() before the read. The if is a better solution as it don’t hang the software if there is no data.

In addition to not reading data faster than it has arrived, you also need to make sure there is room in the array before adding the character to the array.

If indata is declared to be an array of size 12, there is nothing in your code to prevent it from trying to store 800 characters in the 12 element array.

Also, if indata is to be sent to any string processing routines that rely on the fact that strings are NULL-terminated arrays of characters, those routines will produce incorrect results, since your arrays are NOT strings. They are not NULL-terminated.

That looks like the classic case of the array being too small for the incoming string.

Try declaring the array as "indata[16]" and see if you get the same issue.