# Error on my Processing GUI code for Arduino , I need some help

**URL:** https://discourse.processing.org/t/error-on-my-processing-gui-code-for-arduino-i-need-some-help/33341
**Category:** Electronics (Arduino, etc.)
**Created:** [November 5, 2021, 5:08pm UTC](https://discourse.processing.org/t/error-on-my-processing-gui-code-for-arduino-i-need-some-help/33341 "2021-11-05T17:08:22Z")
**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: [November 5, 2021, 9:48pm UTC](https://discourse.processing.org/t/error-on-my-processing-gui-code-for-arduino-i-need-some-help/33341/2 "2021-11-05T21:48:17Z")

</div>

Hello,

Take a look at this example:

Arduino code:

- sends comma delimited string of data with `Serial.print(',');`
- the end of the data string is terminated with a `'\r'` and a `'\n'` from `Serial.println();`

> **Arduino Code**
>
> ```auto
> void setup() 
> {
> Serial.begin(9600);
> }
> 
> void loop() 
> {  
> for(int x = 0; x < 15; x++) 
> {  
> Serial.print((float) x + random(0, 1000)/1000.0 , 3);   
> Serial.print(',');
> }
> Serial.println();  
> delay(1000);
> }
> 
> ```

Processing code:

- receives characters up to and including `'\n'`
- uses `trim()` to trim the data of whitespace including `'\r'` and a `'\n'`
- splits the data separated by a `','` into an array

> **Processing Code**
>
> ```auto
> import processing.serial.*;
> 
> String myString = null;
> Serial myPort;
> 
> void setup()
> {
> size(700, 700);
> printArray(Serial.list());
> String portName = Serial.list()[2];
> myPort = new Serial(this, portName, 9600);
> myPort.clear();
> myString = myPort.readStringUntil('\n');
> myString = null;
> }
> 
> void draw()
> {
> while (myPort.available() > 0)
> { // If data is available,
> String myString = myPort.readStringUntil('\n');
> //println(myString);
> if (myString != null) 
> {
> //println(myString);
> myString = myString.trim();
> //println(myString);
> 
> //String[] q = split(myString, ','); 
> String[] q = splitTokens(myString, ",");
> printArray(q);
>       
> if(q.length == 16)
> {
> printArray(q);
> }
> }
> }
> }
> 
> ```

In my Arduino example…

The Arduino `Serial.println();` sends a `'\r'` and a `'\n'`:  
[https://www.arduino.cc/reference/en/language/functions/communication/serial/println/](https://www.arduino.cc/reference/en/language/functions/communication/serial/println/)

The Processing `trim()` removes the `'\r'` and `'\n'`.

You can terminate the data sent with the Arduino with any character you want as long as it is not a character that is in your data.  
Remember to check for this character in Processing in` readStringUntil()`.

Take a good look at a working example and then scrutinize your code.

`:)`

---

_[View the full topic](https://discourse.processing.org/t/error-on-my-processing-gui-code-for-arduino-i-need-some-help/33341)._
