# Serial data from Arduino to Processing does not update

**URL:** <https://discourse.processing.org/t/serial-data-from-arduino-to-processing-does-not-update/33378>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [November 7, 2021, 4:10pm UTC](https://discourse.processing.org/t/serial-data-from-arduino-to-processing-does-not-update/33378 "2021-11-07T16:10:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![BerndKoggel](https://avatars.discourse-cdn.com/v4/letter/b/71e660/32.png) [@BerndKoggel](https://discourse.processing.org/u/BerndKoggel)\
**Post date:** [November 7, 2021, 4:10pm UTC](https://discourse.processing.org/t/serial-data-from-arduino-to-processing-does-not-update/33378/1 "2021-11-07T16:10:05Z")

</div>

I have an arduino test wether two wires touch, this works. The data is stored in an array for each pin and given either a 1 or 0 if the wire connects to another. The Serial.print is used to send the data, the serial monitor shows the data is correct. However in processing where this data is used it seems to not update. If I touch the wires before starting processing it knows they touch, but when I release the wires processing says they still touch. Same happens if they don’t touch at the start. This really frustrates me, because the data is sent correctly. And I have to deliver this project in 5 hours.

**Arduino code:**

```auto
void sendArrayData() {
  for (int i = 0; i < 12; i++) {
    Serial.print(",");
    Serial.print(i);
    Serial.print(",");
    if (i < 11) {
      Serial.print(partsConnected[i]);
    } else {
      Serial.println(partsConnected[i]);
    }
  }

}

```

**Processing code:**

```auto
void SerialEvent() {
  myString = myPort.readStringUntil('\n');

  if (myString != null) {
    myString = trim(myString);
    println(myString);
    sensors = int(split(myString, ','));
  }
}

```

_Example data when two wires touch for the first time after the program has run for a little second already._

_The data sent by Arduino example if first two wires connect: ,0,1,1,1,2,0,3,0,4,0,5,0,6,0,7,0,8,0,9,0,10,0,11,0_

_The data recieved by Processing: ,0,0,1,0,2,0,3,0,4,0,5,0,6,0,7,0,8,0,9,0,10,0,11,0_

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [November 8, 2021, 6:20am UTC](https://discourse.processing.org/t/serial-data-from-arduino-to-processing-does-not-update/33378/2 "2021-11-08T06:20:30Z")

</div>

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:

```auto
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:

```auto
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);

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [November 8, 2021, 6:54am UTC](https://discourse.processing.org/t/serial-data-from-arduino-to-processing-does-not-update/33378/3 "2021-11-08T06:54:53Z")

</div>

Hello,

This is what your code (with some added code) is doing:

```auto
String [] sensors0;
int [] sensors1;

void setup() 
  {
  String s = ",0,0,1,0,2,0,3,0,4,0,5,0,6,0,7,0,8,0,9,0,10,0,11,0";
  //https://www.arduino.cc/reference/en/language/functions/communication/serial/println/  
  String ard = s + "\r\n";
  print(ard);
  
  //myString = myPort.readStringUntil('\n');
  String myString = ard;

  if (myString != null) 
    {
    myString = trim(myString);
    println(myString);
    sensors0 = (split(myString, ','));
    printArray(sensors0);
    sensors1 = int(split(myString, ','));
    printArray(sensors1);
    }
    
  println(int(""));
  }    

```

> **Console output:**
>
> ```auto
> ,0,0,1,0,2,0,3,0,4,0,5,0,6,0,7,0,8,0,9,0,10,0,11,0
> ,0,0,1,0,2,0,3,0,4,0,5,0,6,0,7,0,8,0,9,0,10,0,11,0
> [0] ""
> [1] "0"
> [2] "0"
> [3] "1"
> [4] "0"
> [5] "2"
> [6] "0"
> [7] "3"
> [8] "0"
> [9] "4"
> [10] "0"
> [11] "5"
> [12] "0"
> [13] "6"
> [14] "0"
> [15] "7"
> [16] "0"
> [17] "8"
> [18] "0"
> [19] "9"
> [20] "0"
> [21] "10"
> [22] "0"
> [23] "11"
> [24] "0"
> [0] 0
> [1] 0
> [2] 0
> [3] 1
> [4] 0
> [5] 2
> [6] 0
> [7] 3
> [8] 0
> [9] 4
> [10] 0
> [11] 5
> [12] 0
> [13] 6
> [14] 0
> [15] 7
> [16] 0
> [17] 8
> [18] 0
> [19] 9
> [20] 0
> [21] 10
> [22] 0
> [23] 11
> [24] 0
> 0
> 
> ```

`:)`

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [November 8, 2021, 11:55am UTC](https://discourse.processing.org/t/serial-data-from-arduino-to-processing-does-not-update/33378/4 "2021-11-08T11:55:08Z")

</div>

> [@BerndKoggel](#):
>
> And I have to deliver this project in 5 hours.

Was this an academic or homework assignment?

---

<div class="post-metadata">

**Author:** ![BerndKoggel](https://avatars.discourse-cdn.com/v4/letter/b/71e660/32.png) [@BerndKoggel](https://discourse.processing.org/u/BerndKoggel)\
**Post date:** [November 8, 2021, 3:07pm UTC](https://discourse.processing.org/t/serial-data-from-arduino-to-processing-does-not-update/33378/5 "2021-11-08T15:07:27Z")

</div>

It was an academic assignment. I luckily found the issue before the deadline. I added a while loop in the SerialEvent() which was true as long as myPort.available() \> 0. This worked, but caused a lot of framedrops, obviously. However it was good enough.

I just realised there were reactions on this post, I did not get any notifications. So thanks everyone for your help, I truly appreciate it!
