Hi All,
This is essentially a com port busy issue. I am unable to find a solution for this other than resetting the M5stickC. (Basically a ESP32)
The M5stickC is programmed as a bluetooth device. It sends data out constantly. The processing sketch monitors the Bluetooth com port (incoming) and reads data from it.
Data can be send by the device and received by the PC via bluetooth. The program works fine on the first go, turning the device on beofre running the sketch, doing everything I expect it to.
Here is where the problem begins, now, after I stop the processing sketch and I try to Run the code again, the following error appears,
RuntimeException: Error opening serial port COM10: Port busy
I tried a few bluetooth code examples and this behaviour just repeats itself.
I am assuming that once I closed the program, the com port is still ‘closed’ to new programs, even if a new instance is started. Therefore the error returned that the port is busy.
I’m not sure what is causing this or how it can be resolved. The current solution that I have are
- power on and off the bluetooth device for each processing Run.
- For some reason, this does not happen to a serial com port that is connect via USB, To get another ESP32/arduino to read the bluetooth data and stream it via USB.
I am looking for a solution where I do not need another MCU, or having to power cycle the device each time I start the processing sketch.
One of the sample code that I used for processing to read the bluetooth data.
import processing.serial.*;
Serial myPort; // The serial port
void setup () {
// set the window size:
size(300, 100);
// List all the available serial ports
printArray(Serial.list());
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[0], 9600);
// don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');
// set inital background:
background(0xff);
}
void draw () {
//Map and draw the line for new data point
delay(10);
}
void serialEvent (Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');
println(inString);
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
}
}
Sample Arduino sketch that I used
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
BluetoothSerial SerialBT;
int i;
void setup() {
Serial.begin(9600);
SerialBT.begin("ESP32test"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
i = 0;
}
void loop() {
SerialBT.print("testing ");
SerialBT.println(i);
i++;
delay(20);
}