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<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>=1 && i<6) {
field2[i-1] = buff[i];
field2[5] = '\0';
}
if(i>=6) {
field3[i-6]=buff[i];
field3[2] = '\0';
}
}
for(int i=0;i<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?
buff[9].