Go Down

Topic: Save Arduino input in array, and THEN plot it. (Read 790 times) previous topic - next topic

Runzolf

May 22, 2019, 04:30 pm Last Edit: May 22, 2019, 04:33 pm by Runzolf
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:

Code: [Select]
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

Code: [Select]

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...

PaulS

The code you posted does something. Re-read your post, and see if you can figure out what your code actually does. Or what the problem that you need help with is.

Your Arduino will send data forever. The processing app will keep writing to the two arrays, even when they are full. That hardly seems like a good idea.

Processing sketches need to have a draw() method.
The art of getting good answers lies in asking good questions.

Go Up