Error with arduino <-> processing code "disabling serialEvent() for COM6 null."

HI, I’m new in Processing, and i want to use arduino and make rotary encoder as arrows. Unfortunetly i have only Uno, not leonardo, so i wanted to made a code in processing to emulate pressing a key. But evry time i want to run, i have error

Blockquote Error, disabling serialEvent() for COM6 null.

My code :

import processing.serial.*;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.KeyStroke;
Serial MyPort;
String KeyString = “”;
void setup()
{
System.out.println(“Hi”);
size(300, 300);
MyPort = new Serial(this, “COM6”, 9600);// My Arduino is on COM3. Enter the COM on which your Arduino is on.
MyPort.bufferUntil(‘\n’);
}
void draw(){
background(237, 240, 241);
fill(20, 160, 133); // Green Color
stroke(33);
strokeWeight(1);
textSize(32);
textSize(24);
fill(33);
text(“Status:”, 100, 150);
textSize(30);
textSize(16);
text(“Joystick”, 100, 50);
text(KeyString, 100, 170);
}
void serialEvent(Serial MyPort)throws Exception {
KeyString = MyPort.readStringUntil(‘\n’);
KeyString = KeyString.substring(0, KeyString.indexOf(‘:’));
System.out.println(KeyString);
Robot Arduino = new Robot();
int KeyToPress;
switch(KeyString){
case “1” :
Arduino.keyPress(38);
Arduino.keyRelease(38);
break;
case “2” :
Arduino.keyPress(39);
Arduino.keyRelease(39);
break;
case “3” :
Arduino.keyPress(40);
Arduino.keyRelease(40);
break;
case “4” :
Arduino.keyPress(37);
Arduino.keyRelease(37);
break;
}
}

Help please!

Hi @Neoncodes,

Welcome to the forum :slight_smile:

The error is due to the COM port connection. At which COM Port are you trying to connect your arduino?

Then replace the port and the baud rate in line

MyPort = new Serial(this, “Your COM port goes here”, insert you baudrate here);

The following tutorial should also help you in the first steps :slight_smile:
https://learn.sparkfun.com/tutorials/connecting-arduino-to-processing/all

Best regards

Thanks, my arduino is at COM6, and baudrate 9600, so in my code it was ok. I did not find the answer in the link provided either, but thank you for your reply nonetheless.

Case closed, i’ve done it in python. If someone is intrested i post it on arduino project hub.