Pages: [1]   Go Down
Author Topic: Processing to Arduino serial communication? Port is already in use?  (Read 547 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Get out while you still can.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there.
I've been happily sketching away having received my uno this evening and have run into something that has me completely stumped.

I wrote something that sends serial data to Processing to convert to MIDI to control things in Ableton Live and it worked wonderfully.
Now I am trying to do the opposite- send midi to Processing to then be turned into serial messages to get sent to my Arduino, but have one big issue-

Now, whenever attempting to compile, upload, or view the Serial Monitor, the Arduino IDE throws the error "Serial Port 'COM3' is already in use.'

Is there some method I should be using to properly write and read that allows what I'm trying to do?

Thanks!

Processing sketch:
Code:
import rwmidi.*;
import processing.serial.*;

MidiInput input;
MidiOutput output;

Serial port;

void setup()
{
 size(400,400);
  input = RWMidi.getInputDevices()[0].createInput(this);
  port = new Serial(this, "COM3", 9600);
}
void noteOnReceived(Note note) {
  println("note on " + note.getPitch());
  if (note.getPitch() == 44){port.write(0);}
}
void draw(){
//
}

Arduino sketch:
Code:
int kickLed = 9;
int snareLed = 11;
int kickStatus = 0;
int incomingByte=0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();
    if ( kickStatus == 0){ kickStatus = 1;}
    else if (kickStatus == 1) {kickStatus = 0;}
    digitalWrite(kickLed, kickStatus);
    Serial.print("I received: ");
    Serial.println(incomingByte, DEC);
 }
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 654
Posts: 50931
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Now, whenever attempting to compile, upload, or view the Serial Monitor, the Arduino IDE throws the error "Serial Port 'COM3' is already in use.'
You'll need to figure out what else has that port opened, and make it close it. Ableton? Processing?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26634
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if ( kickStatus == 0){ kickStatus = 1;}
    else if (kickStatus == 1) {kickStatus = 0;}
aka
Code:
kickStatus = 1 - kickStatus;
or even
Code:
kickStatus = !kickStatus;
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 8
Get out while you still can.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You'll need to figure out what else has that port opened, and make it close it. Ableton? Processing?

I'm assuming that it is Processing, as I'm telling Processing to write the Serial message on COM3 so that it can be read by the Arduino.

Is there a different / better / correct way for me to both have the serial messages sent from Processing to Arduino? Because the Arduino is only reading and Processing is only writing, I assumed they would play nice together?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 654
Posts: 50931
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can't have Processing talking to the Arduino while you try to upload a new sketch to the Arduino. Processing has to shut up while that happens (and disconnect from the port).
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
Get out while you still can.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You can't have Processing talking to the Arduino while you try to upload a new sketch to the Arduino. Processing has to shut up while that happens (and disconnect from the port).

Even when I've shut down Processing and successfully uploaded my code to the Arduino, I get errors both in Processing when then later running the sketch, or in the Arduino Serial Monitor when the Processing sketch is running...

Stumped.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
Get out while you still can.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

AH.

"DUH"

I needed to fully quit the Arduino IDE as it holds onto the port for use in the Serial Monitor.

Things are working fine now.

Thanks!
Logged

Pages: [1]   Go Up
Jump to: