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

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?

Simple Arduino Code:

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


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



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()

  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(){

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!

1 Like
1 Like

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 :frowning:

thanks again :slight_smile:

?? 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…

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??


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;

Checking for the length of data array received solves this.

Below tried and tested:

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

There is a good discussion about this here along with other good suggestions:


Updated link: