# Serial connection between Processing and Arduino doesn't work

**URL:** https://discourse.processing.org/t/serial-connection-between-processing-and-arduino-doesnt-work/34054
**Category:** Electronics (Arduino, etc.)
**Created:** [December 11, 2021, 1:18pm UTC](https://discourse.processing.org/t/serial-connection-between-processing-and-arduino-doesnt-work/34054 "2021-12-11T13:18:11Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [December 11, 2021, 8:38pm UTC](https://discourse.processing.org/t/serial-connection-between-processing-and-arduino-doesnt-work/34054/2 "2021-12-11T20:38:48Z")

</div>

> [@grudovz](#):
>
> and the port is busy while the processing code is running (as you would expect),

It is busy if another application is using the serial port such as :

- Arduino SerialMonitor
- Arduino Serial Plotter
- And so on…

Your Processing code is sending data to the Arduino and the Arduino is sending the data back to Processing as a string.

Reference:  
_[Serial.print() - Arduino Reference](https://www.arduino.cc/reference/en/language/functions/communication/serial/print/)_

Modified Processing code to receive the data to demonstrate that it is working:

```auto
import processing.serial.*;

// The serial port
Serial myPort;

byte b;

void setup() 
  {
  // List all the available serial ports:
  printArray(Serial.list());
  // open port
  myPort = new Serial(this, Serial.list()[0], 9600);
  delay(1000);
  }

void draw() 
  {
  try 
    {
    myPort.write(b++); // Counts from 0 to 255 and repeats since it is a byte
    }
  catch(Exception e) 
    {
    // Print detailed error information to the console.
    System.err.println(e);
    e.printStackTrace();
    }
  //delay(50);
  
  if(myPort.available() > 0)
    {
    int incoming = myPort.read();
    println(incoming);
    }
  }

```

I also added a `delay(1000)` in Processing in the `setup()` to allow the Arduino to reboot before sending data and flooding the buffers.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/c10f350eebcecce4cb522afdcefd698f4f755814.png)

Related topic:

> [@Processing to Arduino Serial Library Example](https://discourse.processing.org/t/processing-to-arduino-serial-library-example/11143/5):
>
> I modified the existing “SimpleWrite” example to: save and check for the state of mouseOverRect() print state to console only writes serial data once a delay() to wait for Arduino to reset once connected to it; in my case, it is an Arduino Mega 2560 R3. I kept the spirit of the original example intact and left it as a “Simple Write” program. My edit of “SimpleWrite” example so it only sends data once: /\*\* \* Simple Write. \* \* Check if the mouse is over a rectangle and writes the status …

I only modified your code to show what it is doing _as is_.  
You still have some exploration to do to understand serial communications.

`:)`

---

_[View the full topic](https://discourse.processing.org/t/serial-connection-between-processing-and-arduino-doesnt-work/34054)._
