Processing + Arduino

Hello everyone
Please help.
I connected processing and arduino. Sending some data from arduno for processing. Everything seems to be in order. But. At the same time, I want to activate the LED (for example) on the arduino by activating the button on the process.
Question:
Why do I send “1” from processing, I see it on the processing monitor, but I don’t see it on the arduino monitor?

At the same time processing is arguing: RuntimeException: Error opening serial port COM7: Port busy

//Arduino Code:
int butt = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
butt = Serial.read();
Serial.println(butt);
}
}

//Processing Code:
import processing.serial.;
import controlP5.
;
Serial myPort;
ControlP5 cp5;

void setup() {
myPort = new Serial(this, “COM7”, 9600);

cp5 = new ControlP5(this);
cp5.addButton(“ON”)
;
}

void draw()
{

}

void ON() {
myPort.write(1);
println (1);
}

check this out

Should I use Firmata? I never saw it.
None of the tutorials mention this.

At the same time, I can control the processing from arduino.

Hi @Leonid, When you connect Processing to Arduino there are lots of choices. One of the major ones is

  • use the Processing Arduino library which talks to the Firmata sketch in the Arduino
  • use my own Processing sketch, talking to my own Arduno sketch.
  • use one of the value synchronising libraries (see Processing ref → libraries).

To avoid many of the errors I wrote an example with the intention that it works first time with data going both ways. Then you can feed your data in place of the data it uses, and then expand it with more data.

Thank You Richard, I will investigate your topic. But what is wrong with my simple code ?

Maybe it’s com7

Try Serial.list()[1]

Hello,

Processing is telling you that the COM7 port is busy; this suggests that the Arduino is connected to your Arduino monitor in your case.

You can make one serial connection with one Arduino COM port to one of these at a time:

  • Arduino monitor
  • Processing
  • Another device or software

Try connecting the Arduino to Processing with and without the Arduino monitor connected and see what happens.

Try adding some code to receive the data that the Arduino is sending to Processing with the Serial.println() statement.

There are other options to get data from the Arduino; do a bit of research on this.

:)

I can’t understand this logic.

  1. Close Serial Monitor of Ard
  2. Start Prc. See the button
  3. Push the button
  4. See “2” on the Serila monitor of Prc
  5. Open Serial Monitor of Ard.
  6. Ard says: “Not Connected…”
  7. Stop Prc
  8. Close Serial Monitor Ard.
    9 Open Serial Monitor Ard
    10 Click Ctrl+Enter
    11 See “10” !!! What is this?

Hi

You can’t use Arduino ide serial and processing serial at the same time

Add led to your Arduino to on and off :mobile_phone_off:

Run Arduino without connect to ide

Hello @Leonid ,

Ctrl+Enter sends a newline character to Arduino; you have newline selected and this is shown in your picture.
A newline character is ‘\n’ which is 10 decimal.
This is received by the Arduino and sent back to the Arduino Monitor using your code example:
Serial.println(butt) // butt = 10;

I can reproduce this with the Arduino IDE 2.0

:)

OK. Thank you everyone for support. I have got it. I just connect LED to the arduino pin and swotched it on from the processing’s button. I understood that I only can’t see any data on the arduino’ Serial monitor. Can’t use them in parallell. Great. I will continue to invistigate this proggrams

2 Likes