Hi all first post here, and new to Processing, this is my first project.
I am trying to read a stream of serial data from an Arduino board, and have it set the angle of a pointer in processing on my screen.
I have followed the guidance here: Connecting Arduino to Processing - SparkFun Learn
and made this:
import processing.serial.*;
Serial myPort;
String val;
void setup()
{
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 115200);
}
void draw()
{
if ( myPort.available() > 0)
{ // If data is available,
val = myPort.readStringUntil('\n');
}
println(val);
}
So, this does indeed print my value to the console, however, the values displayed are not quite as expected, like Processing is very delayed with displaying the numbers.
I have a shaft I’m rotating, and the Arduino is measuring the angle from 0 to 359.999999… degrees. This is being passed out of the Arduino over serial with this print command:
Serial.print(angle);
Serial.print("\n");
which is effectively the same as Serial.println in Arduino.
This works well in the Arduino IDE serial monitor and serial plotter, the numbers shown relate exactly to the shaft position.
But in the processing console, any shaft movement is hugely delayed between moving it and the change appearing in the console, so much so I’ve not been able to quantify it.
I’m wondering if there is a buffer of serial data in Processing that’s causing the delay? or maybe the console just can’t work that fast?
Any ideas?
PS: Processing 4.1.1 on Linux Mint 20.
Many thanks, Scott.