# Sending Arduino to Processing

**URL:** <https://discourse.processing.org/t/sending-arduino-to-processing/16058>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [December 2, 2019, 7:56pm UTC](https://discourse.processing.org/t/sending-arduino-to-processing/16058 "2019-12-02T19:56:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cbeni](https://avatars.discourse-cdn.com/v4/letter/c/a183cd/32.png) [@Cbeni](https://discourse.processing.org/u/Cbeni)\
**Post date:** [December 2, 2019, 7:56pm UTC](https://discourse.processing.org/t/sending-arduino-to-processing/16058/1 "2019-12-02T19:56:36Z")

</div>

Hey, Its my first time connecting the arduino to processing. I followed a tutorial to the T and double checked the code but i am still getting an error. can someone tell me where i went wrong?

Processing Code —

```auto
import processing.serial.*; 

Serial mySerial;

String myString = null;
int ml = 10;
float myVal;
 
 void setup(){
   size(200,400);
   
   String myPort = Serial.list() [1];
   mySerial = new Serial(this, myPort, 9600);
   
 }
   
   void draw(){
     while (mySerial.available() > 0){
       myString = mySerial.readStringUntil(ml);//striping data
       
       if (myString != null) {
         background(0);
         myVal = float(myString); //data#
     // myVal = myVal/100 *height;
        println(myVal);
    // rectMode(CENTER);
    // rect(width/2,height =(myVal/2), 100, myVal);         
       }
     }
   }

```

Arduino Code-----

```auto
void setup() {
  //Int serial port for data
  Serial.begin(9600);

}

void loop() {

  // capture data in arduino
  int variable1 = int(random(100));

  Serial.println(variable1);

  delay(100);
}

```

Thank you!

---

<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 2, 2019, 9:34pm UTC](https://discourse.processing.org/t/sending-arduino-to-processing/16058/2 "2019-12-02T21:34:26Z")

</div>

Hello,

It works here when I connect to the correct serial port.

Try adding this to setup() to see which COM ports are available:  
[https://processing.org/reference/libraries/serial/Serial\_list\_.html](https://processing.org/reference/libraries/serial/Serial_list_.html)

Another resource:  
[https://itp.nyu.edu/physcomp/lessons/serial-communication/interpreting-serial-data/](https://itp.nyu.edu/physcomp/lessons/serial-communication/interpreting-serial-data/)

🙂

Arduino:

```auto
void setup() 
  {
  //Int serial port for data
  Serial.begin(9600);
  }

void loop() 
  {
  // capture data in arduino
  int variable1 = int(random(100));
  Serial.println(variable1);
  delay(100);
  }

```

Processing:

```auto
import processing.serial.*;

Serial mySerial;

String myString = null;
int ml = 10;
float myVal;

void setup() 
  {
  size(200, 400);
  
  // List all the available serial ports
  printArray(Serial.list());
  
  String myPort = Serial.list() [0];
  mySerial = new Serial(this, myPort, 9600);
  }

void draw() 
  {
  while (mySerial.available() > 0) 
    {
    myString = mySerial.readStringUntil(ml); //striping data

    if (myString != null) 
      {
      background(0);
      myVal = float(myString);
      println(myVal);
      }
    }
  }

```

This needs work:

```auto
// rect(width/2, height =(myVal/2), 100, myVal);

```

I will leave that with you.

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

---

<div class="post-metadata">

**Author:** ![Cbeni](https://avatars.discourse-cdn.com/v4/letter/c/a183cd/32.png) [@Cbeni](https://discourse.processing.org/u/Cbeni)\
**Post date:** [December 2, 2019, 11:43pm UTC](https://discourse.processing.org/t/sending-arduino-to-processing/16058/3 "2019-12-02T23:43:58Z")

</div>

Thank you, question how do i find the correct serial number if the serial monitor only comes up blank?

---

<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 2, 2019, 11:53pm UTC](https://discourse.processing.org/t/sending-arduino-to-processing/16058/4 "2019-12-02T23:53:57Z")

</div>

This is what I see:

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

I have a few serial ports for different devices.

You should see the COM port for your Arduino if you are connected to the same PC.

🙂
