Skip to content

Instantly share code, notes, and snippets.

@dj1711572002
Created June 1, 2020 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dj1711572002/16e51e73cb49785e96b5f743af9714c2 to your computer and use it in GitHub Desktop.
Save dj1711572002/16e51e73cb49785e96b5f743af9714c2 to your computer and use it in GitHub Desktop.
//**************************Processing Serial Recive & PlotGraph MultiCH data Sample ***************************
//*************************Shinshu-Makers 2020/06/01**************************************************
import processing.serial.*;//USB Serial library
PrintWriter output;//Filing library
int lf = 10; // Linefeed in ASCII
int cr=13; //Carriage Return in ASCII
String myString1 = null;//Recieved data as string 1st
Serial myPort1; // 1st serial port
int i,j;
String [] mystringArry1=new String[600000];//1stArray declaration Buffer memory recived 600K data
//=============PLOT==================
int x,x_1;
int y0=0,y0_1=0;
int y1=0,y1_1=0;
int y2=0,y2_1=0;
int y3=0,y3_1=0;
int y4=0,y4_1=0;
int y5=0,y5_1=0;
void setup() {
//===================Display setup===================
size(1000,1000);
background(0,0,0);
//=======================================================
// ********************Serial setup=**********************
//List all the available serial ports
printArray(Serial.list());
// Open the port you are using at the rate you want:
myPort1 = new Serial(this, Serial.list()[0], 115200);
myPort1.clear();
myString1 = myPort1.readStringUntil(lf);
myString1 = null;
//**********************************************************
//------------------Save FIle setup--------------------------------------------------------------
String filename = nf(year(),4) + nf(month(),2) + nf(day(),2) + nf(hour(),2) + nf(minute(),2) ;
// 新しいファイルを生成
output = createWriter( filename + ".csv");
i=0;
//-----------------------------------------------------------------------------------------------
}
void draw() {
while (myPort1.available() > 0) {
myString1 = myPort1.readStringUntil(cr);
if (myString1 != null) {
i++;
// print(i,myString1);
mystringArry1[i]=myString1;
float[] data = float(split(myString1,','));
//println(data[0],data[1]);
x_1=x;
x=i;
//*****0ch Yplot*****
y0_1=y0;
y0=Yplot(0,data[1],2,6);
stroke( 255, 0, 0 );
line(x_1,y0_1,x,y0);
//*****1ch Yplot*****
y1_1=y1;
y1=Yplot(1,data[2],2,6);
stroke( 0,255, 0 );
line(x_1,y1_1,x,y1);
//*****2ch Yplot*****
y2_1=y2;
y2=Yplot(2,data[2],2,6);
stroke( 255,255,255 );
line(x_1,y2_1,x,y2);
}
}
}
void keyPressed(){
int k;
String[] datastr=new String[100];
if( key == 'q' ){
for(k=0;k<i;k++){
//datastr=split(mystringArry[k],',');
//println(datastr[0]);
output.print(mystringArry1[k]);
}
output.flush();
output.close();
exit();
}
}
int Yplot(int ch,float y,float yspan,int chsu)//Graph ch plot
{
int Framey=1000;
int chH=int(Framey/chsu);
int baseY=int(chH/2)+(ch*chH);
float ydot=chH/yspan;
int ch_plotY=int(ydot*y+baseY);
return ch_plotY;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment