So I've posted some days ago about a similar problem, today I was trying to get a simpler arduino->processing into working first, but neither this one works.
Basically I've an Arduino sending various values through the serial port. The values appearing are for example 152,0,140,92,53..etc.
I'd like to just save for example 100 of those values and then stop recording.
I can't actually get a functioning sequence without the port "shutting" itself or the data not being recorded at all.
I've looked through TONS of tutorials but I never get it to work.
Can someone please guide me through a working version of it?
The Arduino part is simple as that:
int fsr0;
int fsr1;
void setup()
{
Serial.begin(9600);
}
void loop()
{
fsr0=analogRead(A4);
fsr1=analogRead(A5);
Serial.print(fsr0);
Serial.print(",");
delay(500);
Serial.println(fsr1);
delay(500);
}
The data grabbing sequence in Processing is what follows
import processing.serial.*;
float[] gauge0 = new float[100];
float[] gauge1 = new float[100];
int k=0;
Serial mySerial;
void setup()
{
size (800, 580);
frameRate(10);
//grafico();
String myPort = Serial.list()[0];
mySerial = new Serial(this, myPort, 9600);
mySerial.bufferUntil('\n');
}
void serialEvent(Serial mySerial)
{
String inString = mySerial.readStringUntil('\n');
if (inString!=null); // this area splits the arduino inputs such that they can be received seperately
{
inString=trim(inString);
float[] sensors= float (split(inString, ","));
if (sensors.length>=2)
{
gauge0[k]=sensors[0];
gauge1[k]=sensors[1];
k++;
}
}
}
I also tried to use the Serial.available function as I read from Robin2 guide, but it didn't help much.
Man this is getting exhausting...