I am trying to do a data gathering system on the PC. I was planning to use 5 or more HC-06 bluetooth dongles on arduinos and start receiving data in Processing.
The system worked fine for one device I could talk back and fourth - no problem.
As soon as I added the second BT port I get
RuntimeException: Error opening serial port COM16: Port busy
If I try starting the sketch about 5 times, it will start.
But if I ad more ports it does not start. Everytime, one COM or the other is "Busy’.
I did not start the data streaming from the Arduinos before connecting. I could see how that can confuse the system.
It is said that Win10 can assign 255 COM PORTS. I barely get to use 2?
I have a powerful laptop with 16 g of ram and GPU.
I am sure there is a glitch somewhere. The Ports are not busy. There is not other data streaming. Nor another App uses them.
Here is the code:
import processing.serial.*;
Serial myPort0; // Create object from Serial class
Serial myPort1;
Serial myPort2;
Serial myPort3;
Serial myPort4;
int val0, val1, val2, val3, val4; // Data received from the serial port
void setup()
{
size(700, 700);
String portName = Serial.list()[0];
myPort0 = new Serial(this, "COM16", 9600);
myPort1 = new Serial(this, "COM18", 9600);
//myPort2 = new Serial(this, "COM14", 9600);
// myPort3 = new Serial(this, "COM15", 9600);
//myPort4 = new Serial(this, "COM15", 9600);
}
void draw()
{
if ( myPort0.available() > 0) { // If data is available,
val0 = myPort0.read();
println("VALUES: "+val0+" "+val1+" "+val2+" "+val3+" "+val4);
}
if ( myPort1.available() > 0) { // If data is available,
val1 = myPort1.read(); // read it and store it in val
}
// /*
if ( myPort2.available() > 0) { // If data is available,
val2 = myPort2.read(); // read it and store it in val
}
// */
}
void mousePressed() {
if (mouseButton == LEFT) {
} else if (mouseButton == RIGHT) {
myPort0.clear();
myPort0.stop();
myPort1.clear();
myPort1.stop();
// myPort2.clear();
// myPort2.stop();
exit();
}
}