# Simple arduino to processing serial not outputting anything

**URL:** <https://discourse.processing.org/t/simple-arduino-to-processing-serial-not-outputting-anything/10837>\
**Category:** Electronics (Arduino, etc.)\
**Tags:** homework\
**Created:** [May 2, 2019, 10:15am UTC](https://discourse.processing.org/t/simple-arduino-to-processing-serial-not-outputting-anything/10837 "2019-05-02T10:15:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![eezJerome](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@eezJerome](https://discourse.processing.org/u/eezJerome)\
**Post date:** [May 2, 2019, 10:15am UTC](https://discourse.processing.org/t/simple-arduino-to-processing-serial-not-outputting-anything/10837/1 "2019-05-02T10:15:13Z")

</div>

I understand that it might be annoying that I am posting on a different thread for the same project, but it is a different code and approach, so I thought it was appropriate to do this.

I have literally been at this thing for 12 hours (I woke up this morning and tried to make progress, but nothing 😞). It’s been stupid array errors back and back again, which prompted me to take a different approach.

Basically, I want to have a potentiometer on an Arduino to send it’s values to Processing and from there I will draw a line that moves/draws as my control stick does. This is supposed to be a simpler version of what I really want to do, which is to makes lines with a gyroscope/accelerometer as the values change per axis.

But, I am going nuts making no progress! It is utterly frustrating to the point that reading documentation just throws me off and I feel so dumb because none of what I read sticks through.

It’d be great if someone could kind of walk me through this as I complete this project, and I understand I can’t just have someone do my project for me, but I just need a big help here.

Here’s the code:

```auto
import processing.serial.*;

Serial port;

int index = 0;
int[] input_arr = new int[2];
int px, py; //previous x, y
int x, y; //current x, y

void setup() {
  background(0);
  size(500, 500);

  port = new Serial(this, "COM12", 115200);
  stroke(255);
}

void draw() {
}

void serialEvent() {
  while (port.available() > 0) {
    //two values are being sent, x and y
    //here i assume that after the newline it will go and read the 
    //next set of values
    
    //how the values are coming in through serial:
    // xvalue \t y value
    // newline
    // ...
    String raw = port.readStringUntil('\n');              
    input_arr[index] = int(raw);
    index++;

    if (index > 1) {
      x = px + input_arr[0];
      y = py + input_arr[1];
      // flushes buffer/serial, whatever it's called
      port.clear();
      //following line is for debug; however this doesnt print
      //anything and that's my issue
      println(input_arr[0]); 
      px = x;
      py = y;
    }
  }
  //im certain this should be in draw() but idk at this point tbh.
  line(x, y, px, py);
}

```

At this point I am really really desperate for an answer, solution. Also, at least the code compiles, unlike what it’s been doing for the past 2 days – giving PointerException errors

Please help .-. Reading documentation is giving me nothing and even if I tried nothing is being processed. Stressed af because of this stupid project. I’ll give myself a break in hopes of a miracle (no, not really, I need to think straight to work well).

Thanks

---

<div class="post-metadata">

**Author:** ![Dennis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dennis/32/1111_2.png) [@Dennis](https://discourse.processing.org/u/Dennis)\
**Post date:** [May 2, 2019, 5:07pm UTC](https://discourse.processing.org/t/simple-arduino-to-processing-serial-not-outputting-anything/10837/2 "2019-05-02T17:07:43Z")

</div>

Hi eezJerome, I have This question About:

- can you post the Arduino Code?
- why you force input array data?

```auto
int[] input_arr = new int[2];

```

Sorry if I will don’t response quickly but I’m busy to interconnect one Robot and one Laser 3D with Arduino wireless…

---

<div class="post-metadata">

**Author:** ![eezJerome](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@eezJerome](https://discourse.processing.org/u/eezJerome)\
**Post date:** [May 3, 2019, 1:25am UTC](https://discourse.processing.org/t/simple-arduino-to-processing-serial-not-outputting-anything/10837/3 "2019-05-03T01:25:06Z")

</div>

> [@Dennis](#):
>
> can you post the Arduino Code?

Oh sure! Here:

```auto

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

void loop() {
  int x = analogRead(A1);
  int y = analogRead(A0);

  int x1 = map(x, 1023, 0, -10, 10);
  int y1 = map(y, 0, 1023, -10, 10);

  Serial.print(x1); 
  Serial.write('\t');
  Serial.print(y1); 
  Serial.println('\n');
}
```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [May 3, 2019, 2:23am UTC](https://discourse.processing.org/t/simple-arduino-to-processing-serial-not-outputting-anything/10837/4 "2019-05-03T02:23:54Z")

</div>

so you should split your arduino line by the ‘\t’ to get a string array,  
and convert that strings to int.

* * *

but the arduino code not makes sense,  
you read 0 … 1023 and create int -10 … 10  
that are 20 steps only // you damage your resolution.

why not make them float in arduino and send float?

or much better just send the 0… 1023  
and do the rest in Processing!

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [May 3, 2019, 4:24am UTC](https://discourse.processing.org/t/simple-arduino-to-processing-serial-not-outputting-anything/10837/5 "2019-05-03T04:24:53Z")

</div>

also test that little example project [Issue with using array after splitTokens()](https://discourse.processing.org/t/issue-with-using-array-after-splittokens/10826/4) here

---

<div class="post-metadata">

**Author:** ![eezJerome](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@eezJerome](https://discourse.processing.org/u/eezJerome)\
**Post date:** [May 3, 2019, 7:56am UTC](https://discourse.processing.org/t/simple-arduino-to-processing-serial-not-outputting-anything/10837/6 "2019-05-03T07:56:24Z")

</div>

Thanks will do! I was actually reading the other one; i’ll report any progress/issues
