# Send variable from arduino to processing: Error while disabling serialEvent () for COM4 null

**URL:** https://discourse.processing.org/t/send-variable-from-arduino-to-processing-error-while-disabling-serialevent-for-com4-null/13046
**Category:** Electronics (Arduino, etc.)
**Created:** [July 29, 2019, 5:45pm UTC](https://discourse.processing.org/t/send-variable-from-arduino-to-processing-error-while-disabling-serialevent-for-com4-null/13046 "2019-07-29T17:45:48Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![waffi](https://avatars.discourse-cdn.com/v4/letter/w/9f8e36/32.png) [@waffi](https://discourse.processing.org/u/waffi)
#### Post date: [July 29, 2019, 5:45pm UTC](https://discourse.processing.org/t/send-variable-from-arduino-to-processing-error-while-disabling-serialevent-for-com4-null/13046/1 "2019-07-29T17:45:48Z")

</div>

Hello everybody

I try to send variables from the arduino to processing. From time to time processing brings me this error:  
Error, disabling serialEvent () for COM4 zero

I invite scetch again because then arduino, then it works partially. does anyone know what that is?

```auto
Simple Arduino Code:

int feld1=1;
int feld2=2;
int feld3=3;
int feld4=4;
void setup() {
 Serial.begin(9600);

}

void loop() {
 Serial.print(feld1); // Send the first Value
 Serial.print(','); // Send a delimiter
 Serial.print(feld2); // Send the first Value
 Serial.print(','); // Send a delimiter
 Serial.print(feld3); // Send the first Value
 Serial.print(','); // Send a delimiter
 Serial.print(feld4); // Send the first Value
 Serial.print(','); // Send a delimiter
 Serial.println(); // Send a carriage-return

}

```

Processing:

```auto
import processing.serial.*; // Import the Processing Serial Library for communicating with arduino
Serial myPort; // The used Serial Port
int feld1;
int feld2;
int feld3;
int feld4;
void setup()
{

  background(51);
  println(Serial.list()); // Prints the list of serial available devices (Arduino should be on top of the list)
  myPort = new Serial(this, Serial.list()[0], 9600); // Open a new port and connect with Arduino at 9600 baud
}
void draw(){
 print(feld1);
 print(feld2);
 print(feld3);
 print(feld4);
}

void serialEvent(Serial myPort) // Is called everytime there is new data to read
{
  if (myPort.available() > 0)
  {
    String completeString = myPort.readStringUntil(10); // Read the Serial port until there is a linefeed/carriage return
    if (completeString != null) // If there is valid data insode the String
    {
      trim(completeString); // Remove whiespace characters at the beginning and end of the string
      String seperateValues[] = split(completeString, ","); // Split the string everytime a delimiter is received
      feld1 = int(seperateValues[0]);
      feld2 = int(seperateValues[1]);
      feld3 = int(seperateValues[2]);
      feld4 = int(seperateValues[3]);
    }
  }
}

```

Unfortunately, I did not find any solution on google.

does anyone know what that is?

many thanks for the help!

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [July 29, 2019, 5:51pm UTC](https://discourse.processing.org/t/send-variable-from-arduino-to-processing-error-while-disabling-serialevent-for-com4-null/13046/2 "2019-07-29T17:51:27Z")

</div>

> [@\[SOLVED\] ArrayIndexOutOfBoundsException: 1](https://discourse.processing.org/t/solved-arrayindexoutofboundsexception-1/2288/7):
>
> For multiple data transmission, I recommend you to read this post below: electric_plug[Forum.Processing.org/two/discussion/16618/processing-with-arduino-void-serialevent#Item\_1](http://Forum.Processing.org/two/discussion/16618/processing-with-arduino-void-serialevent#Item_1) As you can see, on the Arduino side, separate the data w/ \t using print() + write(). And then send the last data w/ println(). On the Processing side, inside serialEvent(), use Serial::readString() + PApplet.splitTokens() in order to get all the data as a String[] array. Of course, you’re still gonna need to conver…

> [@Using two different readStringUntil "characters"](https://discourse.processing.org/t/using-two-different-readstringuntil-characters/10769/17):
>
> Well, I don’t have any Arduino hardware and neither even seen 1 in front of me yet! woozy_face So I can only do blind coding in the dark for you. dark_sunglasses Theoretically, an Arduino C code like this 1: thinking void setup() { Serial.begin(115200); } void loop() { const int x = map(analogRead(A1), 0, 1023, -10, 10); const int y = map(analogRead(A0), 0, 1023, -10, 10); Serial.print(x); // "-5" Serial.write('\t'); // '\t' Serial.println(y); // "10" + "\r\n" delay…

---

<div class="post-metadata">

### Author: ![waffi](https://avatars.discourse-cdn.com/v4/letter/w/9f8e36/32.png) [@waffi](https://discourse.processing.org/u/waffi)
#### Post date: [July 30, 2019, 10:10pm UTC](https://discourse.processing.org/t/send-variable-from-arduino-to-processing-error-while-disabling-serialevent-for-com4-null/13046/3 "2019-07-30T22:10:20Z")

</div>

Thanks for the answer. Have tried it with both, but unfortunately I can not show the values ​​individually.

I need four variables to query them individually afterwards in an if loop.

maybe another solution? Unfortunately, find nothing in google ☹

thanks again 🙂

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [July 31, 2019, 12:51am UTC](https://discourse.processing.org/t/send-variable-from-arduino-to-processing-error-while-disabling-serialevent-for-com4-null/13046/4 "2019-07-31T00:51:12Z")

</div>

?? what is your question about?  
-a- do you have a communication problem like the header title suggests  
-b- make 4 (int) variables from (string) array?

one of the main things also suggested in the linked discussions is  
that you need to check  
after the split “,”  
prior to use stringarray[x]  
is the length of the resulted array after split. ? are there x elements or is it shorter…

```auto
if( seperateValues.length >=4 ) { feld1 = int(seperateValues[0]); ... }

```

anyhow, how can you code and look for errors in dealing with dynamic strings  
if you not even print the incoming arduino line??

---

<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: [July 31, 2019, 1:51am UTC](https://discourse.processing.org/t/send-variable-from-arduino-to-processing-error-while-disabling-serialevent-for-com4-null/13046/5 "2019-07-31T01:51:44Z")

</div>

Hello,

You are sending 4 commas so there will be 5 data elements “split” for a complete set of your data.  
You do not need to send that last comma from the Arduino.

The “null” after the Error is the concern and it was from the array having “null” elements;  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/482893a90e7b039ec3cdda9657190d47ed808ebf.png)

Checking for the length of data array received solves this.

Below tried and tested:

```auto
      int [] seperateValues = int(split(completeString, ',')); // Split the string everytime a delimiter is received
      println(seperateValues.length);
      if (seperateValues.length == 5)
        {
        feld1 = seperateValues[0];
        feld2 = seperateValues[1];
        feld3 = seperateValues[2];
        feld4 = seperateValues[3];
        printArray(seperateValues); // You will see 5 elements
        }

```

---

<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: [July 31, 2019, 2:10am UTC](https://discourse.processing.org/t/send-variable-from-arduino-to-processing-error-while-disabling-serialevent-for-com4-null/13046/6 "2019-07-31T02:10:29Z")

</div>

There is a good discussion about this here along with other good suggestions:  
[https://itp.nyu.edu/physcomp/lessons/serial-communication/interpreting-serial-data](https://itp.nyu.edu/physcomp/lessons/serial-communication/interpreting-serial-data)

🙂

---

<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: [April 4, 2022, 10:12pm UTC](https://discourse.processing.org/t/send-variable-from-arduino-to-processing-error-while-disabling-serialevent-for-com4-null/13046/7 "2022-04-04T22:12:26Z")

</div>

Updated link:  
[https://itp.nyu.edu/physcomp/lessons/interpreting-serial-data/](https://itp.nyu.edu/physcomp/lessons/interpreting-serial-data/)

`:)`
