Fastest way to read an array of numbers from python I'm trying to send an array of numbers from python to Arduino over the serial connection. I can reliably read a small incoming set of numbers (for example 123435678) from python, which I can then parse since I know how many digits are supposed to be in each number (for example, 1, 23456, 78). I do this with my Arduino code:


void getInput() {
     char buff[9];
     int field1;
     char field2[6];
     char field3[3];

  Serial.readBytes(buff, 8); //read 8 bytes from the Serial port
  buff[9] = '\0'; //null terminate the string we just read
  Serial.println(buff); //check that we got it
  for(int i=0; i&lt;buff_len;i++) { //now we divide up the string into separate numbers
    if(i==0) {
      field1 = buff[0] - 48; //turn it into an int using ASCII  
    }
    if(i&gt;=1 &amp;&amp; i&lt;6) {
      field2[i-1] = buff[i];
      field2[5] = '\0';
    }
    if(i&gt;=6) {
      field3[i-6]=buff[i];
      field3[2] = '\0';
    }
  }
  for(int i=0;i&lt;buff_len;i++) { //clear the buffer
    buff[i]=0;
  }
}


But if I wanted to send a whole array whose contents I don't know in advance, for example like this:

for i in range(200):
    ser.write(i)


What's the best way to get these numbers to Arduino and file them away in an int array? Should I make the array in python first as a numpy.linspace() and send that?
If you don't know the length of the data then you need to be sending start and end markers so your other code can tell where the transmission starts and ends.  I usually use &lt; and >, so the data packet might look like &lt;12345678>.  You don't have to use those particular characters, just pick something that you know won't show up in your data.