Error opening serial port... : Port Busy

I am running:

Windows 8.1, Processing 2.1, Arduino 1.5.4, and Azio BTD-V400 Bluetooth® Adaptor

I'm working through "Making Things Talk (2nd Edition), project 3.

I am unable to connect to the bluetooth module connected to my Arduino because of the following error: "Error opening serial port COM9; Port busy"

I was able to get the code to work while hardwired through a USB cable with no issue. I only needed to update the COM port number and baud rate, which I did. However, when I try to run the program through processing the error pops up.

Additionally confusing, when I installed the bluetooth dongle, it added two COM ports (8 and 9), when I expected one port.

Arduino Code:

/*

  Sensor Reader
  Context:  Arduino

  Reads two analog inputs and two digital inputs and outputs
  their values.

  Connections:
    analog sensors on analog inputs pins 0 and 1
    switches on digital I/O pins 2 and 3

    */
const int leftSensor = 0;
const int rightSensor = 1;
const int resetButton = 2;
const int serveButton = 3;

int leftValue = 0;
int rightValue =0;
int reset = 0;
int serve = 0;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(resetButton, INPUT);
  pinMode(serveButton, INPUT);  

  while (Serial.available() <= 0) {
    Serial.println("hello");        // send a starting message
}
}

void loop() {
  // check to see whether there is a byte available to read
  // in the serial buffer:
  if (Serial.available() > 0) {
    int inByte = Serial.read();
  // read the analog sensors:
  leftValue = analogRead(leftSensor);
  rightValue = analogRead(rightSensor);

  //read the digital sensors:
  reset = digitalRead(resetButton);
  serve = digitalRead(serveButton);

  // print the results:
  Serial.print(leftValue);
  Serial.print(",");
  Serial.print(rightValue);
  Serial.print(",");
  Serial.print(serve);
  Serial.print(",");
  Serial.println(reset);
}
}

Processing Code:

/*
  Serial String Reader
  Context:  Processing

*/
import processing.serial.*;      // import the Processing serial library
Serial myPort;                   // The serial port
String resultString;             // string for the results


float leftPaddle, rightPaddle;   // variables for the sensor values
int resetButton, serveButton;    // variables for the button values
int leftPaddleX, rightPaddleX;   // horizontal positions of the paddles
int paddleHeight = 100;          // vertical dimension of the paddle
int paddleWidth = 10;            // horizontal dimension of the paddle

float leftMinimum = 600;         // minimum value of the left sensor
float rightMinimum = 600;        // minimum value of the right sensor
float leftMaximum = 1000;        // maximum value of the left sensor
float rightMaximum = 1000;       // maximum value of the right sensor


int ballSize = 25;               //  the size of the ball
int xDirection = 1;              //  the ball's horizontal direction (left is -1, right is 1).
int yDirection =1;               //  up is -1, down is 1.
boolean ballInMotion;            // is the ball moving?
int leftScore, rightScore;
int xPos, yPos;                  //  the ball's horizontal and vertical positions

int fontSize = 36;               //  point size of the scoring font


void setup() {
  size(640, 480);                // set the size of the applet window

  println(Serial.list());

  String portName = Serial.list()[1];  
  //open the serial port:
  myPort = new Serial(this, portName, 115200);

  //read bytes into a buffer until you get a linefeed (ASCII 10:
  myPort.bufferUntil('\n');

  //initialize the sensor values;
  leftPaddle = height/2;
  rightPaddle = height/2;
  resetButton = 0;
  serveButton = 0;

  // initialize the paddle horizontal position;
  leftPaddleX = 50;
  rightPaddleX = width - 50;

  // set no borders on drawn shapes:
  noStroke();

  //initialize the ball in the center of the screen:
  xPos = width/2;
  yPos=height/2;

  PFont myFont = createFont(PFont.list()[2], fontSize);
  textFont(myFont);
}

void draw(){
  // set the background and fill color for the applet window:
  background(#044f6f);
  fill(#ffffff);
  // show a string in the window;
  if (resultString != null) {



  }
  // draw the left paddle;
  rect(leftPaddleX, leftPaddle, paddleWidth, paddleHeight);

  //draw the right paddle;
  rect(rightPaddleX, rightPaddle, paddleWidth, paddleHeight);

  // calculate the ball's position and draw it;
  if (ballInMotion == true) {
    animateBall();
  }

  // if the serve button is pressed, start the ball moving;
  if (serveButton == 1){
    ballInMotion = true;
  }

  // if the reset button is pressed, reset the scores
  // and start the ball moving;
  if (resetButton == 1){
    leftScore = 0;
    rightScore = 0;
    ballInMotion = true;
  }

  // print the scores;
  text(leftScore, fontSize, fontSize);
  text(rightScore, width-fontSize, fontSize);

}
Sign In or Register to comment.