# Trying to make 2 strings out of one Serial transmission

**URL:** <https://discourse.processing.org/t/trying-to-make-2-strings-out-of-one-serial-transmission/19819>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [April 16, 2020, 2:04am UTC](https://discourse.processing.org/t/trying-to-make-2-strings-out-of-one-serial-transmission/19819 "2020-04-16T02:04:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![laptophead](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laptophead/32/2701_2.png) [@laptophead](https://discourse.processing.org/u/laptophead)\
**Post date:** [April 16, 2020, 2:04am UTC](https://discourse.processing.org/t/trying-to-make-2-strings-out-of-one-serial-transmission/19819/1 "2020-04-16T02:04:32Z")

</div>

I made a GUI for an Arduino robot. Every 500 mS I am getting a serial communication and it works well.

Now I have two data strings. One pertains to the Motor Currents and it always starts with M.

The other provides other general info on the robot and never starts with M.

So I thought I can create 2 strings and show them on the screen at different locations.

```auto
if (BTPort.available() > 0) {
  IncomingStr = BTPort.readStringUntil(lf); 
 }
  
  First = IncomingStr.charAt(0);
  if (First == 'M')
  Incoming_Currents = IncomingStr;
  
  else
  Incoming_Info = IncomingStr;

```

It did not work, I get a null pointer…

Wonder why

Thank you  
Mitch

---

<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:** [April 16, 2020, 8:47am UTC](https://discourse.processing.org/t/trying-to-make-2-strings-out-of-one-serial-transmission/19819/2 "2020-04-16T08:47:37Z")

</div>

Hello,

Check for a null character.  
You can initialize strings also; be sure to test code as well for valid data. Prefix each with a character.  
See example below.

> **[null / Reference](https://processing.org/reference/null.html)**
>
> Special value used to signify the target is not a valid data element. In Processing, you may run across the keyword null when trying to access data which is not there.

> **[readStringUntil() / Libraries](https://processing.org/reference/libraries/serial/Serial_readStringUntil_.html)**
>
> Combination of readBytesUntil() and readString(). Returns null if it doesn't find what you're looking for.

[String Initialization in Java](https://www.baeldung.com/java-string-initialization)

I also have an example here that may be of interest:

> [@Problem with the use of several sensors, Arduino / Processing](https://discourse.processing.org/t/problem-with-the-use-of-several-sensors-arduino-processing/18118/4):
>
> Hello, thank you very much for your response but I already have my graphic interface developed, how could I implement the multiwii protocol in the interface that I already have developed in Processing?

`:)`

---

<div class="post-metadata">

**Author:** ![laptophead](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/laptophead/32/2701_2.png) [@laptophead](https://discourse.processing.org/u/laptophead)\
**Post date:** [April 16, 2020, 4:59pm UTC](https://discourse.processing.org/t/trying-to-make-2-strings-out-of-one-serial-transmission/19819/3 "2020-04-16T16:59:01Z")

</div>

Thanks a lot , I could not use “match” but I got it to work.

```auto
 while (BTPort.available() > 0) {
    IncomingStr = BTPort.readStringUntil(lf);
    if (IncomingStr != null) {
      First = IncomingStr.charAt(0);
      println(IncomingStr);
      println(First);
      
  if (First == 'M')  
   Incoming_Currents = IncomingStr; // incoming current string from teensy
   
   
   
   else 
   Incoming_Info= IncomingStr; // incoming current string from teensy
    }
  }
    

```

The essential part was if (IncomingStr != null).  
I was under the impression that the string stays at the last value till the next transmission, but it goes to Null instead.  
During null, my if else functions did not work.

Thanks  
Mitch
