I have an issue getting Processing and the Arduino to talk to each other over the same Serial port. To condense my problem, I wrote a simple program where Processing sends "Processing: Hello!" every second, and the Arduino sends "Arduino: Hello there!" every second, both to the same Serial port. Here is the code:
PROCESSING CODE:
import processing.serial.*; //import the Serial library
Serial mySerial; //the Serial port object
void delay(int time)
{
int start = millis();
while (millis() - start < time){}
}
void setup()
{
size(200, 200);
println(Serial.list());
mySerial = new Serial(this, Serial.list()[9], 9600);
println(Serial.list()[9]);
mySerial.bufferUntil('\n');
}
void serialEvent( Serial mySerial)
{
mySerial.write("Processing: Hello!");
delay(1000);
}
ARUDINO CODE:
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println("Arduino: Hello there!");
delay(1000);
}
What I think I should be seeing in my Serial monitor on the Arduino sketch is:
"Arduino: Hello there!"
"Processing: Hello!"
"Arduino: Hello there!"
"Processing: Hello!"
"Arduino: Hello there!"
"Processing: Hello!"
...
What I actually see is:
"Arduino: Hello there!"
"Arduino: Hello there!"
"Arduino: Hello there!"
"Arduino: Hello there!"
...
Okay, so perhaps the Serial monitor only monitors Arduino output. Then, is there any other way to view the output from Processing on the Arduino side?