Importing(reading) text into a program and using the end of the line as a marke

For my robot, I am trying to merge two Processing programs(a graphics example(tutorial) and a radar program) to create a display, without success. The robot sends information for the Processing program to display. I want to use the end of the line as the end of data package character, but have had no success in finding the character I am looking for. I want each data packet to be on a single line so that I can read it.

The first(Second) draft of the robot program is as follows:

This post edited to incorporate comments.

#include <MeMegaPi.h>
#include <stdio.h>
#include <stdlib.h>            
  #include <math.h>       
#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>

MeUltrasonicSensor ultraSensor(PORT_7); /* Ultrasonic module can ONLY be connected to port 3, 4, 6, 7, 8 of base shield. */

int Angle;
int Distance;

void setup() {
  Serial.begin(115200);
  MeGyro gyro;
}

void loop() {
  int i;
  for (i = 0; i < 360; i++) {
    gyro.update();
    Angle = gyro.getAngleZ();
    Serial.print  (Angle); // Sends the current angle into the Serial Port
    Serial.print  (",");      // Sends addition character right next to the previous value needed later in the Processing IDE for indexingIDEfor indexing
    Distance = ultraSensor.distanceCm();
    Serial.print  (Distance);    // Sends the distance value into the Serial Port
    Serial.println("");
    delay (100);
  }
}

The Processing program code follows:

import processing.serial.*; // imports library for serial communication
import java.awt.event.KeyEvent; // imports library for reading the data from the serial port
import java.io.IOException;

import toxi.color.*;
import toxi.geom.*;
import toxi.math.*;

// keeper of transition state
float transition;

// use a S-Curve to achieve an ease in/out effect
InterpolateStrategy is=new SigmoidInterpolation(3);

Serial myPort; // defines Object Serial
// defubes variables
String angle="";
String distance="";
String data="";
String noObject;
float pixsDistance, w2, h2;
int iAngle = 3/4*3, iDistance =300 ;
int index1=0;
int index2=0;
PFont orcFont;

void setup() {
  
  float h2=height * 0.5;
//  size(800, 800);
  background(255);
  smooth();
  noStroke();
  
  
 size (800, 800,P3D); // ***CHANGE THIS TO YOUR SCREEN RESOLUTION***
 smooth();
 myPort = new Serial(this,"COM5", 115200); // starts the serial communication
 myPort.bufferUntil('.'); // reads the data from the serial port up to the character '.'. So actually it reads this: angle,distance.
  fill(98,245,31);
//  background(255);
  noStroke();
  fill(0,4);
  
  fill(98,245,31); // green color
  
 
  translate(w2, h2);
}


void draw() {
 
  if (frameCount % 1 == 0) {
    fill(frameCount * 3 % 255, frameCount * 5 % 255,frameCount * 7 % 255);
    pushMatrix();
    translate(400, 400);
    rotate(radians(iAngle % 360) );
    rect(0, 0, 400, 1);
    box(50.0,100.0,float(angle));
    popMatrix();
//    print(angle);
    
  }
  
}


void serialEvent (Serial myPort) { // starts reading data from the Serial Port
  // reads the data from the Serial Port up to the end of the line and puts it into the String variable "data".
  data = myPort.readStringUntil('CR/LF');  //  Is it LF(No), CR(No), EOL(No) OR 'LF', 'CR', 'EOL'(NO), \n(No)
  data = data.substring(0,data.length()-1);
  
  index1 = data.indexOf(","); // find the character ',' and puts it into the variable "index1"
  angle= data.substring(0, index1); // read the data from position "0" to position of the variable index1 or thats the value of the angle the Arduino Board sent into the Serial Port
  distance= data.substring(index1+1, data.length()); // read the data from position "index1" to the end of the data pr thats the value of the distance
  
  // converts the String variables into Integer
  iAngle = int(angle);
  iDistance = int(distance);
}
#include <MeMegaPi.h>


#include <MeMegaPi.h>

Maybe you need to include this file a couple more times...

  MeGyro gyro;
}

