Serial data from Arduino to Processing does not update

Is it necessary to transmit the element number along with the 0 or 1? Arrays have automatic indices. Also not sure you need the leading comma. For whatever it’s worth, the following seems to work on my system.

Arduino:

int pins[12] = {0,0,0,1,0,0,0,0,0,0,0,0,};

void setup() {
 Serial.begin(9600);
}

void loop() {
  for (byte i = 0; i < 12; i = i + 1) {  
   Serial.print(pins[i]);
   if(i < 11) {
    Serial.print(","); // To avoid trailing comma
   }  
  }
  Serial.print("\n");
  delay(10);
}

Processing:

Serial port;
String dataStr;
String[] state = new String[12];

while (port.available() > 0) {
    dataStr = port.readStringUntil(10); // line feed == 10
    if (dataStr != null) {
      println(dataStr);
      state = split(dataStr, ',');
    }
  }

printArray(state);
1 Like