Sending Strings from arduino to Processing

I want to get Processing to read Strings from Arduino.
I send two Strings massages from the arduino and I want to store them in two different variables on Processing.
I tried to do it, but the two Strings are passed to the first variable and the second variable remains empty. I don't understand why this is the case. Can someone help?

Regards

Arduino Code

    void setup() {
      Serial.begin(9600);
      delay(1000);
      Serial.println("1.first massage");
      Serial.println("2.socend massage"); 
      delay(100);
    }
    void loop() {
    
    }

Processing Code

    import processing.serial.*;
    Serial myPort;
    void setup() {
      myPort=new Serial(this, "COM3", 9600);
    }

    void draw() {
      String s1=myPort.readStringUntil('\n');
      String s2=myPort.readStringUntil('\n');

    // printing variables
      if(s1!=null){
      print("s1:",s1);
      }
      if(s2!=null){
       println("s2:",s2);
      }
    }

This looks like a Processing question rather than an Arduino question

When you read the 2 Strings into Processing how do you know that there is actually something to read ?

How can you tell when you are printing only 1 or 2 variables? In this case, even if there are 2, you print them merged without a line break after the first one.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.