Hi everyone,
My name is Jeroen, and I am new to this Arduino forum. I am trying to establish a serial communication between Arduino and Processing. I start by printing lines with int values from my Arduino (Serial.println(i)), and try to read these on Processing. Here is the code:
Arduino
int i = 0;
void setup(){
Serial.begin(9600);
}
void loop(){
if(i > 3){
i = 0;
}
Serial.println(i);
i++;
delay(1000);
}
Processing
import processing.serial.*;
Serial port;
int val=0;
void setup(){
size(500,500);
port = new Serial(this,"COM9",9600);
port.bufferUntil('\n');
}
void draw(){
background(50);
if(val==0){
fill(125);
}
if(val==1){
fill(125,125,0);
}
else if(val==2){
fill(125,0,0);
}
else if(val==3){
fill(0,0,125);
}
rect(125,125,250,250);
}
void serialEvent(Serial port){
val = int(port.readStringUntil('\n'));
}
When I check the Arduino on the Arduino serial monitor, everything works fine. The lines that are printed contain 1,2,3,0,1,2,3,0,......
The problem is, when I try to read the serial output from the Arduino, nothing happens.. It appears as if Processing does not communicate with the arduino. The TX-LED on the Arduino is flashing though.
I have the RXTX-2.1-7 Processing Library installed, that's what I found out when looking at the black console-box from Processing:
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
Could you guys help me out? I don't know what is wrong with my set-up. I checked the COM-port, which was the right port. I did not have the Arduino serial monitor running at the same time I had the Processing sketch running.
Thanks in advance,
Jeroen