HI guys, I’m new to both processing and JAVA. I need to build a serial project to complete my research. I used a Arduino MEGA 2560 and a AD7606 to capture volt signals from 8 channels and the value will be sent to processing with a “|” as an end character of 8 channels. Besides, I use “enter” to end capture and save my data as csv format. However, I found that I received duplicated values during about every 0.3 seconds but not the true value my chipboard captured.
This is my code:
import processing.io.*;
import processing.serial.*;
////varibles setting
Serial myPort;
String inString;
int flag = 0;
Table table;
int starTime = 0;
float t = 0;
int Year,Month,Day,Hour,Minute;
String testname;
String R0str = new String();
float R0;
void setup()
{
////setup for serial
myPort = new Serial(this, "/dev/cu.usbmodem1101", 115200);
myPort.bufferUntil('|');///set a buffer to divide A and B channel signal
delay(100);
//////setup for tips
//print("Please input the value of R0\n");
//print("press 'ENTER' to end input and start recording, press 'ESC' to exit program\n");
//////setup for saving
table = new Table();
table.addColumn("time");
table.addColumn("RA");
starTime=0;
}
////////read buffer
void serialEvent(Serial p) {
inString = p.readString();
}
// function
void draw() {
if (inString!= null)
{
t = float(millis() - starTime) / 1000;
print(inString);
Year = year();
Month = month();
Day = day();
Hour = hour();
Minute = minute();
testname = "NormR-" + str(Year) + '-' + str(Month) + '-' + str(Day) + '_' + str(Hour) + '-' + str(Minute) + ".csv";
flag = 1;
String list1 = inString;
TableRow newRow = table.addRow();
newRow.setFloat("time",t);
newRow.setString("RA",list1);
}
keyPress();
//println(flag,starTime);
} // func
///detect if key is pressed
void keyPress() {
if (keyPressed)
{
if (key == ENTER)
{
print("'ENTER' is pressed\n");
saveTable(table, testname);
delay(300);
exit();
}
}
}
And the value saved in csv is
As you can see, altough values changes in every milliseconds , the value of PROCESSING won’t change immediately but showing duplicate value for about 0.3 s. I tried to use another serial reading app to read values transfered from my ARDUINO and it shows intime and continous value change during the test, which indicates duplicate value is not a result of sampling rate of Arduino but the PROCESSING.
the value of another serial read app under here:
I want to read values in processing because I can use it to easily deal with my datasave. However those duplicate values keep confusing me. I can’t find the reason they generated so I can’t fix this problem.
If you have any ideas?