# Got stuck for 4 days on a tiny Serial bug

**URL:** <https://discourse.processing.org/t/got-stuck-for-4-days-on-a-tiny-serial-bug/46555>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [June 16, 2025, 11:00am UTC](https://discourse.processing.org/t/got-stuck-for-4-days-on-a-tiny-serial-bug/46555 "2025-06-16T11:00:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sterretje](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@sterretje](https://discourse.processing.org/u/sterretje)\
**Post date:** [June 16, 2025, 11:00am UTC](https://discourse.processing.org/t/got-stuck-for-4-days-on-a-tiny-serial-bug/46555/1 "2025-06-16T11:00:04Z")

</div>

I’ve spent 4 days trying to find a bug in a piece of code ☹

It eventually boiled down to the below (incorrect) line

```java
      _myPort = new Serial(_parent, _port, 115200, 'N', '8', '1');

```

And yes, I’ve done serial stuff with Processing and Arduinos before. When I eventually found it I could cry 😢

---

<div class="post-metadata">

**Author:** ![ProcessingOrg](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/processingorg/32/18341_2.png) [@ProcessingOrg](https://discourse.processing.org/u/ProcessingOrg)\
**Post date:** [June 16, 2025, 11:52am UTC](https://discourse.processing.org/t/got-stuck-for-4-days-on-a-tiny-serial-bug/46555/2 "2025-06-16T11:52:51Z")

</div>

We’ve updated the title of your post to better reflect the content and help others who might run into a similar issue. Thanks for sharing your debugging story, these kinds of posts are valuable for the community!

For more on how to write helpful titles, check out this section of the guidelines for asking questions: [Does your title give a good summary of your problem?](https://discourse.processing.org/t/guidelines-asking-questions/2147#p-7666-does-your-title-give-a-good-summary-of-your-problem-3)

---

<div class="post-metadata">

**Author:** ![sableraph](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sableraph/32/251_2.png) [@sableraph](https://discourse.processing.org/u/sableraph)\
**Post date:** [June 16, 2025, 11:57am UTC](https://discourse.processing.org/t/got-stuck-for-4-days-on-a-tiny-serial-bug/46555/3 "2025-06-16T11:57:16Z")

</div>

Thanks for sharing this. Looks like the issue came from using `'8'` and `'1'` as characters instead of `8` (int) and `1.0` (float). Easy mistake to make, especially since everything _looks_ right at a glance!

Out of curiosity, did the error message help at all in finding this, or was it something you had to track down by trial and error?

---

<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:** [June 16, 2025, 5:08pm UTC](https://discourse.processing.org/t/got-stuck-for-4-days-on-a-tiny-serial-bug/46555/4 "2025-06-16T17:08:11Z")

</div>

Hello,

I always take an interest in Serial related topics.

This is error generated on W10 and Processing 4.4.4:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/9/8/98b073606e2c5b326ba7156a257a31318ac79c62.png)

Code:

```auto

import processing.serial.*;

// The serial port:
Serial _myPort;       

// List all the available serial ports:
printArray(Serial.list());

// This genererated errors:
//_myPort = new Serial(_parent, _port, 115200, 'N', '8', '1');

// Reference: https://processing.org/reference/libraries/serial/Serial.html

// This works:

// Long Version
PApplet parent = this;
String portName = "COM3"; 
int baudRate = 9600; 
char parity = 'N';
int dataBits = 8;
float stopBits = 1.0;

_myPort = new Serial(parent, portName, baudRate, parity, dataBits, stopBits); 

// Short version that does not require variables above
//_myPort = new Serial(this, "COM3", 9600, 'N', 8, 1.0); 

_myPort.write("Yay!");

```

Reference:

> **[Serial / Libraries](https://processing.org/reference/libraries/serial/serial)**
>
> Class for sending and receiving data using the serial communication protocol.

`:)`

---

<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:** [June 16, 2025, 5:54pm UTC](https://discourse.processing.org/t/got-stuck-for-4-days-on-a-tiny-serial-bug/46555/5 "2025-06-16T17:54:24Z")

</div>

Have you tried the keyword `this` instead of this unknown _\_parent_ variable?

> **[this / Reference](https://processing.org/reference/this.html)**
>
> Refers to the current object (i.e., "this object"), which will change depending on the context in which this is referenced. In Processing, it's most common to use this to pass a referenc…

---

<div class="post-metadata">

**Author:** ![sterretje](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@sterretje](https://discourse.processing.org/u/sterretje)\
**Post date:** [June 17, 2025, 4:54am UTC](https://discourse.processing.org/t/got-stuck-for-4-days-on-a-tiny-serial-bug/46555/6 "2025-06-17T04:54:27Z")

</div>

> [@sableraph](#):
>
> Out of curiosity, did the error message help at all in finding this, or was it something you had to track down by trial and error?

There is no error message when I ‘compile’. I can see that the other side receives data (I can not see which data) but it does not send an expected reply back so it is not receiving correct data. If I use any terminal program instead of my Processing application it worked as expected.

> [@sableraph](#):
>
> Looks like the issue came from using `'8'` and `'1'` as characters instead of `8` (int) and `1.0` (float).

Indeed. It was my stupidity to get that wrong.

It would be nice if the Serial library would check for invalid parameters and simply throw an exception.

@glv and @GoToLoop  
The problem was not with the `_parent`.  
The line was in a separate class in a separate file. I passed the parent (_this_) as an argument to the constructor when creating the object.

I was not clear about this because it was not relevant for my original topic title where I only wanted to vent some frustration about my stupidity.
