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