Just a guess as I don't have such devices. Create 2 methods:
- createConnection() .
- closeConnection() .
Within closeConnection() , make myPort = null; as also a flag to indicate it's not active anymore:
import processing.serial.*; Serial myPort; void draw() { if (myPort == null) createConnection(); } void createConnection() { myPort = new Serial(this, Serial.list()[0], 9600); } void closeConnection() { myPort.stop(); myPort = null; }