Hello there,
I want to connect my Arduino UNO Board (of a Grove Kit) with Processing. I could not figure out a way to directly access the Arduino from Processing with the cc.arduino library. For me it seems like it is only usable with Processing versions before Processing 4. This is why I’m working with a serial port this way.
(Definitely feel free to inform me about any shorter way if there is one.)
What I did:
I connected the Arduino board to my MacBook, uploaded StandardFirmata and the following code to the board.
Following code is written inside Arduino IDE.
int analogPin = A0;
int val = 0;
void setup(){
Serial.begin(115200);
}
void loop(){
val = analogRead(analogPin);
Serial.println(val);
delay(350);
}
After that I added a Rotary Angle Sensor to the A0 Pin. I checked the serial monitor of the Arduino IDE to check if things are working — they were. Please note that I am working with a delay of 350.
Then I headed over to processing and worked with this code:
Following code is written in Processing.
import processing.serial.*;
float f;
Serial port;
String val;
void setup() {
port = new Serial(this, "/dev/cu.usbserial-144240", 115200);
size(700,700);
background(255);
}
void draw() {
if ( port.available() > 0)
{ // If data is available,
val = port.readStringUntil('\n');
f = float(val);
}
noStroke();
fill(0);
rect(width/4,height/4,f,f);
println(val);
}
For the sake of just trying it out, I wanted to have a black rectangle resize with the value given from the Rotary Angle sensor. Processing is reading the serial port like it should but only every 350 milliseconds (the delay I set). I would love to see it reading perfectly with a delay below 10 milliseconds or just no delay at all.
Deleting the delay inside of Arduino or setting it to something like 200 milliseconds will result with Processing giving out only one value the whole time.
I hope I was able to clarify my problem. If not, feel free to ask again.
(I found this topic in the forum as well, but it could not help me either: Issue with reading Arduino Port)
Thank you for your help!
gfs