Arduino + Processing "Handshake" Issue
![userHead](https://dfimg.dfrobot.com/dfPortrait2.png)
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?
Hi
Theoretically, Processing can communicate with Arduino on the serial port. However, the serial monitor can just print the output of the arduino.
If you want to print what Arduino receives, you should use serial.event function, which can be used to print the information stored in the serial buffer.
See more here: https://docs.arduino.cc/built-in-examples/communication/SerialEvent
![](https://dfimg.dfrobot.com/nobody/makelog/d839aa5021328f0bef4a2e8e9e1abb4f.png)
![userHeadPic](https://dfimg.dfrobot.com/dfPortrait2.png)