Reputation: 13
First of all, I know this question has been asked a lot but I can't find any answer that solves my problem. So when I try to use processing to write stuff to the serial monitor of the Arduino it says that the port (in my case "com3") is busy. I have no idea with what it could be busy because I already set a delay on the reading of the serial-monitor.
Arduino code:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
// Serial.println("started");
// Serial.println();
}
void loop() {
if(Serial.available()){
char ch = (char) Serial.read();
Serial.println(ch);
ch = "";
delay(100);
}
Processing code:
import processing.serial.*;
Serial sPort;
String port;
void setup() {
port = Serial.list()[0];
sPort = new Serial(this, port, 9600);
//port.write("hey, its working");
}
I know it is really basic but I made the code as small as possible while still showing the problem
Thanks in advance
Upvotes: 0
Views: 1087
Reputation: 105
It seems, that you try to access the Serial port from your running Processing sketch at the same time as from the Arduino Serial Monitor.
It is important to note, that the Arduino IDE Serial Monitor is itself a process, that communicates with your Arduino. The Arduino can not, at the same time, talk to the Serial Monitor and another Program.
But you are halfway to monitor what your Arduino has to say. Use Processing instead. You are already sending the message back. All you have to do is to log incoming Serial messages in your Processing app.
Just add this to your Processing draw loop:
if (sPort.available() > 0) {
print(sPort.readSring());
}
Close the Arduino Serial Monitor, run the Processing Sketch and you should see whatever you sent (using Serial.print in Arduino) in the Processing Console.
Serial.print, just like Serial.read are functions to communicate with any program on the computer once you plugged the USB cable. Serial Monitor is one of them, but there are many others and among them is Processing.
Upvotes: 2