Hey all, I am new on that big world, so I am having several questions. My idea is to import some values from arduino to processing. For that, I used the vsync library, but seems that it is not working properly.
For instance, I have written that example.
Arduino:
#include <VSync.h>
int num1= 0;
int num2= 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int num1 = random(1, 100);
int num2 = random(100, 200);
Serial.println(num1);
Serial.println(num2);
delay(1000);
}
Processing:
import vsync.*;
import processing.serial.*;
ValueReceiver receiver;
ValueSender sender;
public int num1, num2;
void setup() {
size(600,600);
background(0);
Serial serial = new Serial(this, "COM3", 9600);
receiver = new ValueReceiver(this, serial).observe("num1").observe("num2");
}
void draw() {
line(num1, num2, 200, 100);
println(num1);
println(num2);
}
Have you read the forum rules in the how to use this forum sticky post?
You need to say what you were hoping that code would do and what it actually does. Better yet what on earth you are trying to achieve "not working properly " is not going to cut it.
Serial data shoul NOT be read in draw(). Unlike loop() on the Arduino, draw() is not called as fast as possible.
You need to look up the serialEvent() method, and add one to your class.
You also need to define what sort of synchronization you think is going to happen when Processing never talks to the Arduino (or the Arduino never reads what it sent).
Grumpy_Mike:
Have you read the forum rules in the how to use this forum sticky post?
You need to say what you were hoping that code would do and what it actually does. Better yet what on earth you are trying to achieve "not working properly " is not going to cut it.
I did read the sticky posts but maybe I didnt put the attention it needs.
Apart from that, what I'm trying to do is create a variable in Arduino and receive it in Processing thanks to the Vsync library. What I got is that in Arduino I obviously receive the values but on Processing it always appears a 0, so I guess there is no synchronization. On the other hand, what I would like to obtain are the variables on Processing, but as I said, I don't.
PaulS:
Serial data shoul NOT be read in draw(). Unlike loop() on the Arduino, draw() is not called as fast as possible.
You need to look up the serialEvent() method, and add one to your class.
You also need to define what sort of synchronization you think is going to happen when Processing never talks to the Arduino (or the Arduino never reads what it sent).
I have already worked with the serialEvent but even though it is faster the program should work anyway.
The sync between arduino and processing is related with the vsync library and the instruction receiver, at least, this is what I read on the explanation of the library.
Im not really into Arduino so understand my mistakes please.