About Processing's serial port

Hi there It’s me again so Here is a photo about the issue.

. So as you can see (here is the code btw

import processing.serial.*;  
import controlP5.*;
/////////////////
int interval = 0;
int end = 10;   
String receivedString;   
Serial myPort; 
ControlP5 cp5;
Chart XChart;
Chart YChart;
Chart ZChart;
Chart GXChart;
Chart GYChart;
Chart GZChart;
Chart TempChart;
Chart AChart;
Chart BChart;
Chart CChart;
/////////////////
void setup() {
/////////////////
size(1920 , 1080);
background(#F5E6E6);
smooth();
strokeWeight(3);
textSize(16);
/////////////////
myPort= new Serial(this, Serial.list()[0], 115200); 
myPort.clear();  
receivedString = myPort.readStringUntil(end);
cp5 = new ControlP5(this); 
/////////////////
receivedString = null; 
//
XChart = cp5.addChart("X Ekseni")
.setPosition(5, 0)
.setSize(470, 280)
.setRange(-30, 400)
.setView(Chart.LINE) 
.setStrokeWeight(1.5)
.setColorCaptionLabel(color(40));
//         
YChart = cp5.addChart("Y Ekseni")
.setPosition(485, 0)
.setSize(470, 280)
.setRange(-30, 400)
.setView(Chart.LINE) 
.setStrokeWeight(1.5)
.setColorCaptionLabel(color(40));
//               
ZChart = cp5.addChart("Z Ekseni")
.setPosition(965, 0)
.setSize(470, 280)
.setRange(-30, 400)
.setView(Chart.LINE) 
.setStrokeWeight(1.5)
.setColorCaptionLabel(color(40));
//            
GXChart = cp5.addChart("GX Ekseni")
.setPosition(1445, 0)
.setSize(470, 280)
.setRange(-30, 400)
.setView(Chart.LINE) 
.setStrokeWeight(1.5)
.setColorCaptionLabel(color(40));
//
GYChart = cp5.addChart("GY Ekseni")
.setPosition(5, 365)
.setSize(470, 280)
.setRange(-30, 400)
.setView(Chart.LINE) 
.setStrokeWeight(1.5)
.setColorCaptionLabel(color(40));
//               
GZChart = cp5.addChart("GZ Ekseni")
.setPosition(5, 725)
.setSize(470, 280)
.setRange(-30, 400)
.setView(Chart.LINE) 
.setStrokeWeight(1.5)
.setColorCaptionLabel(color(40));
//      
TempChart = cp5.addChart("Sıcaklık")
.setPosition(1445, 365)
.setSize(470, 280)
.setRange(-30, 400)
.setView(Chart.LINE) 
.setStrokeWeight(1.5)
.setColorCaptionLabel(color(40));
//       
AChart = cp5.addChart("Degisik")
.setPosition(485, 725)
.setSize(470, 280)
.setRange(-30, 400)
.setView(Chart.LINE) 
.setStrokeWeight(1.5)
.setColorCaptionLabel(color(40));
//
BChart = cp5.addChart("Farklı")
.setPosition(965, 725)
.setSize(470, 280)
.setRange(-30, 400)
.setView(Chart.LINE) 
.setStrokeWeight(1.5)
.setColorCaptionLabel(color(40));
//              
CChart = cp5.addChart("ASD")
.setPosition(1445, 725)
.setSize(470, 280)
.setRange(-30, 400)
.setView(Chart.LINE) 
.setStrokeWeight(1.5)
.setColorCaptionLabel(color(40));
//
AChart.addDataSet("incoming");
AChart.setData("incoming", new float[100]);
//
BChart.addDataSet("incoming");
BChart.setData("incoming", new float[100]);
//
CChart.addDataSet("incoming");
CChart.setData("incoming", new float[100]);
//                 
TempChart.addDataSet("incoming");
TempChart.setData("incoming", new float[100]);
//                 
GYChart.addDataSet("incoming");
GYChart.setData("incoming", new float[100]);
//
GZChart.addDataSet("incoming");
GZChart.setData("incoming", new float[100]);
//             
XChart.addDataSet("incoming");
XChart.setData("incoming", new float[100]);
//  
YChart.addDataSet("incoming");
YChart.setData("incoming", new float[100]);
//  
ZChart.addDataSet("incoming");
ZChart.setData("incoming", new float[100]);
//
GXChart.addDataSet("incoming");
GXChart.setData("incoming", new float[100]);
//  
delay(1000);
myPort.write('r');
delay(10000);
myPort.clear();
delay(10000);
myPort.clear();
delay(10000);
//////////////////////////End of the Setup void.
}
void draw(){
  while (myPort.available () > 0){ 
receivedString = myPort.readStringUntil(end);
}
if (receivedString != null)
{  
String[] a = split(receivedString, ',');
float[] f = new float[a.length]; 
int[] v = new int[a.length];
for(int i = 0; i < a.length; i++)
{
  f[i] = Float.parseFloat(a[i].trim());
  v[i] = round((float)f[i]);
  println(f[i] + "\t\t" + v[i]);

//Defining what will charts push.(Value)
XChart.push("incoming",v[0]);
YChart.push("incoming",v[1]);
ZChart.push("incoming",v[2]);
GXChart.push("incoming",v[3]);
GYChart.push("incoming",v[4]);
GZChart.push("incoming",v[5]);
AChart.push("incoming",v[6]);
BChart.push("incoming",v[7]);
CChart.push("incoming",v[8]);
TempChart.push("incoming",v[9]);
//Line codes
stroke(#000000);
line(480,0,480,1080);
line(960,360,960,0);
line(960,720,960,1080);
line(1440,0,1440,1080);
line(0,360,1920,360);
line(0,720,1920,720);  
//X Chart Value
fill(#D6C0C0);
stroke(#000000);
rect(180,300,100,50,10);
fill(#FF301E);
text(f[0],200,330);
fill(#FFFFFF);
//Y Chart Value
fill(#D6C0C0);
stroke(#000000);
rect(660,300,100,50,10);
fill(#FF301E);
text(f[1],680,330);
fill(#FFFFFF);
//Z Chart Value
fill(#D6C0C0);
stroke(#000000);
rect(1140,300,100,50,10);
fill(#FF301E);
text(f[2],1160,330);
fill(#FFFFFF);
//GX Chart Value
fill(#D6C0C0);
stroke(#000000);
rect(1620,300,100,50,10);
fill(#FF301E);
text(f[3],1640,330);
fill(#FFFFFF);
//GY Chart Value
fill(#D6C0C0);
stroke(#000000);
rect(180,660,100,50,10);
fill(#FF301E);
text(f[4],200,690);
fill(#FFFFFF);
//GZ Chart Value
fill(#D6C0C0);
stroke(#000000);
rect(1620,660,100,50,10);
fill(#FF301E);
text(f[5],1640,690);
fill(#FFFFFF);
//A Chart Value
fill(#D6C0C0);
stroke(#000000);
rect(180,1020,100,50,10);
fill(#FF301E);
text(f[6],200,1050);
fill(#FFFFFF);
//B Chart Value
fill(#D6C0C0);
stroke(#000000);
rect(660,1020,100,50,10);
fill(#FF301E);
text(f[7],680,1050);
fill(#FFFFFF);
//C Chart Value
fill(#D6C0C0);
stroke(#000000);
rect(1140,1020,100,50,10);
fill(#FF301E);
text(f[8],1160,1050);
fill(#FFFFFF);
//Temp Chart Value
fill(#D6C0C0);
stroke(#000000);
rect(1620,1020,100,50,10);
fill(#FF301E);
text(f[9],1640,1050);
fill(#FFFFFF);
}
}
}

)
There is nothing wrong about this code but it does not work when I try to run it. If there is a way to solve this plz write down thanks

1 Like

Hello,

Please format your code as a courtesy to the community:
https://discourse.processing.org/faq#format-your-code

Try to cut and paste it and you will see why.

I won’t look at it as is.

:)

Okay,sure I’ll do it

Hello,

What is sending the data?

I substituted some test data:

receivedString = "0,100,2,30,4,50,6,70,8,90,10";
if (receivedString != null)

That is all I can offer without knowing more.

Try adding:
https://processing.org/reference/libraries/serial/Serial_list_.html

And make sure you are connected to the correct serial port.

Your formatting made this easy to copy.

:)

1 Like

Yes I tried to send some numbers into it now. And It worked. But When I actually try to get some numbers from arduino It just doesnt work it gets stuck everytime I try to send numbers from arduino

Write some very simple Arduino code to send test data and share that and I will try it.

Keep it simple.

:)

  void setup() {
  Serial.begin(115200);
  }
  
  void loop() {
  Serial.print("756.34");
  Serial.print(",");
  Serial.print("354.45");
  Serial.print(",");
  Serial.print("87.98);
  }

You are not sending an ‘end’ from Arduino.

receivedString = myPort.readStringUntil(end);

You need to send this on Arduino side.

https://www.arduino.cc/reference/en/language/functions/communication/serial/println

:)

1 Like

So you mean If I just put Serial.println(" "); It will solve the problem

Thx man I appreciate it very much thx for all again. Much love from Turkey

2 Likes