# Receiving data from Arduino

**URL:** <https://discourse.processing.org/t/receiving-data-from-arduino/11239>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [May 14, 2019, 7:48pm UTC](https://discourse.processing.org/t/receiving-data-from-arduino/11239 "2019-05-14T19:48:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![GuilhermeVolker](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/guilhermevolker/32/5657_2.png) [@GuilhermeVolker](https://discourse.processing.org/u/GuilhermeVolker)\
**Post date:** [May 14, 2019, 7:48pm UTC](https://discourse.processing.org/t/receiving-data-from-arduino/11239/1 "2019-05-14T19:48:50Z")

</div>

HI! I’am having problem with my code, iam able to read the data, on arduino serial its fine but on Processing its too much slow, i dont have a clue about whats going on.

```auto

void recebeData(){
   if(myPort.available()>0){
   val = myPort.readStringUntil('\n');       
   
   if(val != null){
   str = split(val," "); //split data with space
   
  num = float(str); //convert to float
   gx = num[0];  
   gy = num[1];
   }else{
     print("ERROR ");
   }
   println(num);

  }
}

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [May 14, 2019, 8:11pm UTC](https://discourse.processing.org/t/receiving-data-from-arduino/11239/2 "2019-05-14T20:11:46Z")

</div>

> [@Using two different readStringUntil "characters"](https://discourse.processing.org/t/using-two-different-readstringuntil-characters/10769):
>
> Hello. I am not sure what to call the value inside the bufferUntil, but as my title implies I need to use two different characters, rather than just the newline (\n). Is it possible that, inside the serialEvent() function, I have something like ... void serialEvent(Serial port){ x = float(port.readStringUntil("X")); y = float(port.readStringUntil("Y")) } //statements ... where the values from serial look something like: (note: for the sake of using the values for Processing, I appende…

---

<div class="post-metadata">

**Author:** ![moh\_maya](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@moh\_maya](https://discourse.processing.org/u/moh_maya)\
**Post date:** [May 15, 2019, 7:11am UTC](https://discourse.processing.org/t/receiving-data-from-arduino/11239/3 "2019-05-15T07:11:18Z")

</div>

> [@GuilhermeVolker](#):
>
> str = split(val," "); //split data with space

I’m still learning, but shouldn’t this be an array, like this:

```auto
str [] = split(val," "); //split data with space

```

where the square brackets define an array that is populated with data from the serial? Not sure if this is the issue causing the slow rate, or if it’s an issue at all…

How slow though? Are you getting just the first line, or is the rate of new data slow? Is it updating past the first few lines of data?

---

<div class="post-metadata">

**Author:** ![GuilhermeVolker](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/guilhermevolker/32/5657_2.png) [@GuilhermeVolker](https://discourse.processing.org/u/GuilhermeVolker)\
**Post date:** [May 15, 2019, 1:12pm UTC](https://discourse.processing.org/t/receiving-data-from-arduino/11239/4 "2019-05-15T13:12:00Z")

</div>

I’am sorry, i forgot to put the global variables on the code, i’d declare the variable as an array already, but tanks!

```auto
String[] str;
float[] num;
float gx,gy;

```

---

<div class="post-metadata">

**Author:** ![GuilhermeVolker](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/guilhermevolker/32/5657_2.png) [@GuilhermeVolker](https://discourse.processing.org/u/GuilhermeVolker)\
**Post date:** [May 15, 2019, 2:58pm UTC](https://discourse.processing.org/t/receiving-data-from-arduino/11239/5 "2019-05-15T14:58:11Z")

</div>

It work! thank you very much for your help!  
I was getting something near to a single read for second, now its working on the same rate as the arduino send 😉 )