How useful. A class instance that immediately goes out of scope.

  int i;
  for (i = 0; i < 100; i++) {
    Serial.print  (i); // Sends the current degree into the Serial Port

No, it doesn't. There is no hint that i has ANY relationship to degree(s).

    Angle = float(i)*500/400;
    Serial.print  (int(Angle));    // Sends the distance value into the Serial Port

More nonsense. Distance should NOT be stored in a variable called Angle.

 myPort.bufferUntil('.'); // reads the data from the se

So, why did you quit sending the dot?

You can use '\n' (newline).

Serial.println will also work; it appends (if not mistaken) '\r' (carriage return) followed by '\n'.

I am satisfied with the draft of the Robot program. as follows:

// Robot.ino
#include <MeMegaPi.h>
#include <stdio.h>
#include <stdlib.h>                    /* qsort *
 #include <math.h>                           /* math functions                */
#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>

#define Pi 3
MeUltrasonicSensor ultraSensor(PORT_7); /* Ultrasonic module can ONLY be connected to port 3, 4, 6, 7, 8 of base shield. */

int Angle;
int Distance;

MeGyro gyro;
 
void setup() {
 Serial.begin(115200);
 gyro.begin();
}

void loop() {
 int i;
 for (i = 0; i < 100; i++) {
   gyro.update();
   Angle = gyro.getAngleZ();
   Serial.print  (Angle); // Sends the current angle into the Serial Port
   Serial.print  (",");      // Sends addition character right next to the previous value needed later in the Processing IDE for indexing
   Distance = ultraSensor.distanceCm();
   Serial.print  (Distance);    // Sends the distance value into the Serial Port
   Serial.println("");
   delay (100);
 }
}

But, I can not read the data in the Processing Program. as follows:

import processing.serial.*; // imports library for serial communication
import java.awt.event.KeyEvent; // imports library for reading the data from the serial port
import java.io.IOException;

import toxi.color.*;
import toxi.geom.*;
import toxi.math.*;

// keeper of transition state
float transition;

// use a S-Curve to achieve an ease in/out effect
InterpolateStrategy is=new SigmoidInterpolation(3);

Serial myPort; // defines Object Serial
// defubes variables
String angle="";
String distance="";
String data="";
String noObject;
float pixsDistance, w2, h2;
int iAngle = 3/4*3, iDistance =300 ;
int index1=0;
int index2=0;
PFont orcFont;

void setup() {
  
  float h2=height * 0.5;
//  size(800, 800);
  background(255);
  smooth();
  noStroke();
  
  
 size (800, 800,P3D); // ***CHANGE THIS TO YOUR SCREEN RESOLUTION***
 smooth();
 myPort = new Serial(this,"COM5", 115200); // starts the serial communication
 myPort.bufferUntil('.'); // reads the data from the serial port up to the character '.'. So actually it reads this: angle,distance.
  fill(98,245,31);
//  background(255);
  noStroke();
  fill(0,4);
  
  fill(98,245,31); // green color
  
 
  translate(w2, h2);
}


void draw() {
 
  if (frameCount % 1 == 0) {
    fill(frameCount * 3 % 255, frameCount * 5 % 255,frameCount * 7 % 255);
    pushMatrix();
    translate(400, 400);
    rotate(radians(iAngle % 360) );
    rect(0, 0, 400, 1);
    box(50.0,100.0,float(angle));
    popMatrix();
//    print(angle);
    
  }
  
}


void serialEvent (Serial myPort) { // starts reading data from the Serial Port
  // reads the data from the Serial Port up to the end of the line and puts it into the String variable "data".
  data = myPort.readStringUntil('CR/LF');  //  Is it LF(No), CR(No), EOL(No) OR 'LF', 'CR', 'EOL'(NO), \n(No)
  data = data.substring(0,data.length()-1);
  
  index1 = data.indexOf(","); // find the character ',' and puts it into the variable "index1"
  angle= data.substring(0, index1); // read the data from position "0" to position of the variable index1 or thats the value of the angle the Arduino Board sent into the Serial Port
  distance= data.substring(index1+1, data.length()); // read the data from position "index1" to the end of the data pr thats the value of the distance
  
  // converts the String variables into Integer
  iAngle = int(angle);
  iDistance = int(distance);
}

If the data is printed as

Serial.print  (Angle); // Sends the current angle into the Serial Port
   Serial.print  (",");      // Sends addition character right next to the previous value needed later in the Processing IDE for indexing
   Distance = ultraSensor.distanceCm();
   Serial.print  (Distance);    // Sends the distance value into the Serial Port
   Serial.print(".");

The Processing program can read the data.
If the data is printed as

Serial.print  (Angle); // Sends the current angle into the Serial Port
   Serial.print  (",");      // Sends addition character right next to the previous value needed later in the Processing IDE for indexing
   Distance = ultraSensor.distanceCm();
   Serial.print  (Distance);    // Sends the distance value into the Serial Port
   Serial.println(".");

I can read the data.

But, what code would let both me and the Processing program read the data(at different times) The Processing program does not need carriage return and line, but I do.

  data = myPort.readStringUntil('CR/LF');  //  Is it LF(No), CR(No), EOL(No) OR 'LF', 'CR', 'EOL'(NO), \n(No)

After you've told Processing to buffer data until the dot arrives, this function will only be called when that happens. Then, you should read all the data. What the heck is this trying to do? Post a picture of your keyboard with the ONE character between the single quotes there circled.