Go Down

Topic: Processing to Arduino serial communication? Port is already in use? (Read 568 times) previous topic - next topic

humblesound

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: [Select]
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: [Select]
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);
}
}


PaulS

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?

AWOL

Code: [Select]
if ( kickStatus == 0){ kickStatus = 1;}
    else if (kickStatus == 1) {kickStatus = 0;}

aka
Code: [Select]
kickStatus = 1 - kickStatus;
or even
Code: [Select]
kickStatus = !kickStatus;
"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.

humblesound


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?

PaulS

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).

humblesound


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.

humblesound

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!

Go Up